How to implement bitboards?.. and some more questions

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

User avatar
pocopito
Posts: 238
Joined: Tue Jul 12, 2011 1:31 pm

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

Post by pocopito »

To bitboard.

Bitboards aren't only very efficient for the moves generator, but also are really efficient in the evaluation because you have a lot of important information already stored on them, and a fast way (bitwise operators) to combine them to get extra info (passed pawns, doubled pawns, etc).

As a summary, bitboards representation provide an efficient framework to get info from the position on the board.
Two first meanings of the dutch word "leren":
1. leren [vc] (learn, larn, acquire) acquire or gain knowledge or skills.
2. leren [v] (teach, learn, instruct) impart skills or knowledge to.
Henk
Posts: 7218
Joined: Mon May 27, 2013 10:31 am

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

Post by Henk »

I know nothing about it.

[
Even if I would have a bitboard with all possible moves for a piece I don't know how I can iterate over these moves efficiently. Could be it is described many times but I haven't found it.

Maybe such a bitboard is useless for that purpose. So perhaps one has to go back and test some predefined bits starting from a location in a bitboard and test if it is occupied or not ?
]
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 »

Doing something with the set bits of a bitboard:

Code: Select all

while (BitScanForward(&indexbit, bitboardvar)) {
		bitboardvar &= bitboardvar - 1;  //unset the bit 
		//do something with indexbit, for example put in an array

	}
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 »

zullil wrote:
vittyvirus wrote:Can anyone give me one word answer for this: To bitboard or not to bitboard?
Eventually.
Since you are a beginner, I feel you should start with an array-based board representation (of your own design) and see if you can write a correct move-generator.

My fear is, that in your rush to "create" the next 3000+ engine, you will end up "borrowing" a lot of code without gaining any real understanding of what it means to write a chess program.

So save bitboards for version 2. Just my 2¢, but I'm not even a programmer.
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 »

zullil wrote: Since you are a beginner, I feel you should start with an array-based board representation (of your own design) and see if you can write a correct move-generator.

My fear is, that in your rush to "create" the next 3000+ engine, you will end up "borrowing" a lot of code without gaining any real understanding of what it means to write a chess program.

So save bitboards for version 2. Just my 2¢, but I'm not even a programmer.
+1

With Andscacs I started doing a complete working engine with nothing that I did not understand or I was not used to.
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 »

That's what I was upto; to implement bitboards in my next version or after move generator. But I thought I'd have to work a lot if I implement it later. I've written board generator for Knight moves (that's pretty easy) and I am writing code to do/undo a move (to do is easy but to ujdo is ...). As advised by you guyz, I'm doing it completely on my own.