Author: Graham Banks
Date: 12:29:09 09/16/04
Dann Corbit remarked that he was greatly impressed with Thinker 4.6c's strong
performances considering the small size of the program. Here is Lance Perkins'
(Programmer of Thinker) reply:
The next release (in a few weeks) of Thinker will even be smaller (from 77K to
69K). I am replacing all of the experimental code with better implementation,
now that I am contented with the results.
I have below an example of the efficient coding that is in Thinker. This is the
entire move generator (the GeneratePawnMoves is similar to the
GeneratePieceMoves). Other implementations that also use bitboards have at least
five times the source code compared to my implementation.
TMove *CPosition::GeneratePieceMoves (TMove *pmoves, TBitBoard target)
{
TBitBoard pieces = AllPieces (wtm) ^ Pawns (wtm);
while (pieces)
{
TBitBoard moves;
TSquare from = FindBitAndClear(pieces);
TPieceType pct = PieceType (BoardPiece (from));
switch (pct)
{
case Knight:
moves = KnightAttacks (from) & target;
break;
case Bishop:
moves = BishopAttacks (from) & target;
break;
case Rook:
moves = RookAttacks (from) & target;
break;
case Queen:
moves = QueenAttacks (from) & target;
break;
case King:
moves = KingAttacks (from) & target;
break;
}
if (moves)
{
TMove mv = MvMkFrom (from) + MvMkPiece (pct);
do
{
TSquare to = FindBitAndClear(moves);
*pmoves++ = mv | MvMkTo (to) | CaptureOnSq (to);
}
while (moves);
}
}
return (pmoves);
}
#define EmptySquares() (~(AllPieces(White)|AllPieces(Black)))
TMove *CPosition::GenerateCaptureAndPromotionMoves (TMove *pmoves) // used by
q-search and gen-all-moves
{
pmoves = GeneratePieceMoves (pmoves, AllPieces (Opponent (wtm)));
return GeneratePawnMoves (pmoves, AllPieces (Opponent (wtm)) |
c_PromotionSquares);
}
TMove *CPosition::GenerateNonCaptureMoves (TMove *pmoves)
{
pmoves = GeneratePieceMoves (pmoves, EmptySquares());
return GeneratePawnMoves (pmoves, EmptySquares() | c_NonPromotionSquares);
}
TMove *CPosition::GenerateAllMoves (TMove *pmoves)
{
pmoves = GenerateCaptureAndPromotionMoves (pmoves);
return GenerateNonCaptureMoves (pmoves);
}
This page took 0 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.