Squares

From Chessprogramming wiki
Jump to: navigation, search

Home * Chess * Squares

Piet Mondrian - Tableau I [1]

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

Multiple Squares

Lines

Two squares

Often, but not always related to a move

Areas

The whole Board

Lists, Arrays and Sets of Squares

Pawn Squares

See also

External Links

References

Up one Level