Home
Download
How Computers
play chess
How NagaSkaki
plays chess
Tips for writing a
chess program
|
How NagaSkaki plays chess
NagaSkaki is a young program and a lot of enhancements
must still be implemented in its engine. Here is a summary of its current
engine:
-
The chessboard is represented with bitboards.
-
Searching is done with an alpha beta algorithm with:
extensions (check, recapture, etc.), lazy evaluation and futility
pruning
-
It uses Null move forward pruning in the opening,
middle game and ending when both sides have at least one piece (with
R=2 and R=3).
-
NagaSkaki's positional knowledge has not been fine
tuned and it seems to play rather aggressive.
-
It uses a small opening book that can handle transpositions.
-
Other features it has: Killer moves, History heuristics,
quiescence search, Aspiration window and Transposition tables.
Move Generation is a bit different than the normal
rotated bitboards (Actually they're not rotated at all!) and works as
follows:
-
First Generate a bitboard of all squares occupied
by pieces.
-
Next all the bits, except those in the direction
we want to move (left, right, up and down for rook), are deleted.
-
Now we "shift" all the bits to the direction we want
to move, e.g. for a rook moving right from the A file: The occupied
board 0001 1010 becomes: 0000 1101 | 0000 0110 | 0000 0011 = 0000
1111 (I only show the occupied rank - of course the whole bitboard
consists of 64 bits.)
-
We then XOR the bits, so that all bits where we can
move are set (1111 0000).
-
AND the result with all bits, except those where
our own pieces are, so that we only generate captures of enemy pieces
and not our own.
-
Lastly, convert the bitboard to moves.
Here is an example of the generation of horizontal rook
moves:
bitboard rightboard = (occupiedboard & rookXrays[sq][0]);
//rookXrays[sq][0] is all bits to the right of rook
rightboard = rightboard<<1|rightboard<<2|rightboard<<3|rightboard<<4|rightboard<<5|rightboard<<6;
rightboard&=rookXrays[sq][0];
rightboard=(rightboard^rookXrays[sq][0]) & notfriendlyboard;
bitboard leftboard = (occupiedboard & rookXrays[sq][2]); //rookXrays[sq][2]
is all bits to the left of rook
leftboard=leftboard>>1|leftboard>>2|leftboard>>3|leftboard>>4|leftboard>>5|leftboard>>6;
leftboard&=rookXrays[sq][2];
leftboard=(leftboard^rookXrays[sq][2]) & notfriendlyboard;
bitboardToMoves(rightboard|leftboard);
Last updated: 22 March 2004
|