Moderator: Andres Valverde
John Digsby wrote:Hi,
I'm trying something a little new for chess programming in terms of how to make the computer evaluate positions. I previously wrote a move generator based on representing the board as two arrays of squares occupied by black and squares occupied by white, accompanied by a bog-standard 64-length array. I precomputed all valid moves for every piece on every square of an empty board, and loaded them into memeory at initialisation.
All this, just to try to make my code somewhat less verbose and easier for me to maintain!
As I reached the evaluation routines, and wanted to start looking at structures like outposted knights, etc. I found I was writing very complex code, which would produce a bit of a bottleneck during the tree search.
I have since poked around the source of Crafty and the same evaluations that I'm having to write into 30-40 line functions for are represented by simple boolean ifs because of the bitboard representation.
I understand how this works, but didn't implement it because it was so complicated. Since I'm mostly interested in the evaluation end, I wondered if there was some C++ source for a chessboard class (or somesuch) that implemented bitboards. I would convert Crafty happily, except that I don't understand exactly how ordinary C file structures work and can't seem to find the bit I'm after.
If anyone can help either finding an existing C++ solution, or in suggesting how to extract the one in Crafty I would be very appreciative, as I would rather get on with the "interesting" part than be bogged down in generation again!
John Digsby wrote:I understand how this works, but didn't implement it because it was so complicated. Since I'm mostly interested in the evaluation end, I wondered if there was some C++ source for a chessboard class (or somesuch) that implemented bitboards.
Dann Corbit wrote:The author of Elephant has the most interesting C++ bitboard based move generator set I have ever seen. I guess he might let you have a copy if you asked him. He has implemented lots of fundamentally different bitboard techniques in his generators.
Glaurung 1 and Glaurung 2 are both ones of the very best (and my first personal favorites) examples of chess code architecture, chess-domain decisions and naming conventions.Tord Romstad wrote:John Digsby wrote:I understand how this works, but didn't implement it because it was so complicated. Since I'm mostly interested in the evaluation end, I wondered if there was some C++ source for a chessboard class (or somesuch) that implemented bitboards.
Glaurung uses bitboards, is written in C++, and has a chessboard class (called 'Position'). But I should warn you that it is quite a big and messy program (more compact than Crafty, though), and written in quite strange and unidiomatic C++.
But I will not recommend particular Glaurung's bitboard implementation as a start point of a new program. I think classical Crafty old-fashioned C-code can be understood and refactored into simpler C++ with more sucess.
Bitboard temp;
...
Bitboard abit = temp & -temp;
John Digsby wrote:
- Code: Select all
Bitboard temp;
...
Bitboard abit = temp & -temp;
This should always be 1, since the minus sign will do nothing to the unsigned variable. Or have I missed something
-x == ~x + 1
John Digsby wrote:This should always be 1, since the minus sign will do nothing to the unsigned variable. Or have I missed something
John Digsby wrote:What would people recommend, rotated or magic bitboards?
John Digsby wrote:What would people recommend, rotated or magic bitboards?
Return to Programming and Technical Discussions
Users browsing this forum: No registered users and 9 guests