8x8 Board

From Chessprogramming wiki
Jump to: navigation, search

Home * Board Representation * Mailbox * 8x8 Board

8x8 Board [1]

The 8x8 Board as basic square-centric board representation is either a two-dimensional array of bytes (or integers), containing piece and empty square codes, indexed by file and rank index, or more commonly a one-dimensional array indexed by a square in a 0..63 range which combines rank or file indices in three consecutive bits each [2] . Such a board representation is often used redundantly in bitboard programs to answer the question which piece (if any) resides on a square efficiently. It has to deal with square mapping accordantly.

Programming

TSCP

TSCP uses two 64 element arrays, containing empty square plus pure piece code, and empty square plus piece color code [3]:.

int color[64];  /* LIGHT, DARK, or EMPTY */
int piece[64];  /* PAWN, KNIGHT, BISHOP, ROOK, QUEEN, KING, or EMPTY */

However, when generating moves, TSCP converts the board data into a bigger array 10x12 Board.

FirstChess

FirstChess uses two 64 integer arrays, for all tasks, including move generating.

int piece[64] = {
    ROOK,  KNIGHT,BISHOP,QUEEN, KING,  BISHOP,KNIGHT,ROOK,
    PAWN,  PAWN,  PAWN,  PAWN,  PAWN,  PAWN,  PAWN,  PAWN,
    EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY,
    EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY,
    EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY,
    EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY,
    PAWN,  PAWN,  PAWN,  PAWN,  PAWN,  PAWN,  PAWN,  PAWN,
    ROOK,  KNIGHT,BISHOP,QUEEN, KING,  BISHOP,KNIGHT,ROOK
};

int color[64] = {
    BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK,
    BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK,
    EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY,
    EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY,
    EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY,
    EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY,
    WHITE, WHITE, WHITE, WHITE, WHITE, WHITE, WHITE, WHITE,
    WHITE, WHITE, WHITE, WHITE, WHITE, WHITE, WHITE, WHITE
};

Banksia

Banksia uses only one vector from C++ standard library [4]:

std::vector<Piece> pieces;

The vector is initialized [5]:

Piece empty(PieceType::empty, Side::none);
for(int i = 0; i < 64; i++) {
    pieces.push_back(empty);
}

Alternatives

As a lone board representation, the 8x8 board has some efficiency issues with move generation related to off the board test. Therefore more common are approaches dealing with that, that is 10x12 board with surrounding ranks and files, and Vector Attacks with its cheap test and unique square difference property with respect to distance and direction [6]. In Games Playing with Computers, 1972 [7] , Alex Bell introduced an array of 65 squares, where the purpose of square 65 (always empty) is to detect pawns capturing outside the board by a table driven move generator.

See also

Square Mapping Considerations
0x88

Publications

Forum Posts

Re: C++ code for board[8][8] representation by Rein Halbersma, CCC, March 08, 2021 » C++

External Links

Cast [8]: Jean Arp, Paul Bowles, Ceal Bryson, Alexander Calder, Jean Cocteau, Willem de Vogel, Dorothea Tanning
Max Ernst, Richard Huelsenbeck, Frederick Kiesler, Julien Lary, Julien Levy, Jaqueline Matisse, Eugene Pellegrini, Man Ray, Yves Tanguy

References

Up one Level