piece- to vs. from- to

Discussion of chess software programming and technical issues.

Moderator: Ras

User avatar
Evert
Posts: 2929
Joined: Sat Jan 22, 2011 12:42 am
Location: NL

Re: piece- to vs. from- to

Post by Evert »

voyagerOne wrote: Another unorthodox method I use is:
I have a bitboard for each piece so 16 bbs not 6 for each color. I also have a unionPawn bb.
How do handle positions with more than the initial number of pieces of one type (two queens being the most obvious example)?
I would say it's overkill. In Jazz I have 6 bitboards for all piece types and 2 for each colour (so to get all white rooks I need to do "all_white_pieces & all_rooks"). Jazz uses copy-move, so I wanted the board structure to be as compact as I can get away with.
My general program (Sjaak) uses a similar approach (but it can handle up to 16 piece types and doesn't use copy-move) except that it distinguishes "north-moving" pawns and "south-moving" pawns.
I am wondering if this is an efficient way...or I should change to 6 bbs.
Not necessarily. Certainly not if the main reason you want to do it is because that's what other people are doing.
Use whatever seems most natural to you.
voyagerOne
Posts: 154
Joined: Tue May 17, 2011 8:12 pm

Re: piece- to vs. from- to

Post by voyagerOne »

Good question.

I have reserved two spots for promotions. (16 and 17)

If promotion and 14(queen) is dead. then 14 is alive.
else
16 = queen.

Same idea for 17 but with knights.

This should cover 99.99999% games played.

However, this is not very elagent. Since I will need to have queens=queen14 | queen16;

So I am on the fence...but am leaning towards 6 bb.
kbhearn
Posts: 411
Joined: Thu Dec 30, 2010 4:48 am

Re: piece- to vs. from- to

Post by kbhearn »

At some point yes, you need to convert your bits into individual moves using bitscan and clearing the bit you scanned each iteration until you're left with an empty bitboard.
voyagerOne
Posts: 154
Joined: Tue May 17, 2011 8:12 pm

Re: piece- to vs. from- to

Post by voyagerOne »

So in the case of Pawns. You just can't generate all moves at once...you will need to take each bit to calculate the moves. If you do all the moves at once...you still need to scan each bit and verify its move.

Am I correct with this statement?

Thanks.
User avatar
Evert
Posts: 2929
Joined: Sat Jan 22, 2011 12:42 am
Location: NL

Re: piece- to vs. from- to

Post by Evert »

voyagerOne wrote:You just can't generate all moves at once...you will need to take each bit to calculate the moves. If you do all the moves at once...you still need to scan each bit and verify its move.
Depends on what you mean by "generate all moves at once".
You can certainly very easily generate all possible pawn move destinations at once using bitshifts and occupancy masks. If you mean "generate a list of from-to tuples", then you first need to loop over the resulting bitboard and extract all the possible pawn destinations one by one (given the destination, you know where the pawn was before).
voyagerOne
Posts: 154
Joined: Tue May 17, 2011 8:12 pm

Re: piece- to vs. from- to

Post by voyagerOne »

Thank you very much Evert. This answers my question.
bob
Posts: 20943
Joined: Mon Feb 27, 2006 7:30 pm
Location: Birmingham, AL

Re: piece- to vs. from- to

Post by bob »

voyagerOne wrote:So in the case of Pawns. You just can't generate all moves at once...you will need to take each bit to calculate the moves. If you do all the moves at once...you still need to scan each bit and verify its move.

Am I correct with this statement?

Thanks.
Not clear. Suppose all pawns are on the original squares for white, a2-h2. I shift the whole mess left 8 bits so that now all pawns are on a3-h3. I find the first one bit which is a3, or bit 16 (a1=0, a2=8) So to=16, from=16-8, and I clear that bit. I find the first one. Which is now b3 or bit 16. To=17, from =17-8, and I clear that bit. Etc...
voyagerOne
Posts: 154
Joined: Tue May 17, 2011 8:12 pm

Re: piece- to vs. from- to

Post by voyagerOne »

Thanks RH. I think I fully understand now.

So do you repeat that for double pushes and attacks?

So a total of 3 cycles?

Thanks in advance.
bob
Posts: 20943
Joined: Mon Feb 27, 2006 7:30 pm
Location: Birmingham, AL

Re: piece- to vs. from- to

Post by bob »

voyagerOne wrote:Thanks RH. I think I fully understand now.

So do you repeat that for double pushes and attacks?

So a total of 3 cycles?

Thanks in advance.
Total of 4. 1 push, double push, then attacks left, followed by attacks right...