Author: Albert Bertilsson
Date: 02:41:55 02/09/03
Recently I tested a thought on how to optimize my InCheck test routine...
When testing if the player king was next to the opponent king after a move I did
this:
...
for (direction = 0 ; direction < 8 ; direction++)
{
pos = square + Direction[direction];
if (!(pos & 0x88) && myBoardOpponent[pos] == King)
return true;
}
...
I thought this could be optimized by using a table lookup to the KingAttacks
like this:
...
if (Bit[myKingPosOpponent] & KingAttacks[myKingPosPlayer]) return true;
...
No loops, just a two table lookups....
When I tested it, it turned out that the table lookup was slightly SLOWER!?
Are there any general rules to tell when a table lookup is more efficient?
This is a very simple loop, but it still involves looking at the board eight
times, so I guess it's quite close the point where a table lookup is more
effiecient.
System is a Athlon XP 1800+ with SDRAM, if it matters.
/Regards Albert Bertilsson
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.