Re: How to make movelist using bitboards
Posted: Sat Feb 20, 2021 2:30 am
That’s what I explained in my previous post.Luis Babboni wrote: ↑Sat Feb 20, 2021 2:09 am What i do not understand is how to produce EACH possible move.
That’s what I explained in my previous post.Luis Babboni wrote: ↑Sat Feb 20, 2021 2:09 am What i do not understand is how to produce EACH possible move.
Some previous posts have explained already: you need to find indexes of all bit 1s. An index of a bit 1 is the square your piece will move to.Luis Babboni wrote: ↑Sat Feb 20, 2021 2:09 am What i do not understand is how to produce EACH possible move.
How use the byte with ALL (say 3) possible moves for some piece to have EACH move separately.
I think I need them separately.
Code: Select all
01001000
10000000
00000000
00000000
00000000
00000000
00000000
00000000
Code: Select all
00001000
10000000
00000000
00000000
00000000
00000000
00000000
00000000
Code: Select all
while aBB != 0 {
to = pop(aBB);
move = createMove(from, to);
store the move in the moveList
}
Let me ask you, what do need to know to follow the description above?Desperado wrote: ↑Fri Feb 19, 2021 4:28 pmHello Luis,Luis Babboni wrote: ↑Fri Feb 19, 2021 3:15 pm Hi!
I´m a little ashamed cause I cant find what Im looking for so I suspect is very obvious or I missing something important.
I think I´m able to find a bitboard with, for example, a 1 in each of possible moves (say 8) for a given knight and a 0 in all other positions.
My question is how, from that, I could make a list move with those 8 possible moves.
I mean, how to separate each move from others.
Sorry if it is a very stupid question, but I could not find the idea of how make it anywhere. it seems is as obvious that it is not needed to explain it (or as I said, I´m missing something very important)
Thank!
As pointed out by others you need a function to get the index (0...63) of a bit (like bitscan).Code: Select all
bitboard tmpsrc,tmpdst; // 1. the source squares are related to a piece for example tmpsrc = bb_white_knights; // 2.loop that bitboard while (tmpsrc) { // 2.1 pick every (piece) bit you find, you get the source square src = scan_and_remove_bit(tmpsrc) // 2.2 use the source square to generate the attacked squares // target can be empty squares or opponent squares to be captured for example tmpdst = AttackN(src) & target // 2.3 loop the destination squares while (tmpdst) { dst = scan_and_remove_bit(tmpdst) // here you have the pair of squares... store the move in your list. AddMove(src,dst...) } }
Hope that helps.
Code: Select all
onebit = 1
for tosquare=0 to 63 do
if (onebit & bitboard) != 0 then
GenerateMove(fromsquare, tosquare);
endif
onebit = 2*onebit
next tosquare
Code: Select all
while bitboard != 0 do
tosquare = NumberOfTrailingZeros(bitboard)
GenerateMove(fromsquare, tosquare)
bitboard = bitboard & (bitboard - 1)
loop
The move generator might be faster with bitboards than without it. But it is possible that the speed gain for move generation is not as big as you might expect. Usually the bigger gain of using bitboards in a chess engine comes from the evaluation function.Luis Babboni wrote: ↑Sat Feb 20, 2021 2:09 am I understand that the use of bitboards allow you to make a faster move generator than not use it. Is this correct?
The word "byte" may be misleading in this context since in our understanding a byte typically has 8 bits. The 64 bit number you produce is usually called "bitboard".I understand how to produce 64 bits byte with ALL possible moves for each piece.
The bitboard you produce for all possible moves of a given piece represents a set of N target squares (N >= 0), where the position of each "1" relates to one target square. To convert this into a list of N moves you need to create N "move objects" where each object consists of the "from" square that you already know (the square of the given piece), the "to" square which corresponds to one of the 1s in your bitboard, and possibly more information that you store in your "move object" (e.g. a move type, maybe also the type of the captured piece, etc.). If your square representation stored in a move object is not a number between 0 and 63 but something else then you would have to map the 0..63 number to your other representation (but typically a bitboard engine uses 0..63 square encoding everywhere).What i do not understand is how to produce EACH possible move.
How use the byte with ALL (say 3) possible moves for some piece to have EACH move separately.
I think I need them separately.
I guess there is something too obvious or too wrong in my thought that you suppouse I obviously know but I do not know.
I love your explanations!
Very sorry.emadsen wrote: ↑Sat Feb 20, 2021 2:30 amThat’s what I explained in my previous post.Luis Babboni wrote: ↑Sat Feb 20, 2021 2:09 am What i do not understand is how to produce EACH possible move.
The title of your post is How to make movelist using bitboards.