Author: KarinsDad
Date: 12:51:10 04/19/99
Go up one level in this thread
On April 19, 1999 at 14:12:51, Alex Boby wrote: > > I have a quick question about bitboards: Say I'm generating the knight >moves and I come up with the attack board for a knight... I then have to parse >that board to find out which bits are true so I can come up with the move list. >I currently just loop through all of them (the bits in the attack board) and see >which ones are lit up but it seems to me like this is very inefficient yet I >can't think of any other way... is there one? Another thing you can do is: If you have a 64 bit structure (or eight 8 bit structures) for the entire board for your bitboard for each color, you can use a special knight lookup table (i.e. a different set of up to 8 values for each of the 64 squares where the knight resides). For each of the (up to) 8 possible entries, you can AND the knight attack board with the value returned from the structure and if it is not equal to zero, you add the move. The code being used to check whether certain bits are turned on knows EXACTLY which of up to 8 possible squares CAN be turned on (based on the knight starting location). Also, you can have another knight table that knows how many times to loop through (i.e. a knight on a1 needs only check the b3 and c2 squares, so you only need to loop through twice). A faster way to do this (without any lookup tables) is to have a different set of code (i.e. one large switch statement) for each of the 64 starting squares. This way, for a given knight starting square, you know exactly which moves can be made and you can hardwire a check for each one. This results in one check (the switch) for the starting square and one check (an IF and an AND) for each possible move. This requires a "switch" statement and 336 "if x and y" statements (2 checks for the a1 square, 8 checks for the c3 square) for all legal knight moves (quite a few pages of code), but it is fairly quick. The downside is that unless you write code to generate the proper values for you, you should doublecheck it with a printout (i.e. for a knight on a1, legal moves are b3 and c2) since it is easy to accidentally screw up the hardcoded values. Hope this helps, KarinsDad :)
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.