//some code for the generation of knight moves
U64 KNIGHT_LOOKUP_TABLE[64] = {
0x0000000000020400ULL, 0x0000000000050800ULL, 0x00000000000A1100ULL, 0x0000000000142200ULL,
... and on};
U64 knights = whiteKnights;
U64 possibleMoves = enemy|empty;
//code inside the loop is incomplete btw
while(whiteKnights){
from = bit_scan_forward(knights);
targets = KNIGHT_LOOKUP_TABLE[from] & possibleMoves;
}
is this how it works?
from = bit_scan_forward(knights) finds the position of the knight; say the first knight is on c3.
is the index to KNIGHT_LOOKUP_TABLE a bit? say that the location of the knight is c3 which is bit 2 in the knight look up table, ie.,KNIGHT_LOOKUP_TABLE[2] = 0x00000000000A1100ULL
Pre computed look up tables
Moderator: Ras
-
AlvaroBegue
- Posts: 932
- Joined: Tue Mar 09, 2010 3:46 pm
- Location: New York
- Full name: Álvaro Begué (RuyDos)
Re: Pre computed look up tables
Looking at the patterns in the table, it looks like the convention is that c3 is bit 18. So you'll read KNIGHT_LOOKUP_TABLE[18], which will contain the bit pattern of the squares that can be reached from a knight at c3. Then targets will be the intersection of those locations with the locations that are possible destinations for white pieces (i.e., black or empty).
Perhaps I didn't understand what part you are having trouble with...
EDIT: It could be 22 or something else instead of 18. I can't tell from that piece of code.
Perhaps I didn't understand what part you are having trouble with...
EDIT: It could be 22 or something else instead of 18. I can't tell from that piece of code.
-
acetylmine
- Posts: 2
- Joined: Fri May 27, 2016 10:21 pm
Re: Pre computed look up tables
Yes, c3 is bit 18. Your right.
I wanted to know if c3 = bit 18 is used to index the KNIGHT_LOOKUP_TABLE[64].
So,
KNIGHT_LOOKUP_TABLE[18] = the 18th element in the array which is the bitboard with 1 bits on each square the knight can reach from c3.
I wanted to know if c3 = bit 18 is used to index the KNIGHT_LOOKUP_TABLE[64].
So,
KNIGHT_LOOKUP_TABLE[18] = the 18th element in the array which is the bitboard with 1 bits on each square the knight can reach from c3.
-
AlvaroBegue
- Posts: 932
- Joined: Tue Mar 09, 2010 3:46 pm
- Location: New York
- Full name: Álvaro Begué (RuyDos)
Re: Pre computed look up tables
Yup, you got it.