Hacker News new | ask | show | jobs
by moomin 3095 days ago
I’m a bit concerned with the bitboard representation. What happens when a pawn takes another piece?

Edit: The above is what I would say if someone presented this approach in an interview.

2 comments

Let's say black pawn takes the white queen: Unset the bit representing this black pawn, set the bit where the black pawn is now, set the white queen long to zero. One load and two write operations to memory. The bit fiddling is probably neglible in terms of time on a modern CPU.
So here's the second question I'd ask: what happens if there was already a black pawn on the white queen's column?
A 64bit data type means one bit per field. It is not 8bit per pawn. It does not distinguish between pawns.
Why would that matter? The bitboard representation allows for multiple pawns per column.
I'd like to see the rest of this implemented. What does this global functions look like? Are they swamped with if statements "I hope not" or are you storing some game logic in structs to replace polymorphism. I don't disagree with with the compact pawn struct as a starting point but to further prove your point I would love to see the rest / pseudo code.
stockfish is an open source chess engine that uses BitBoards https://github.com/official-stockfish/Stockfish/