Author: Ricardo Gibert
Date: 09:54:51 02/10/03
Go up one level in this thread
On February 09, 2003 at 05:41:55, Albert Bertilsson wrote:
>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;
I would think it ought to look something like this:
return Attacks[WhiteKingPosition - BlackKingPosition]>>KingAttacksBit;
or if you have a PIV and want to avoid the shift, then maybe:
return !!(Attacks[WhiteKingPosition - BlackKingPosition]&KingAttacksBit);
or if you don't care about coercing all the non-zero values to 1, then just:
return Attacks[WhiteKingPosition - BlackKingPosition]&KingAttacksBit;
In all cases, there is only one table lookup and no iftest. The above is what
infer from http://www.seanet.com/~brucemo/topics/0x88.htm under "A Bonus" near
the bottom of the page.
>...
>
>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.