Пример #1
0
        // Returns true if a path of set bits in 'path' exists that 8-way connect
        // any set bit in sq1 to any set bit of sq2
        public static bool SquaresAreConnected(ulong sq1, ulong sq2, ulong path)
        {
            // With bitboard sq1, do an 8-way flood fill, masking off bits not in
            // path at every step. Stop when fill reaches any set bit in sq2, or
            // fill cannot progress any further

            if ((~(sq1 &= path) | ~(sq2 &= path)) != 0)
            {
                return(false);
            }

            // Drop bits not in path
            // Early exit if sq1 or sq2 not on any path

            while ((sq1 & sq2) != 0)
            {
                ulong temp = sq1;
                // Set all 8 neighbours
                sq1 |= BitBoardHelper.ShiftEastOne(sq1) | BitBoardHelper.ShiftWestOne(sq1);
                sq1 |= BitBoardHelper.ShiftSouthOne(sq1) | BitBoardHelper.ShiftNorthOne(sq1);
                // Drop bits not in path
                sq1 &= path;
                if (sq1 == temp)
                {
                    // Fill has stopped
                    return(false);
                }
            }
            // Found a good path
            return(true);
        }
Пример #2
0
        public static ulong[] GenerateAntiDiagonals()
        {
            ulong[] arr = new ulong[15];

            for (int i = 0; i < 8; ++i)
            {
                ulong board      = 0;
                ulong minusBoard = 0;

                for (int x = 0; x <= i; ++x)
                {
                    int y = i - x;

                    board      |= BitBoardHelper.GetOneBitNumber(x, y);
                    minusBoard |= BitBoardHelper.GetOneBitNumber(7 - x, 7 - y);
                }

                arr[14 - i] = minusBoard;
                arr[i]      = board;
            }

            return(arr);
        }
Пример #3
0
 public static ulong[] GenerateRotatedRanks()
 {
     return(Enumerable.Range(0, 256)
            .Select(b => BitBoardHelper.FlipDiagonalA1H8((ulong)b))
            .ToArray());
 }