Difference between revisions of "8x8 Board"

From Chessprogramming wiki
Jump to: navigation, search
 
(12 intermediate revisions by 2 users not shown)
Line 6: Line 6:
 
Such a board representation is often used redundantly in [[Bitboards|bitboard]] programs to answer the question which piece (if any) resides on a square efficiently. It has to deal with [[Square Mapping Considerations|square mapping]] accordantly.  
 
Such a board representation is often used redundantly in [[Bitboards|bitboard]] programs to answer the question which piece (if any) resides on a square efficiently. It has to deal with [[Square Mapping Considerations|square mapping]] accordantly.  
  
 +
=Programming=
 +
==TSCP==
 +
[[TSCP]] uses two 64 element arrays, containing empty square plus [[Pieces#PieceTypeCoding|pure piece code]], and  empty square plus piece color code <ref>[https://jim.sh/svn/jim/vendor/microwindows/current/src/demos/tuxchess/data.c TSCP - data.c]</ref>:.
 +
<pre>
 +
int color[64];  /* LIGHT, DARK, or EMPTY */
 +
int piece[64];  /* PAWN, KNIGHT, BISHOP, ROOK, QUEEN, KING, or EMPTY */
 +
</pre>
 +
 +
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.
 +
 +
<pre>
 +
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
 +
};
 +
</pre>
 +
 +
==Banksia==
 +
[[Banksia]] uses only one vector from C++ standard library <ref>https://github.com/nguyenpham/Banksia/blob/master/src/base/base.h Banksia - base.h</ref>:
 +
<pre>
 +
std::vector<Piece> pieces;
 +
</pre>
 +
 +
The vector is initialized <ref>https://github.com/nguyenpham/Banksia/blob/master/src/chess/chess.cpp Banksia - chess.cpp</ref>:
 +
<pre>
 +
Piece empty(PieceType::empty, Side::none);
 +
for(int i = 0; i < 64; i++) {
 +
    pieces.push_back(empty);
 +
}
 +
</pre>
 
=Alternatives=  
 
=Alternatives=  
As a lone board representation, the 8x8 board has some efficiency issues with [[Move Generation|move generation]] related to off the board test. Therefore more common are approaches dealing with that, that is [[10x12 Board|10x12 board]] with surrounding ranks and files, and [[Vector Attacks]] with its cheap test and unique square difference property with respect to [[Distance|distance]] and [[Direction|direction]] <ref>[[Fritz Reul]] ('''2009'''). ''New Architectures in Computer Chess''. Ph.D. Thesis, ''2 Non-Bitboard Architectures''</ref>. In ''Games Playing with Computers'', 1972 <ref>[http://www.chilton-computing.org.uk/acl/literature/books/gamesplaying/p003.htm Chapter 3: Board Games - 3.1 CHESS] from [[Alex Bell]] ('''1972'''). ''[http://www.chilton-computing.org.uk/acl/literature/books/gamesplaying/overview.htm Games Playing with Computers]''. [https://en.wikipedia.org/wiki/Allen_%26_Unwin Allen & Unwin], ISBN-13: 978-0080212227</ref> , [[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.
+
As a lone board representation, the 8x8 board has some efficiency issues with [[Move Generation|move generation]] related to off the board test. Therefore more common are approaches dealing with that, that is [[10x12 Board|10x12 board]] with surrounding ranks and files, and [[Vector Attacks]] with its cheap test and unique square difference property with respect to [[Distance|distance]] and [[Direction|direction]] <ref>[[Fritz Reul]] ('''2009'''). ''New Architectures in Computer Chess''. Ph.D. Thesis, ''2 Non-Bitboard Architectures''</ref>. In ''Games Playing with Computers'', 1972 <ref>[http://www.chilton-computing.org.uk/acl/literature/books/gamesplaying/p003.htm Chapter 3: Board Games - 3.1 CHESS] from [[Alex Bell]] ('''1972'''). ''[http://www.chilton-computing.org.uk/acl/literature/books/gamesplaying/overview.htm Games Playing with Computers]''. [https://en.wikipedia.org/wiki/Allen_%26_Unwin Allen & Unwin], ISBN-13: 978-0080212227</ref> , [[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 Generation|table driven move generator]].
  
 
=See also=  
 
=See also=  
Line 14: Line 64:
 
* [[Bitboards]]
 
* [[Bitboards]]
 
: [[Square Mapping Considerations]]
 
: [[Square Mapping Considerations]]
 +
* [[Table-driven Move Generation]]
 
* [[Vector Attacks]]
 
* [[Vector Attacks]]
 
: [[0x88]]
 
: [[0x88]]
Line 24: Line 75:
 
* [https://www.stmintz.com/ccc/index.php?id=178465 Fastest Conversion from 0x88 board to 8x8 board representation] by [[Artem Petakov|Artem Pyatakov]], [[CCC]], July 06, 2001
 
* [https://www.stmintz.com/ccc/index.php?id=178465 Fastest Conversion from 0x88 board to 8x8 board representation] by [[Artem Petakov|Artem Pyatakov]], [[CCC]], July 06, 2001
 
* [https://www.stmintz.com/ccc/index.php?id=189800 Re: Ferret/Gerbil question] by [[Bruce Moreland]], [[CCC]], September 21, 2001 » [[Ferret]], [[Gerbil]], [[0x88]]
 
* [https://www.stmintz.com/ccc/index.php?id=189800 Re: Ferret/Gerbil question] by [[Bruce Moreland]], [[CCC]], September 21, 2001 » [[Ferret]], [[Gerbil]], [[0x88]]
 +
* [http://www.talkchess.com/forum3/viewtopic.php?f=7&t=76817 C++ code for <nowiki>board[8][8]</nowiki> representation] by [[Yves De Billoëz]], [[CCC]], March 08, 2021
 +
: [http://www.talkchess.com/forum3/viewtopic.php?f=7&t=76817&start=4 Re: C++ code for <nowiki>board[8][8]</nowiki> representation] by [[Rein Halbersma]], [[CCC]], March 08, 2021 » [[Cpp|C++]]
  
 
=External Links=
 
=External Links=
Line 30: Line 83:
 
* [http://www.chilton-computing.org.uk/acl/literature/books/gamesplaying/p003.htm Chapter 3: Board Games - 3.1 CHESS] from [[Alex Bell]] ('''1972'''). ''[http://www.chilton-computing.org.uk/acl/literature/books/gamesplaying/overview.htm Games Playing with Computers]''. [https://en.wikipedia.org/wiki/Allen_%26_Unwin Allen & Unwin], ISBN-13: 978-0080212227
 
* [http://www.chilton-computing.org.uk/acl/literature/books/gamesplaying/p003.htm Chapter 3: Board Games - 3.1 CHESS] from [[Alex Bell]] ('''1972'''). ''[http://www.chilton-computing.org.uk/acl/literature/books/gamesplaying/overview.htm Games Playing with Computers]''. [https://en.wikipedia.org/wiki/Allen_%26_Unwin Allen & Unwin], ISBN-13: 978-0080212227
 
* [https://en.wikipedia.org/wiki/8_x_8:_A_Chess_Sonata_in_8_Movements 8 x 8: A Chess Sonata in 8 Movements] (1957) directed by  [https://en.wikipedia.org/wiki/Hans_Richter_%28artist%29 Hans Richter], [[:Category:Marcel Duchamp|Marcel Duchamp]] and [https://en.wikipedia.org/wiki/Jean_Cocteau Jean Cocteau], [https://en.wikipedia.org/wiki/YouTube YouTube] Video
 
* [https://en.wikipedia.org/wiki/8_x_8:_A_Chess_Sonata_in_8_Movements 8 x 8: A Chess Sonata in 8 Movements] (1957) directed by  [https://en.wikipedia.org/wiki/Hans_Richter_%28artist%29 Hans Richter], [[:Category:Marcel Duchamp|Marcel Duchamp]] and [https://en.wikipedia.org/wiki/Jean_Cocteau Jean Cocteau], [https://en.wikipedia.org/wiki/YouTube YouTube] Video
: Cast <ref>[http://www.imdb.com/title/tt0122855/fullcredits?ref_=tt_ov_st_sm 8 X 8: A Chess Sonata in 8 Movements (1957) - Full Cast & Crew - IMDb]</ref>: [https://en.wikipedia.org/wiki/Jean_Arp Jean Arp], [https://en.wikipedia.org/wiki/Paul_Bowles Paul Bowles], [http://www.imdb.com/name/nm2701438/ Ceal Bryson], [https://en.wikipedia.org/wiki/Alexander_Calder Alexander Calder], [https://en.wikipedia.org/wiki/Jean_Cocteau Jean Cocteau], [http://www.imdb.com/name/nm0212232/?ref_=ttfc_fc_cl_t6 Willem de Vogel], [[Arts#Tanning|Dorothea Tanning]]
+
: Cast <ref>[http://www.imdb.com/title/tt0122855/fullcredits?ref_=tt_ov_st_sm 8 X 8: A Chess Sonata in 8 Movements (1957) - Full Cast & Crew - IMDb]</ref>: [https://en.wikipedia.org/wiki/Jean_Arp Jean Arp], [https://en.wikipedia.org/wiki/Paul_Bowles Paul Bowles], [http://www.imdb.com/name/nm2701438/ Ceal Bryson], [https://en.wikipedia.org/wiki/Alexander_Calder Alexander Calder], [https://en.wikipedia.org/wiki/Jean_Cocteau Jean Cocteau], [http://www.imdb.com/name/nm0212232/?ref_=ttfc_fc_cl_t6 Willem de Vogel], [[:Category:Dorothea Tanning|Dorothea Tanning]]
: [[Arts#Ernst|Max Ernst]], [https://en.wikipedia.org/wiki/Richard_Huelsenbeck Richard Huelsenbeck], [https://en.wikipedia.org/wiki/Frederick_John_Kiesler Frederick Kiesler], [http://www.imdb.com/name/nm1508036/?ref_=ttfc_fc_cl_t12 Julien Lary], [https://en.wikipedia.org/wiki/Julien_Levy Julien Levy], [http://www.imdb.com/name/nm1506477/?ref_=ttfc_fc_cl_t14 Jaqueline Matisse], [http://www.imdb.com/name/nm2692339/?ref_=ttfc_fc_cl_t15 Eugene Pellegrini], [[Arts#Ray|Man Ray]], [https://en.wikipedia.org/wiki/Yves_Tanguy Yves Tanguy]
+
: [[:Category:Max Ernst|Max Ernst]], [https://en.wikipedia.org/wiki/Richard_Huelsenbeck Richard Huelsenbeck], [https://en.wikipedia.org/wiki/Frederick_John_Kiesler Frederick Kiesler], [http://www.imdb.com/name/nm1508036/?ref_=ttfc_fc_cl_t12 Julien Lary], [https://en.wikipedia.org/wiki/Julien_Levy Julien Levy], [http://www.imdb.com/name/nm1506477/?ref_=ttfc_fc_cl_t14 Jaqueline Matisse], [http://www.imdb.com/name/nm2692339/?ref_=ttfc_fc_cl_t15 Eugene Pellegrini], [[:Category:Man Ray|Man Ray]], [https://en.wikipedia.org/wiki/Yves_Tanguy Yves Tanguy]
 
: {{#evu:https://www.youtube.com/watch?v=gMIBbesWJDA|alignment=left|valignment=top}}
 
: {{#evu:https://www.youtube.com/watch?v=gMIBbesWJDA|alignment=left|valignment=top}}
  
Line 39: Line 92:
 
'''[[Mailbox|Up one Level]]'''
 
'''[[Mailbox|Up one Level]]'''
 
[[Category:Marcel Duchamp]]
 
[[Category:Marcel Duchamp]]
 +
[[Category:Max Ernst]]
 +
[[Category:Man Ray]]
 +
[[Category:Dorothea Tanning]]
 +
[[Category:Film]]

Latest revision as of 00:09, 9 March 2021

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