Squares

Home * Chess * Squares



A Square in chess is one of 64 elements of a chessboard, which might be empty or occupied by a chess man. Square centric representations, like mailbox or 0x88 board arrays, contain piece codes, the information, what piece, if any, resides on a particular square. The piece centric bitboard, as array of 64 bits, represent a boolean property of each square by a single bit.

Depending on the underlying data structure of the board representation, each square has an address inside the board. Square centric representations keep arrays of squares, containing the information which piece (if any) resides on each square. That is why these representation is often called mailbox approach, since each square has a associated mailbox which is either empty or contains a chess piece. To find the address of a certain square index in the a1..h8 aka 0..63 range sometimes requires additional computation or lookup, for instance to map coordinates for 0x88 boards or surrounded mailbox boards.

In bitboards the address of a square correspondents to a bit-index, containing a boolean property of that square (bit set), or not (bit clear). The square mapping determines how bit-indices associate the squares on the board.

=Square by Rank and File= A Square, like a point inside a cartesian coordinate system, can be determined by x- and y-coordinates, here the labels of files and ranks. Since each rank and file has eight squares, the mentioned rank-file mapping implies following formulas to determine the the square address: square = 8*rank + file; square = (rank << 3) + file; with the obvious relation to calculate rank- and file-indices from the square index: rank = square >> 3; // div 8 file = square & 7; // modulo 8 =Algebraic Square Notation= In algebraic chess notation a target square of a move is specified by two characters for its cartesian coordinate, per convention a letter for the file ('a'-'h'), followed by a digit for the rank number ('1'-'8').

=Square Definition= A typical little-endian rank-file mapping enumeration in C++: enum enumSquare { a1, b1, c1, d1, e1, f1, g1, h1, a2, b2, c2, d2, e2, f2, g2, h2, a3, b3, c3, d3, e3, f3, g3, h3, a4, b4, c4, d4, e4, f4, g4, h4, a5, b5, c5, d5, e5, f5, g5, h5, a6, b6, c6, d6, e6, f6, g6, h6, a7, b7, c7, d7, e7, f7, g7, h7, a8, b8, c8, d8, e8, f8, g8, h8 };

=Square Properties=
 * Center Distance
 * Center Manhattan-Distance
 * Color of a Square
 * Occupancy
 * Square Attacked By
 * Square Control

=Multiple Squares=

Lines

 * Ranks
 * Files
 * Diagonals
 * Anti-Diagonals
 * Rays as subset of Lines
 * Line-masks from Bitboards

Two squares
Often, but not always related to a move
 * Origin Square
 * Target Square
 * Distance
 * Manhattan-Distance
 * Knight-Distance
 * Direction
 * 0x88 Square Relations
 * In Between
 * Intersection Squares
 * Butterfly Boards

Areas

 * Center
 * Wings

The whole Board
Lists, Arrays and Sets of Squares
 * Chessboard
 * Board Representation
 * Mailbox
 * Vector Attacks
 * Bitboards
 * Flipping Mirroring and Rotating
 * Square Mapping Considerations
 * Setwise Rule of the Square
 * Quad-Bitboards

=Pawn Squares=
 * En passant
 * En passant target square inside the Forsyth-Edwards Notation
 * Promotion Square
 * Stop Square
 * Stop and Telestop

=See also=
 * Corresponding Squares

=External Links=
 * Square from Wikipedia
 * Magic square from Wikipedia
 * The Euler's 8x8 magic square - Chess.com

=References=

Up one Level