static PawnStructureEvaluator()
        {
            _innerFileMasks = new ulong[8];
            _outerFileMasks = new ulong[8];
            _chainMasks     = new ulong[64];

            for (var i = 0; i < 8; i++)
            {
                _innerFileMasks[i] = BoardConstants.AFile >> i;

                if (i - 1 >= 0)
                {
                    _outerFileMasks[i] |= BoardConstants.AFile >> (i - 1);
                }

                if (i + 1 < 8)
                {
                    _outerFileMasks[i] |= BoardConstants.AFile >> (i + 1);
                }
            }

            for (var i = 0; i < 64; i++)
            {
                _chainMasks[i] = DiagonalPatternGenerator.GetPattern(i) & BoxPatternGenerator.GetPattern(i);
            }
        }
예제 #2
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));
        }