Ejemplo n.º 1
0
 static void Main(string[] args)
 {
     GenerateMagics(
         "rook",
         MagicBitboardFactory.GenerateRookOccupancyBitboards(),
         MagicBitboardFactory.RookOffsets,
         "rook.txt");
 }
Ejemplo n.º 2
0
            public void CalculatesCorrectly()
            {
                var bitboards = MagicBitboardFactory.GenerateRookOccupancyBitboards();

                Assert.AreEqual(0x8080808080807EUL, bitboards[7]);
                Assert.AreEqual(0x404047A040400UL, bitboards[26]);
                Assert.AreEqual(0x17E0101010100UL, bitboards[40]);
                Assert.AreEqual(0x6E10101010101000UL, bitboards[60]);
            }
Ejemplo n.º 3
0
            public void CalculatesCorrectly()
            {
                int[] expected = { 0, 2, 6, 8, 9, 13, 16 };
                int[] actual   = MagicBitboardFactory.GenerateOffsets(0x12345UL);
                TestUtils.TestArrayEquality(expected, actual);

                expected = new int[] { 32, 37, 40, 41, 46 };
                actual   = MagicBitboardFactory.GenerateOffsets(0x432100000000UL);
                TestUtils.TestArrayEquality(expected, actual);
            }
Ejemplo n.º 4
0
            public void CaclulatesCorrectly()
            {
                Bitboard[] bitboards = MagicBitboardFactory.GenerateBishopOccupancyBitboards();

                Assert.AreEqual(0x40201008040200UL, bitboards[0]);
                Assert.AreEqual(0x40201008040200UL, bitboards[63]);
                Assert.AreEqual(0x28440200000000UL, bitboards[60]);
                Assert.AreEqual(0x40221400142200UL, bitboards[27]);
                Assert.AreEqual(0x4020100A0000UL, bitboards[10]);
            }
Ejemplo n.º 5
0
        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));
        }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
0
 public void CalculatesCorrectly()
 {
     Bitboard[] expected = { 0, 1, 2, 3, 0x0000008000000000UL, 0x0000008000000001UL, 0x0000008000000002UL, 0x0000008000000003UL };
     Bitboard[] actual   = MagicBitboardFactory.GeneratePermutations(0x8000000003UL);
     TestUtils.TestArrayEquality(expected, actual);
 }