How to implement bitboards?.. and some more questions

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

mar
Posts: 2554
Joined: Fri Nov 26, 2010 2:00 pm
Location: Czech Republic
Full name: Martin Sedlak

Re: How to implement bitboards?.. and some more questions

Post by mar »

Henk wrote:I don't understand why one should use bitboards for generating all moves. The engine can only apply one move at the time, so I need a separate bitboard for each move.

For captures it's a different story. For you only have one capture per direction.
Bitboards are especially effective when generating slider moves, multiply, mask and shift and a couple of lookups (magic bbs) are certainly much faster than iterating over n squares.
Why do you keep talking about movegen, what about eval and mobility?
And why would you want a "separate bitboard" for each move?
Seems to me you're on a trolling spree again, trying to confuse OP :)
Henk
Posts: 7218
Joined: Mon May 27, 2013 10:31 am

Re: How to implement bitboards?.. and some more questions

Post by Henk »

mar wrote:
Henk wrote:I don't understand why one should use bitboards for generating all moves. The engine can only apply one move at the time, so I need a separate bitboard for each move.

For captures it's a different story. For you only have one capture per direction.
Bitboards are especially effective when generating slider moves, multiply, mask and shift and a couple of lookups (magic bbs) are certainly much faster than iterating over n squares.
Why do you keep talking about movegen, what about eval and mobility?
And why would you want a "separate bitboard" for each move?
Seems to me you're on a trolling spree again, trying to confuse OP :)
If I apply a move I apply one move only so if I represent that with a bitboard I need a bitboard with one move only.
Last edited by Henk on Thu Jul 03, 2014 3:06 pm, edited 1 time in total.
mar
Posts: 2554
Joined: Fri Nov 26, 2010 2:00 pm
Location: Czech Republic
Full name: Martin Sedlak

Re: How to implement bitboards?.. and some more questions

Post by mar »

Henk wrote:If I apply a move I apply one move only so if I represent that with a bitboard I need a bitboard with one move only.
I don't get it. You need to update existing bitboard(s) representation when making a move (usually boils down to a simple xor).
If I have a bitboard which contains all moves I need to count these bits to compute mobility. I don't know or understand how counting bits can be implemented fast.
SSE4.2 has popcnt instruction. Other than that you can either use lookup tables/simple loop (masking out LSBit) or clever SWAR,
chessprogramming wiki has (surprisingly :) an excellent article about it: https://chessprogramming.wikispaces.com ... tion+Count
tpetzke
Posts: 686
Joined: Thu Mar 03, 2011 4:57 pm
Location: Germany

Re: How to implement bitboards?.. and some more questions

Post by tpetzke »

... but bitboards are not there for representing moves. You don't need 64 bits for that. Bitboards capture the occupation of squares of a certain piece type or the attack pattern of a certain piece on a certain square.

You can of course use a pair of bitboards to represent a move (a "before" and "after" bitboard and then figure out what move it represents by looking at the difference). But his is probably the most inappropriate usage of bitboards one can think of.
Thomas...

=======
http://macechess.blogspot.com - iCE Chess Engine
mar
Posts: 2554
Joined: Fri Nov 26, 2010 2:00 pm
Location: Czech Republic
Full name: Martin Sedlak

Re: How to implement bitboards?.. and some more questions

Post by mar »

Also bitboards are effective at detecting passers (lookup mask then and with opponent pawns), detecting (semi)open files and more.
ZirconiumX
Posts: 1334
Joined: Sun Jul 17, 2011 11:14 am

Re: How to implement bitboards?.. and some more questions

Post by ZirconiumX »

vittyvirus wrote:To all of you:
Is

Code: Select all

square[21] = 1;
faster than

Code: Select all

square |= &#40;1ULL&#41; << 21;
?
Why is my code fast and slow?[/code]
Fixed that for you.

I do not know much about memory writing, but from what I can tell, it isn't writing memory that makes code slow, it's the reading it afterward.

Reading memory takes about 9 cycles. Reading a register takes 1.

Matthew:out
Some believe in the almighty dollar.

I believe in the almighty printf statement.
User avatar
vittyvirus
Posts: 646
Joined: Wed Jun 18, 2014 2:30 pm
Full name: Fahad Syed

Re: How to implement bitboards?.. and some more questions

Post by vittyvirus »

Can anyone give me one word answer for this: To bitboard or not to bitboard?
zullil
Posts: 6442
Joined: Tue Jan 09, 2007 12:31 am
Location: PA USA
Full name: Louis Zulli

Re: How to implement bitboards?.. and some more questions

Post by zullil »

vittyvirus wrote:Can anyone give me one word answer for this: To bitboard or not to bitboard?
Eventually.
ZirconiumX
Posts: 1334
Joined: Sun Jul 17, 2011 11:14 am

Re: How to implement bitboards?.. and some more questions

Post by ZirconiumX »

vittyvirus wrote:Can anyone give me one word answer for this: To bitboard or not to bitboard?
Yes.

Matthew:out
Some believe in the almighty dollar.

I believe in the almighty printf statement.
User avatar
cdani
Posts: 2204
Joined: Sat Jan 18, 2014 10:24 am
Location: Andorra

Re: How to implement bitboards?.. and some more questions

Post by cdani »

vittyvirus wrote:Can anyone give me one word answer for this: To bitboard or not to bitboard?
Once you get used to it, you "think bitboard" always :-)