0

So I've been having some trouble wrapping my head around an issue. I'm currently writing a bitboard based chess engine in Java (its been a ride figuring everything out). So far all of the pawn/king/knight moves work as expected and without bugs.

What I need help understanding is sliding piece move generation. I have generated the array of empty board moves for each square / piece. From my current understanding I also need to develop an array that contains each possible occupancy on each square as well-- and then somehow look up that array based on a variety of methods.

Is this way of thinking about it correct? Is it a matter of picking every number from 0 to 2^63 and xor'ing it with the move bitboard for that square and then storing that with some method (magic/rotated bitboards) to initialize the array and accessing it the same way at run time?

Pseudocode and explanations are much appreciated. (I'm using the >>> by the way).

Kev
  • 15,899
  • 15
  • 79
  • 112
thePanthurr
  • 104
  • 1
  • 9

2 Answers2

3

There are many ways to generate sliding piece moves for bitboards, with varying performance and complexity. Many of them are listed here.

Probably the fastest and most common one is magic bitboards, which uses multiplication of bitboards with "magic" precalculated values to generate the possible moves in all four directions at once. The drawback is that it uses very large lookup tables. This probably shouldn't be your first implementation as it's more complicated.

Obstruction difference and hyperbola quintessence are not much slower than magic bitboards, while easier to implement.

Even simpler and slower is dumb7fill which is a loop in every possible direction, without requiring any lookup tables.

interjay
  • 107,303
  • 21
  • 270
  • 254
  • Thank you, but even with magic bitboards you are using the magic number to accurately reference a lookup table. My question is more so how to generate that lookup table. Unless I just don't understand. – thePanthurr Apr 11 '17 at 19:27
  • @thePanthurr Your question makes it seem like you think the same lookup table would be used for any sliding piece method. But they all need different lookup tables. Some of them (e.g. magic bitboards) use multiple lookup tables. You should decide which method you want to use, read about it, and then ask specifically about what you don't understand. – interjay Apr 11 '17 at 20:54
  • @thePanthurr You don't need to generate the table yourself. – ABCD Apr 12 '17 at 17:00
  • @interjay https://chessprogramming.wikispaces.com/Magic+Bitboards This page notes in step 4: "Use the index to reference a preinitialized move database." -- I am wondering how to generate that database of occupancy moves, given that I have the empty board moves database done. SmallChess - What is the alternative? – thePanthurr Apr 13 '17 at 06:08
  • @thePanthurr That should contain the valid positions to move to depending on the occupied squares represented by the 1-bits in the index. You can generate each entry using dumb7fill or Kogge-Stone. – interjay Apr 14 '17 at 11:12
  • The page on magic bitboards has moved [here](https://www.chessprogramming.org/Magic_Bitboards) – Anton Thomas Nov 30 '21 at 18:58
0

I'm personally using hyperbola quintessence technique to generate slider piece (Rooks, Bishops & Queen) moves. It's very simple and are memory efficient when compared to magic bitboard technique, but are little bit slower than magic bitboards as there is a bit of computation involved in hyperbola quintessence when compared to lookup in case of magic bitboards. Please refer to this talkchess.com forum for a good understanding of how rank attacks are generated as it's the one I personally felt I didn't understand it very well. The forum discussion gave me the required understanding & it is pretty neat and works very well. Hyperbola Quintessence works well with Java as well, I'm using C++ for my chess engine. Good luck with your chess engine programming.

techcraver
  • 401
  • 3
  • 21