Already forgotten how magic bitboards work.
Maybe better not have used it. I don't know.
Code: Select all
public enum coord
{
a1, b1, c1, d1, e1, f1, g1, h1,
a2, b2, c2, d2, e2, f2, g2, h2,
a3, b3, c3, d3, e3, f3, g3, h3,
a4, b4, c4, d4, e4, f4, g4, h4,
a5, b5, c5, d5, e5, f5, g5, h5,
a6, b6, c6, d6, e6, f6, g6, h6,
a7, b7, c7, d7, e7, f7, g7, h7,
a8, b8, c8, d8, e8, f8, g8, h8
};
Per Square:
coord coord;
Index = (int)coord;
int StraightNShift = 64 - MagicKeyLenStraight[Index];
public Dictionary<ulong, ulong> StraightMovesDict = new Dictionary<ulong, ulong>();
ulong straightMoves =
MoveGenerationHelper.Moves(u & RightMoves, leftShift, 1, RightMoves) |
MoveGenerationHelper.Moves(u & LeftMoves, rightShift, 1, LeftMoves) |
MoveGenerationHelper.Moves(u & UpMoves, leftShift, 8, UpMoves) |
MoveGenerationHelper.Moves(u & DownMoves, rightShift, 8, DownMoves);
StraightMovesDict[u] = straightMoves;
foreach (var pair in StraightMovesDict)
{
int index = MagicKey(pair.Key, StraightMagic, StraightNBits);
StraightMovesArr[index] = pair.Value;
}
public int MagicKey(ulong occupancy, ulong magic, int nBits)
{
var ind = occupancy * magic;
var index = (int)(ind >> (64 - nBits));
return index;
}
public ulong StraightMoves(ulong occupiers) =>
StraightMovesArr[*(StraightOcc & occupiers) * StraightMagic) >> StraightNShift];
public bool SelfTest()
{
foreach (var pair in StraightMovesDict)
{
int index = MagicKey(pair.Key, StraightMagic, StraightNBits);
if (StraightMovesArr[index] != pair.Value) return false;
}
return true;
}