Changes

Jump to: navigation, search

Pieces

13,237 bytes added, 17:23, 7 May 2018
Created page with "'''Home * Chess * Pieces''' border|right|thumb| [[Pawn, Rook, Knight, Bishop. Queen, and King <ref>An ex..."
'''[[Main Page|Home]] * [[Chess]] * Pieces'''

[[FILE:JaquesCookStaunton.jpg|border|right|thumb| [[Pawn]], [[Rook]], [[Knight]], [[Bishop]]. [[Queen]], and [[King]] <ref>An example of early-style [https://en.wikipedia.org/wiki/Staunton_chess_set Staunton Chess Set] - Photo used by permission of [http://www.uschess.org/cc/absolute/camarattabio.php Frank A. Camaratta, Jr.]; [https://en.wikipedia.org/wiki/House_of_Staunton The House of Staunton, Inc.]; [http://www.houseofstaunton.com/ houseofstaunton.com], [https://en.wikipedia.org/wiki/Chess_piece Chess piece from Wikipedia], [https://en.wikipedia.org/wiki/Wikimedia_Commons Wikimedia Commons]</ref> ]]

This is about [https://en.wikipedia.org/wiki/Chess_piece Chess Pieces] of Classical or Orthodox Chess. Other chess variants introduce [https://en.wikipedia.org/wiki/Fairy_chess_piece 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 [[Pawn|Pawns]] and even the [[King]], but consider [https://en.wikipedia.org/wiki/Minor_piece#Minor_piece minor pieces], [[Knight]] and [[Bishop]], and the [https://en.wikipedia.org/wiki/Minor_piece#Major_piece major pieces] (also heavy pieces), [[Rook]] and [[Queen]]. Rook, Bishop and Queen are so called [[Sliding Pieces|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|move generation]] issues.
<span id="PieceCoding"></span>
=Piece Coding=
There are six types of pieces for each side, in total twelve different men. Since only one piece may occupy one [[Squares|square]] at a time, one usually expands the range of piece codes with the Nil-Piece aka empty square, often encoded as zero. Depending on the [[Board Representation|board representation]], some programmers introduce an artificial blocking piece, which surrounds the embedded [[8x8 Board|8x8 boards]] inside a [[10x12 Board|10x12 board]] for cheaper off the board tests in offset [[Move Generation|move generation]].

For cheaper extraction, most programmers prefer distinct coding of piece-types and the color of piece. Quite common is to use three bits to encode the piece-type plus one bit or [[Two's Complement]] (not recommend for languages with zero based array indices, like [[C]], [[Cpp|C++]] or [[Java]]) for the color.

Other programs distinguish not only piece-type and color, but enumerate all 32 pieces from their [[Initial Position|initial position]], which label or code does not change during the course of a game (even after a possible [[Promotions|promotion]] of a pawn) and might be one-to-one associated with the bit-position of a 32-bit [[Piece-Sets|piece set]], and/or are used to index a [[Piece-Lists|piece list]] containing the current [[Squares|square]] the piece resides on.

[[Lachex]] for instance used following enumeration scheme: the a1-rook was labeled with 1, b1-knight with 2, a2-pawn with 9, the a8-rook with 17 and the h7-pawn with 32. Beside a [[Bitboard Board-Definition|bitboard board-definition]] using 12 piece [[Bitboards|bitboards]] and [[Occupancy|occupancy]] as union set, Lachex used a redundant [[8x8 Board|8x8 board array]], containing those 1..32 piece-codes, but zero for empty squares. Another piece-array contained the associated piece-types or zero if the piece is missing <ref> [[Burton Wendroff]] ('''1985'''). ''Attack Detection and Move Generation on the [http://www.cisl.ucar.edu/computers/gallery/cray/xmp.jsp X-MP/48].'' [[ICGA Journal|ICCA Journal]], Vol. 8, No. 2</ref>.
<span id="PieceTypeCoding"></span>
==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 [[Material|Piece Values]] and that like. Often the order of enumeration is conform with the value of the pieces, for instance a [[Cpp|C++]] enumeration:
<pre>
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,
};
</pre>

==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) [[Array|arrays]] in [[C]], [[Cpp|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-endian|big end]].
<pre>
PieceCode:4 = 8 * Color:1 + PieceType:3;
</pre>
In C++ as enumeration:
<pre>
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,
};
</pre>
To concatenate piece type and color the other way around is also quite common, color at the [[Little-endian|little end]].
<pre>
PieceCode:4 = 2 * PieceType:3 + Color:1;
</pre>
<span id="DisjointPieceFlags"></span>
==Disjoint Piece Flags==
An alternative coding approach for most efficient inner loops with cheap test-instructions in scanning [[Board Representation|board arrays]] in conjunction with [[Move Generation|move generation]], specially [[Captures|captures]], is to encode pieces by five and up to eight disjoint bits (one [[Byte|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 <ref>[[Fritz Reul]] ('''2009'''). ''New Architectures in Computer Chess'', Ph.D. Thesis, ''Chapter 2 Non-Bitboard Architectures''</ref>:
{| class="wikitable"
|-
! Bit
! Binary
! Semantic
|-
| style="text-align:center;" | 0
| <code>0000 0001</code>
| style="text-align:center;" | White
|-
| style="text-align:center;" | 1
| <code>0000 0010</code>
| style="text-align:center;" | Black
|-
| colspan=3 | combined (ored with)
|-
| style="text-align:center;" | 2
| <code>0000 0100</code>
| style="text-align:center;" | [[Pawn]]
|-
| style="text-align:center;" | 3
| <code>0000 1000</code>
| style="text-align:center;" | [[Knight]]
|-
| style="text-align:center;" | 4
| <code>0001 0000</code>
| style="text-align:center;" | [[Bishop]]
|-
| style="text-align:center;" | 5
| <code>0010 0000</code>
| style="text-align:center;" | [[Rook]]
|-
| style="text-align:center;" | 6
| <code>0100 0000</code>
| style="text-align:center;" | [[Queen]]
|-
| style="text-align:center;" | 7
| <code>1000 0000</code>
| style="text-align:center;" | [[King]]
|}

==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 [[Cpp|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 [https://en.wikipedia.org/wiki/Zillions_of_Games Zillions of Games] or different [https://en.wikipedia.org/wiki/Fairy_chess Fairy Chess] variants, it might be a reasonable idea, to design derived piece classes with virtual functions and late binding during runtime.

==Samples==
* [[Gambiet#PieceCoding|Piece Coding in Gambiet]]

=Value of Pieces=
* [[Influence Quantity of Pieces]]
* [[Point Value]]

''and under the [[Evaluation]] topic:''
* [[Evaluation of Pieces]]
* [[Material]]
* [[Mobility]]
* [[Trapped Pieces]]

=Tactical Properties=
* [[En prise]]
* [[Hanging Piece]]
* [[Loose Piece]]
* [[Overloading]]
<span id="Drawing"></span>
=Printing and Drawing=
* [[2D Graphics Board#Drawing|Drawing Piece Sample Code]]
* [[David Lindsay#ChessFont|Boris Diplomat Chess Piece Font]] by [[David Lindsay]]
<span id="ASCIIArt"></span>
==ASCII Art==
[https://en.wikipedia.org/wiki/ASCII_art ASCII art] chess pieces, collected by Andreas Freise <ref>[http://www.ascii-art.de/ascii/c/chess.txt chess - Ascii Art Dictionary] by [http://www.sr.bham.ac.uk/~adf/ Andreas Freise]</ref>:
<pre>
. +
[] () _,, () ()
)( )( "-=\~ )( )( ()
)( )( )( )( )( )(
ejm97 /__\ /__\ /__\ /__\ /__\ /__\

. +
[] () _,, () ()
)( )( "-X\~ )( )( ()
)( )( )( )( )( )(
ejm97 /XX\ /XX\ /XX\ /XX\ /XX\ /XX\
</pre>
[https://en.wikipedia.org/wiki/ASCII_art ASCII art] [https://en.wikipedia.org/wiki/Staunton_chess_set Staunton chess set] by David Moeser <ref>[http://www.chessvariants.com/d.pieces/ascii.html ASCII Chess Pieces] by [http://www.chessvariants.com/books.html#lotus David Moeser]</ref>
<pre>
.::.
_::_
_/____\_ ()
\ / <~--~>
\____/ \__/ <>_
(____) (____) (\) ) __/"""\
| | | | \__/ WWWWWW ]___ 0 }
|__| | | (____) | | __ / }
/ \ |__| | | | | ( ) /~ }
(______) /____\ |__| |__| || \____/
(________) (______) /____\ /____\ /__\ /____\
/________\ (________) (______) (______) (____) (______)
King Queen Bishop Rook Pawn kNight
</pre>
==<span id="Unicode"></span>Unicode==
* [https://en.wikipedia.org/wiki/Chess_symbols_in_Unicode Chess symbols] in [https://en.wikipedia.org/wiki/Unicode Unicode] <ref>[https://en.wikipedia.org/wiki/Unicode Unicode] representations of [https://en.wikipedia.org/wiki/Chess_symbols_in_Unicode Chess symbols] in two [https://en.wikipedia.org/wiki/Font fonts] ([https://en.wikipedia.org/wiki/Arial_Unicode_MS Arial Unicode MS] and [https://en.wikipedia.org/wiki/Tahoma_%28typeface%29 Tahoma]) by [https://en.wikipedia.org/wiki/User:Monedula Monedula], [https://en.wikipedia.org/wiki/Wikimedia_Commons Wikimedia Commons]</ref>:
: [[FILE:Chess symbols.PNG|none|border|text-bottom|link=https://en.wikipedia.org/wiki/Chess_symbols_in_Unicode]]

=See also=
* [[Piece Drop]]
* [[Piece-Lists]]
* [[Piece Recognition]]
* [[Quad-Bitboards]] for dense "vertical" piece code nibbles

=Forum Posts=
* [https://www.stmintz.com/ccc/index.php?id=176601 Chess piece abbreviations] by [[Bruce Moreland]], [[CCC]], June 23, 2001

=External Links=
* [https://en.wikipedia.org/wiki/Chess_piece Chess piece from Wikipedia]
* [https://en.wikipedia.org/wiki/Lewis_chessmen Lewis chessmen from Wikipedia]
* [https://en.wikipedia.org/wiki/Staunton_chess_set Staunton chess set from Wikipedia]
* [http://www.houseofstaunton.com/ The House of Staunton - Chess Sets and Chess Boards - Manufacturer of the World's Finest Chess Sets and Chess Boards]
* [http://www.fide.com/fide/handbook?id=16&view=category Standards of Chess Equipment and tournament venue for FIDE Tournaments]
* <span id="Pickup"></span>[https://en.wikipedia.org/wiki/Average_White_Band Average White Band] - [https://en.wikipedia.org/wiki/Pick_Up_the_Pieces_(Average_White_Band_song) Pick up the pieces] (1974), [https://en.wikipedia.org/wiki/YouTube YouTube] Video
: {{#evu:https://www.youtube.com/watch?v=MfAJLGFWxYo|alignment=left|valignment=top}}

=References=
<references />
'''[[Chess|Up one Level]]'''

Navigation menu