예제 #1
0
        public static MagicContainer[] GenerateBishopAttacks(ulong[] keys = null)
        {
            var masks        = new ulong[64];
            var permutations = new ulong[64][];
            var attacks      = new ulong[64][];

            for (var fieldIndex = 0; fieldIndex < 64; fieldIndex++)
            {
                masks[fieldIndex]        = DiagonalPatternGenerator.GetPattern(fieldIndex) & ~BoardConstants.Edges;
                permutations[fieldIndex] = new ulong[1 << MagicShifts.BishopShifts[fieldIndex]];
                attacks[fieldIndex]      = new ulong[1 << MagicShifts.BishopShifts[fieldIndex]];

                for (var permutationIndex = 0; permutationIndex < permutations[fieldIndex].Length; permutationIndex++)
                {
                    permutations[fieldIndex][permutationIndex] = PermutationsGenerator.GetPermutation(masks[fieldIndex], permutationIndex);
                    attacks[fieldIndex][permutationIndex]      = AttacksGenerator.GetDiagonalAttacks(permutations[fieldIndex][permutationIndex], fieldIndex);
                }
            }

            return(_bishopMagicArray = GenerateAttacks(masks, permutations, attacks, MagicShifts.BishopShifts, keys));
        }
예제 #2
0
        public static MagicContainer[] GenerateRookAttacks(ulong[] keys = null)
        {
            var masks        = new ulong[64];
            var permutations = new ulong[64][];
            var attacks      = new ulong[64][];

            for (var fieldIndex = 0; fieldIndex < 64; fieldIndex++)
            {
                masks[fieldIndex] = (FilePatternGenerator.GetPatternForField(fieldIndex) & ~BoardConstants.TopBottomEdge) |
                                    (RankPatternGenerator.GetPatternForField(fieldIndex) & ~BoardConstants.RightLeftEdge);

                permutations[fieldIndex] = new ulong[1 << MagicShifts.RookShifts[fieldIndex]];
                attacks[fieldIndex]      = new ulong[1 << MagicShifts.RookShifts[fieldIndex]];

                for (var permutationIndex = 0; permutationIndex < permutations[fieldIndex].Length; permutationIndex++)
                {
                    permutations[fieldIndex][permutationIndex] = PermutationsGenerator.GetPermutation(masks[fieldIndex], permutationIndex);
                    attacks[fieldIndex][permutationIndex]      = AttacksGenerator.GetFileRankAttacks(permutations[fieldIndex][permutationIndex], fieldIndex);
                }
            }

            return(_rookMagicArray = GenerateAttacks(masks, permutations, attacks, MagicShifts.RookShifts, keys));
        }