Changes

Jump to: navigation, search

8x8 Board

1,955 bytes added, 02:42, 6 March 2021
Precalculate data
==Precalculate data==
Some programs pre-calculate data for each cell and extract it when generating moves. That method is well-known mentioned by [[Hans Eric Sandstroem]] in [[GNU Chess]] version 4.0 document , 6 Sep 1989: <pre>The general idea behind this algoritm is to pre calculatea lot of data. The data that is pre calculated is every possible movefor every piece from every square disregarding any other pieces on theboard. This pre calculated data is stored in an array that looks likethis: struct sqdata { short nextpos; short nextdir;};struct sqdata posdata[8][64][64];/* posdata[piecetype][fromsquare][destinationsquare] */example: the first move for a queen at e8 is stored at; posdata[queen][e8][e8].nextpos suppose this is e7 and e7 is occupied then the next move will be found in; posdata[queen][e8][e7].nextdir To handle the differeces between white and black pawns (they move inopposite directions) an array ptype has been introduced: static const short ptype[2][8] = { no_piece,pawn,knight,bishop,rook,queen,king,no_piece, no_piece,bpawn,knight,bishop,rook,queen,king,no_piece}; ^^^^^And it is used like this: piecetype = ptype[side][piece]When generating moves for pieces that are not black pawns, piececan be used directly in posdata. As in the example above. Thus the only thing one has to do when generating the movesis to check for collisions with other pieces. the move generation to do this looks like this: (for non pawns) p = posdata[piece][sq]; u = p[sq].nextpos; do { if (color[u] == neutral) { LinkMove(ply,sq,u,xside); u = p[u].nextpos; } else { if (color[u] == xside) LinkMove(ply,sq,u,xside); u = p[u].nextdir; } } while (u != sq);  - I`nt this just beautiful! The array posdata is initialized in the routine Initialize_moves.This routine is called just once and it works so no time has been spenton the structure of this code).GenMoves and CaptureList generates themoves but the routines ataks, BRscan, Sqatakd, KingScan and trappedalso relies on the move generation algoritm so they have also beenrewritten. </pre>
=Alternatives=

Navigation menu