Page 1 of 1

How do i know which bitboard to update after a move ?

Posted: Sat Aug 01, 2015 9:07 am
by daniel_bog
Hello :)
This is my first attempt on creating a chess engine.
As a first goal I'd like it to be able to reliably beat me in chess ... :lol:

I jumped into C and after some research I chose to represent my board with bitboards. I have bitboards for all the pieces and colors (i.e pawns[WHITE, BLACK, BOTH]).
Now let's say I, the player, move a certain piece (i.e d2d4 at the beginning of the game), and I update the bitboard that represents all of the pieces, and my question is,
how do I know to update the bitboard of the pawns and the white pawns, whithout doing a lot of tedius checks ?

An advice or suggestions will be greatly appreciated :D

Re: How do i know which bitboard to update after a move ?

Posted: Mon Aug 03, 2015 5:19 pm
by Gronk
If you are using Bitboards then there are only 1 and 0 ... so a compare and or an ADD, XOR operation (if you have an inline assembler e.g.) and maybe a checksum for every bitboard will do the trick to simplify the tedious checks, so that you can check which field of the bitboards has been changed. If you know which field of the board has been changed then you can skip other Bitboards, but if it's a piece capture e.g., then you have to process more bitboard operations ... Write your routines as long as possible, check'em well that they are correct and nothing is missing, and then make them smaller and faster step by step until you've reached a very fast and safe bitboard routine.

Here are some resources:

http://chessprogramming.wikispaces.com/

Especially this one...

http://chessprogramming.wikispaces.com/BitScan

Re: How do i know which bitboard to update after a move ?

Posted: Tue Aug 04, 2015 5:42 am
by User923005
There is more than one way to do it.
You can keep a piece list for the board {usually a 2-D array} (so that you know what chessman is sitting on d2 and also that d4 is empty).

Since you keep separate bitmaps of each piece and color, when you are doing makemove() you will probably be processing by the input bitboard of chessmen of a given type.
That will also tell you what has moved.

Look at some implementations to see how it is done.

Because it is faster than other methods, most people writing new engines are using magic bitboards. You might take a look at this:
https://chessprogramming.wikispaces.com/Magic+Bitboards
Those bitboards work off of the idea of a perfect hash.