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!
How to make movelist using bitboards
Moderators: hgm, Rebel, chrisw
-
- Posts: 464
- Joined: Sat Feb 28, 2015 4:37 pm
- Location: Argentina
-
- Posts: 7220
- Joined: Mon May 27, 2013 10:31 am
Re: How to make movelist using bitboards
I have a dictionary:
per Square64MoveGEn.
So per bitCoord you can lookup the move for that piece type.
Also found this:
I don't understand why I don't use Index = (int)Math.Log(coord, 2);
instead of creepy debruijn index
Code: Select all
BitCoordMoveDict[] MovesDict{get;}
So per bitCoord you can lookup the move for that piece type.
Also found this:
Code: Select all
IMoveBase[] rep = new MoveBase[64];
BitBoardIndex bbIndex = BitBoardIndex.Instance;
public IMoveBase Get(ulong coord)
{
return rep[bbIndex.Index(coord)];
}
instead of creepy debruijn index
Last edited by Henk on Fri Feb 19, 2021 3:39 pm, edited 5 times in total.
-
- Posts: 759
- Joined: Fri Jan 04, 2013 4:55 pm
- Location: Nice
Re: How to make movelist using bitboards
Isa download :
-
- Posts: 464
- Joined: Sat Feb 28, 2015 4:37 pm
- Location: Argentina
Re: How to make movelist using bitboards
Sorry, not understand.
I need ot have a list of all moves and use the bitboard I said to check each of the total moves to know wich is possible and wich no? I do not think that.
It seems I do not understand the background idea.
I need ot have a list of all moves and use the bitboard I said to check each of the total moves to know wich is possible and wich no? I do not think that.
It seems I do not understand the background idea.
-
- Posts: 464
- Joined: Sat Feb 28, 2015 4:37 pm
- Location: Argentina
Re: How to make movelist using bitboards
At least for the moment I do not looking for the code.
I need first to understand the idea.
I need first to understand the idea.
-
- Posts: 464
- Joined: Sat Feb 28, 2015 4:37 pm
- Location: Argentina
Re: How to make movelist using bitboards
Sorry, is not easy to explain me!
I did a not bug chess engine yet, Soberango, but I have very little know in programming and nothing in C. I did it in FreeBasic.
i have, i think, a reasonabily understanding of maths, so this is not a problem.
I did a not bug chess engine yet, Soberango, but I have very little know in programming and nothing in C. I did it in FreeBasic.
i have, i think, a reasonabily understanding of maths, so this is not a problem.
-
- Posts: 7220
- Joined: Mon May 27, 2013 10:31 am
Re: How to make movelist using bitboards
I don't know or can''t remember. Just google it.
I only have this you have to bitshift bitboard moves in a direction 6 times
For straight moves to the right:
Too complicated.
I only have this you have to bitshift bitboard moves in a direction 6 times
For straight moves to the right:
Code: Select all
Moves(straightOccupancyBB & rightMovesBB, leftShift, 1, rightMovesBB)
public static UInt64 Moves(UInt64 occupiedDirMoves, IShiftOperator shift, int multiplier, UInt64 locationDirMoves)
=>
locationDirMoves ^ (
(
shift.Shift(occupiedDirMoves, multiplier)
| shift.Shift(occupiedDirMoves, 2 * multiplier)
| shift.Shift(occupiedDirMoves, 3 * multiplier)
| shift.Shift(occupiedDirMoves, 4 * multiplier)
| shift.Shift(occupiedDirMoves, 5 * multiplier)
| shift.Shift(occupiedDirMoves, 6 * multiplier)
) & locationDirMoves
)
);
-
- Posts: 27808
- Joined: Fri Mar 10, 2006 10:06 am
- Location: Amsterdam
- Full name: H G Muller
Re: How to make movelist using bitboards
Most modern CPUs have an instruction BSF (BitScanForward) which gives the number of trailing zero bits in the operand. Bitboard engines use that to get the square number of a target square indicated in the bitboard bb. This can then be removed from the bitboard by calculating the bitwise AND operation of bb AND bb-1, after which you can 'extract' the square number of the next target square in the same way. Until finally the entire remaining bb is zero, because all targets have been processed.
C/C++ does not support BSF in its language, but many compilers offer functions (written in assembler) to calculate it. If your BASIC doesn't, then you are out of luck.
There is an older method from before CPUs had BSF, which extracts the lowest 1 bit (by calculating bb AND -bb), multiplies it with a magic 'DeBruin' constant,shifts it to the right 58 places, and uses the 6-bit number that is left in a lookup table that then gives the square number.
C/C++ does not support BSF in its language, but many compilers offer functions (written in assembler) to calculate it. If your BASIC doesn't, then you are out of luck.
There is an older method from before CPUs had BSF, which extracts the lowest 1 bit (by calculating bb AND -bb), multiplies it with a magic 'DeBruin' constant,shifts it to the right 58 places, and uses the 6-bit number that is left in a lookup table that then gives the square number.
-
- Posts: 879
- Joined: Mon Dec 15, 2008 11:45 am
Re: How to make movelist using bitboards
Hello 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!
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.
Last edited by Desperado on Fri Feb 19, 2021 4:46 pm, edited 2 times in total.
-
- Posts: 7220
- Joined: Mon May 27, 2013 10:31 am
Re: How to make movelist using bitboards
I don't understand his question. For getting first bit I use this.
Code: Select all
/// <returns>least significant bit</returns>
public static UInt64 First(UInt64 bits)
=> bits & (~bits + 1);
/// <returns>bits - least significant bit</returns>
public static UInt64 Rest(UInt64 bits)
{
var res = bits & (bits - 1);
Debug.Assert(res == bits - First(bits));
return res;
}