Pieces

Home * Chess * Pieces

[ Pawn, Rook, Knight, Bishop. Queen, and King [1] This is about Chess Pieces of Classical or Orthodox Chess. Other chess variants introduce Fairy chess pieces with different movement.

In chess terminology the term Piece is a bit ambiguous and may have different meanings - the term Chess Men is therefor often appropriate, since pieces otherwise don’t include Pawns and even the King, but consider minor pieces, Knight and Bishop, and the major pieces (also heavy pieces), Rook and Queen. Rook, Bishop and Queen are so called sliding pieces, since they may “slide” in appropriate ray-directions as far they like - as long they are not hindered (blocked) by own or opponent pieces (which they may capture), with implications on move generation issues.

Piece-Type Coding

Any enumeration of piece-type codes is fine. Harm Geert Muller proposed distinct white and black pawn codes inside the otherwise colorless range of piece-types, to take the different move-directions of pawns into account. This way piece-type completely specifies the mechanical move abilities, and three bits are still appropriate for a dense range to index tables or lookup-arrays, e.g. for Piece Values and that like. Often the order of enumeration is conform with the value of the pieces, for instance a C++ enumeration:


enum EPieceType
{
   ept_pnil   = 0, // empty
   ept_wpawn  = 1,
   ept_bpawn  = 2,
   ept_knight = 3,
   ept_bishop = 4,
   ept_rook   = 5,
   ept_queen  = 6,
   ept_king   = 7,
};

Piece Type and Color

One approach is to use negative values for black and positive for white (or color don’t care) pieces. But if we like to index (zero based) arrays in C, C++ or Java by piece codes an offset has to be considered - also the Two’s Complement needs abs-functions or additional indirection to extract the pure piece code, rather than to mask (and eventually shift) three bits. That is why most programmers rely on positive ranges only and concatenate the three piece-type bits with one color-bit, for instance the color at the big end.


 PieceCode:4 = 8 * Color:1 + PieceType:3;

In C++ as enumeration:


enum EPieceCode
{
   epc_empty   = ept_pnil,
   epc_wpawn   = ept_wpawn,
   epc_woff    = ept_bpawn, // may be used as off the board blocker in mailbox
   epc_wknight = ept_knight,
   epc_wbishop = ept_bishop,
   epc_wrook   = ept_rook,
   epc_wqueen  = ept_queen,
   epc_wking   = ept_king,

   epc_blacky  = 8, // color code, may used as off the board blocker in mailbox
   epc_boff    = ept_wpawn  + epc_blacky, // may be used as off the board blocker in mailbox
   epc_bpawn   = ept_bpawn  + epc_blacky,
   epc_bknight = ept_knight + epc_blacky,
   epc_bbishop = ept_bishop + epc_blacky,
   epc_brook   = ept_rook   + epc_blacky,
   epc_bqueen  = ept_queen  + epc_blacky,
   epc_bking   = ept_king   + epc_blacky,
};

To concatenate piece type and color the other way around is also quite common, color at the little end.


 PieceCode:4 = 2 * PieceType:3 + Color:1;

Disjoint Piece Flags

An alternative coding approach for most efficient inner loops with cheap test-instructions in scanning board arrays in conjunction with move generation, specially captures, is to encode pieces by five and up to eight disjoint bits (one byte). Each white and black piece has a disjoint color bit set, and appropriate bits may indicate a sliding piece, orthogonal or diagonal stepping or sliding etc.. One may even use one disjoint bit out of six per piece, yielding in exactly two bits set per regular piece code, for instance [3]:

| Bit | Binary | Semantic

0
0000 0001White
1
0000 0010Black
combined (ored with)
2
0000 0100Pawn
3
0000 1000Knight
4
0001 0000Bishop
5
0010 0000Rook
6
0100 0000Queen
7
1000 0000King

Encapsulation

There are a lot of possibilities to encode pieces, however surrounding source code should not directly rely on the binary representation and range of that codes, e.g. the semantic of a certain bit. In general, it is recommend to hide implementation details, likely in C++ inside a wrapper class with inlined getter and setter, or in C a set of C-Macros and functions that “wrap” an scalar integer type. A distinct type, e.g. a type definition in C/C++ is recommend for better compile time checking, other programmer still prefer (unsigned) integer types for passing pieces (and moves, colors and square coordinates) around.

On the other hand, one should not exaggerate abstraction, to be aware of an wrapped integer type is fine, and that bytes are appropriate to store an array of piece codes, which may easily zero-extended to wider types if passed via registers. If you intend to implement stuff like Zillions of Games or different Fairy Chess variants, it might be a reasonable idea, to design derived piece classes with virtual functions and late binding during runtime.

Samples

Value of Pieces

and under the Evaluation topic:

Tactical Properties

Printing and Drawing

ASCII Art

ASCII art chess pieces, collected by Andreas Freise [4]:


                                .      +
       []       ()    _,,       ()     ()
       )(       )(   "-=\~      )(     )(       ()
       )(       )(     )(       )(     )(       )(
ejm97 /__\     /__\   /__\     /__\   /__\     /__\

                                .      +
       []       ()    _,,       ()     ()
       )(       )(   "-X\~      )(     )(       ()
       )(       )(     )(       )(     )(       )(
ejm97 /XX\     /XX\   /XX\     /XX\   /XX\     /XX\

ASCII art Staunton chess set by David Moeser [5]


    .::.
    _::_
  _/____\_        ()
  \      /      <~--~>
   \____/        \__/         <>_
   (____)       (____)      (\)  )                        __/"""\
    |  |         |  |        \__/      WWWWWW            ]___ 0  }
    |__|         |  |       (____)      |  |       __        /   }
   /    \        |__|        |  |       |  |      (  )     /~    }
  (______)      /____\       |__|       |__|       ||      \____/
 (________)    (______)     /____\     /____\     /__\     /____\
 /________\   (________)   (______)   (______)   (____)   (______)
    King        Queen       Bishop      Rook      Pawn     kNight

Unicode

Chess symbols in Unicode, see also the Unicode Board.

| Name | Symbol | Code point | HTML (dec) | HTML (hex)

White KingU+2654
White QueenU+2655
White RookU+2656
White BishopU+2657
White KnightU+2658
White PawnU+2659
Black KingU+265A
Black QueenU+265B
Black RookU+265C
Black BishopU+265D
Black KnightU+265E
Black Pawn♟︎U+265F

See also

Forum Posts

feat.: Phil Collins, Gerald Albrigth, Sadao Watanabe, Klaus Doldinger, Pee Wee Ellis, George Duke, James Carter, arranged and conducted by Arif Mardin

References

  1. An example of early-style Staunton Chess Set - Photo used by permission of Frank A. Camaratta, Jr.; The House of Staunton, Inc.; houseofstaunton.com, Chess piece from Wikipedia, Wikimedia Commons
  2. Burton Wendroff (1985). Attack Detection and Move Generation on the X-MP/48. ICCA Journal, Vol. 8, No. 2
  3. Fritz Reul (2009). New Architectures in Computer Chess, Ph.D. Thesis, Chapter 2 Non-Bitboard Architectures
  4. chess - Ascii Art Dictionary by Andreas Freise
  5. ASCII Chess Pieces by David Moeser

Up one Level