static Bitboard GenerateReducedMagic(int square, bool bishop) { Bitboard occBB = Bitboards.RookPremasks[square]; if (bishop) { occBB = Bitboards.BishopPremasks[square]; } Bitboard[] permutations = MagicBitboardFactory.GeneratePermutations(occBB); Bitboard[] moves = MagicBitboardFactory.GenerateMovesFromPermutations( square, permutations, bishop ? MagicBitboardFactory.BishopOffsets : MagicBitboardFactory.RookOffsets); return(MagicBitboardFactory.GenerateMagicNumber(permutations, moves, 1)); }
static void GenerateMagics(string piece, Bitboard[] occupancyBBs, int[] offsets, string filename) { Bitboard[] result = new Bitboard[64]; DateTime start = DateTime.Now; for (int i = 0; i < 64; i++) { Console.Write($"Generating {piece} magic for square {i}..."); var permutations = MagicBitboardFactory.GeneratePermutations(occupancyBBs[i]); var moves = MagicBitboardFactory.GenerateMovesFromPermutations(i, permutations, offsets); result[i] = MagicBitboardFactory.GenerateMagicNumber(permutations, moves); Console.WriteLine("Done"); } Console.WriteLine($"Total Elapsed Time: {(DateTime.Now - start).ToString()}"); if (File.Exists(filename)) { File.Delete(filename); } MagicBitboardFactory.WriteMagicsToFile(filename, result); }
public void CalculatesCorrectly() { Bitboard[] expected = { 0, 1, 2, 3, 0x0000008000000000UL, 0x0000008000000001UL, 0x0000008000000002UL, 0x0000008000000003UL }; Bitboard[] actual = MagicBitboardFactory.GeneratePermutations(0x8000000003UL); TestUtils.TestArrayEquality(expected, actual); }