public static void AddAdjacentMaps(this byte[] board, bool white, int i, ref LeafList moves, bool allowCheck)
 {
     int idx = i + UP;
     byte[] temp;
     while (idx < OUTOFBOUNDSHIGH)
     {
         if (IsValidMove(board, white, idx))
         {
             temp = board.Move(i, idx);
             if (!InCheck(temp, white))
                 moves.Add(temp,idx);
             if (TakesOpponentPiece(board, white, idx))
                 break;
         }
         else break;
         idx += UP;
     }
     idx = i + DOWN;
     while (idx > OUTOFBOUNDSLOW)
     {
         if (IsValidMove(board, white, idx))
         {
             temp = board.Move(i, idx);
             if (allowCheck || !InCheck(temp, white))
                 moves.Add(temp,idx);
             if (TakesOpponentPiece(board, white, idx))
                 break;
         }
         else break;
         idx += DOWN;
     }
     idx = i % COLUMN;
     int bse = i - idx;
     while (--idx > -1)
     {
         if (IsValidMove(board, white, bse + idx))
         {
             temp = board.Move(i, bse + idx);
             if (allowCheck || !InCheck(temp, white))
                 moves.Add(temp, idx);
             if (TakesOpponentPiece(board, white, bse + idx))
                 break;
         }
         else break;
     }
     idx = i % COLUMN;
     bse = i - idx;
     while (++idx < 8)
     {
         if (IsValidMove(board, white, bse + idx))
         {
             temp = board.Move(i, bse + idx);
             if (allowCheck || !InCheck(temp, white))
                 moves.Add(temp, idx);
             if (TakesOpponentPiece(board, white, bse + idx))
                 break;
         }
         else break;
     }
 }
示例#2
0
        public static void AddAdjacentMaps(this byte[] board, bool white, int i, ref LeafList moves, bool allowCheck)
        {
            int idx = i + UP;

            byte[] temp;
            while (idx < OUTOFBOUNDSHIGH)
            {
                if (IsValidMove(board, white, idx))
                {
                    temp = board.Move(i, idx);
                    if (!InCheck(temp, white))
                    {
                        moves.Add(temp, idx);
                    }
                    if (TakesOpponentPiece(board, white, idx))
                    {
                        break;
                    }
                }
                else
                {
                    break;
                }
                idx += UP;
            }
            idx = i + DOWN;
            while (idx > OUTOFBOUNDSLOW)
            {
                if (IsValidMove(board, white, idx))
                {
                    temp = board.Move(i, idx);
                    if (allowCheck || !InCheck(temp, white))
                    {
                        moves.Add(temp, idx);
                    }
                    if (TakesOpponentPiece(board, white, idx))
                    {
                        break;
                    }
                }
                else
                {
                    break;
                }
                idx += DOWN;
            }
            idx = i % COLUMN;
            int bse = i - idx;

            while (--idx > -1)
            {
                if (IsValidMove(board, white, bse + idx))
                {
                    temp = board.Move(i, bse + idx);
                    if (allowCheck || !InCheck(temp, white))
                    {
                        moves.Add(temp, idx);
                    }
                    if (TakesOpponentPiece(board, white, bse + idx))
                    {
                        break;
                    }
                }
                else
                {
                    break;
                }
            }
            idx = i % COLUMN;
            bse = i - idx;
            while (++idx < 8)
            {
                if (IsValidMove(board, white, bse + idx))
                {
                    temp = board.Move(i, bse + idx);
                    if (allowCheck || !InCheck(temp, white))
                    {
                        moves.Add(temp, idx);
                    }
                    if (TakesOpponentPiece(board, white, bse + idx))
                    {
                        break;
                    }
                }
                else
                {
                    break;
                }
            }
        }
示例#3
0
 public static void AddPawnMoves(this byte[] board, bool white, int i, ref LeafList moves, bool allowCheck)
 {
     byte[] temp;
     if (!white)
     {
         if (i / COLUMN == 1)
         {
             if (board[i + UPUP] == _ && board[i + UP] == _)
             {
                 temp = board.MovePawn(i, i + UPUP, white);
                 if (allowCheck || allowCheck || !InCheck(temp, white))
                 {
                     moves.Add(temp, i + UPUP);
                 }
             }
         }
         if (board[i + UP] == _)
         {
             temp = board.MovePawn(i, i + UP, white);
             if (allowCheck || !InCheck(temp, white))
             {
                 moves.Add(temp, i + UP);
             }
         }
         if (board[i + UPLEFT].IsUpper() && (i + UPLEFT) % COLUMN != COL8)
         {
             temp = board.MovePawn(i, i + UPLEFT, white);
             if (allowCheck || !InCheck(temp, white))
             {
                 moves.Add(temp, i + UPLEFT);
             }
         }
         if (i < 54 && board[i + UPRIGHT].IsUpper() && (i + UPRIGHT) % COLUMN != COL1)
         {
             temp = board.MovePawn(i, i + UPRIGHT, white);
             if (allowCheck || !InCheck(temp, white))
             {
                 moves.Add(temp, i + UPRIGHT);
             }
         }
     }
     else
     {
         if (i / COLUMN == COL7)
         {
             if (board[i + DOWNDOWN] == _ && board[i + DOWN] == _)
             {
                 temp = board.MovePawn(i, i + DOWNDOWN, white);
                 if (allowCheck || !InCheck(temp, white))
                 {
                     moves.Add(temp, i + DOWNDOWN);
                 }
             }
         }
         if (board[i + DOWN] == _)
         {
             temp = board.MovePawn(i, i + DOWN, white);
             if (allowCheck || !InCheck(temp, white))
             {
                 moves.Add(temp, i + DOWN);
             }
         }
         if (board[i + DOWNRIGHT].IsLower() && (i + DOWNRIGHT) % COLUMN != COL1)
         {
             temp = board.MovePawn(i, i + DOWNRIGHT, white);
             if (allowCheck || !InCheck(temp, white))
             {
                 moves.Add(temp, i + DOWNRIGHT);
             }
         }
         if (i > 8 && board[i + DOWNLEFT].IsLower() && (i + DOWNLEFT) % COLUMN != COL8)
         {
             temp = board.MovePawn(i, i + DOWNLEFT, white);
             if (!InCheck(temp, white))
             {
                 moves.Add(temp, i + DOWNLEFT);
             }
         }
     }
 }
示例#4
0
        public static void AddKingMoves(this byte[] board, bool white, int i, ref LeafList moves, bool allowCheck)
        {
            byte[] temp;
            int    idx = i + UPLEFT;

            if (idx < OUTOFBOUNDSHIGH)
            {
                if (idx % COLUMN != COL8 && board.IsValidMove(white, idx))
                {
                    temp = board.Move(i, idx);
                    if (allowCheck || !InCheck(temp, white))
                    {
                        moves.Add(temp, idx);
                    }
                }
                if (board.IsValidMove(white, ++idx))
                {
                    temp = board.Move(i, idx);
                    if (allowCheck || !InCheck(temp, white))
                    {
                        moves.Add(temp, idx);
                    }
                }
                if (++idx % COLUMN != COL1 && board.IsValidMove(white, idx))
                {
                    temp = board.Move(i, idx);
                    if (allowCheck || !InCheck(temp, white))
                    {
                        moves.Add(temp, idx);
                    }
                }
            }
            idx = i + RIGHT;
            if (idx % COLUMN != COL1 && board.IsValidMove(white, idx))
            {
                temp = board.Move(i, idx);
                if (allowCheck || !InCheck(temp, white))
                {
                    moves.Add(temp, idx);
                }
            }
            idx = i + LEFT;
            if (idx % COLUMN != COL8 && board.IsValidMove(white, idx))
            {
                temp = board.Move(i, idx);
                if (allowCheck || !InCheck(temp, white))
                {
                    moves.Add(temp, idx);
                }
            }
            idx = i + DOWNRIGHT;
            if (idx > -1)
            {
                if (i % COLUMN != COL8 && board.IsValidMove(white, idx))
                {
                    temp = board.Move(i, idx);
                    if (allowCheck || !InCheck(temp, white))
                    {
                        moves.Add(temp, idx);
                    }
                }
                if (board.IsValidMove(white, --idx))
                {
                    temp = board.Move(i, idx);
                    if (allowCheck || !InCheck(temp, white))
                    {
                        moves.Add(temp, idx);
                    }
                }
                if (i % COLUMN != COL1 && board.IsValidMove(white, --idx))
                {
                    temp = board.Move(i, idx);
                    if (allowCheck || !InCheck(temp, white))
                    {
                        moves.Add(temp, idx);
                    }
                }
            }
        }
示例#5
0
        public static void AddKnightMoves(this byte[] board, bool white, int i, ref LeafList moves, bool allowCheck)
        {
            int originRow = i % COLUMN;
            int idx       = i + UPUPRIGHT;

            byte[] temp;
            if (idx < OUTOFBOUNDSHIGH && originRow < COL8 && board.IsValidMove(white, idx))
            {
                temp = board.Move(i, idx);
                if (allowCheck || !InCheck(temp, white))
                {
                    moves.Add(temp, idx);
                }
            }
            idx = i + UPUPLEFT;
            if (idx < OUTOFBOUNDSHIGH && originRow > COL1 && board.IsValidMove(white, idx))
            {
                temp = board.Move(i, idx);
                if (allowCheck || !InCheck(temp, white))
                {
                    moves.Add(temp, idx);
                }
            }
            idx = i + UPRIGHTRIGHT;
            if (idx < OUTOFBOUNDSHIGH && originRow < COL7 && board.IsValidMove(white, idx))
            {
                temp = board.Move(i, idx);
                if (allowCheck || !InCheck(temp, white))
                {
                    moves.Add(temp, idx);
                }
            }
            idx = i + UPLEFTLEFT;
            if (idx < OUTOFBOUNDSHIGH && originRow > COL2 && board.IsValidMove(white, idx))
            {
                temp = board.Move(i, idx);
                if (allowCheck || !InCheck(temp, white))
                {
                    moves.Add(temp, idx);
                }
            }
            idx = i + DOWNDOWNLEFT;
            if (idx > OUTOFBOUNDSLOW && originRow > COL1 && board.IsValidMove(white, idx))
            {
                temp = board.Move(i, idx);
                if (allowCheck || !InCheck(temp, white))
                {
                    moves.Add(temp, idx);
                }
            }
            idx = i + DOWNDOWNRIGHT;
            if (idx > OUTOFBOUNDSLOW && originRow < COL8 && board.IsValidMove(white, idx))
            {
                temp = board.Move(i, idx);
                if (allowCheck || !InCheck(temp, white))
                {
                    moves.Add(temp, idx);
                }
            }
            idx = i + DOWNLEFTLEFT;
            if (idx > OUTOFBOUNDSLOW && originRow > COL2 && board.IsValidMove(white, idx))
            {
                temp = board.Move(i, idx);
                if (allowCheck || !InCheck(temp, white))
                {
                    moves.Add(temp, idx);
                }
            }
            idx = i + DOWNRIGHTRIGHT;
            if (idx > OUTOFBOUNDSLOW && originRow < COL7 && board.IsValidMove(white, idx))
            {
                temp = board.Move(i, idx);
                if (allowCheck || !InCheck(temp, white))
                {
                    moves.Add(temp, idx);
                }
            }
        }
示例#6
0
        public static void AddDiagonalMaps(this byte[] board, bool white, int i, ref LeafList moves, bool allowCheck)
        {
            byte[] temp;
            int    idx = i + UPLEFT;

            while (idx < OUTOFBOUNDSHIGH && idx % COLUMN != COL8)
            {
                if (IsValidMove(board, white, idx))
                {
                    temp = board.Move(i, idx);
                    if (allowCheck || !InCheck(temp, white))
                    {
                        moves.Add(temp, idx);
                    }
                    if (board.TakesOpponentPiece(white, idx))
                    {
                        break;
                    }
                }
                else
                {
                    break;
                }
                idx += UPLEFT;
            }
            idx = i + UPRIGHT;
            while (idx < OUTOFBOUNDSHIGH && idx % COLUMN != COL1)
            {
                if (IsValidMove(board, white, idx))
                {
                    temp = board.Move(i, idx);
                    if (allowCheck || !InCheck(temp, white))
                    {
                        moves.Add(temp, idx);
                    }
                    if (board.TakesOpponentPiece(white, idx))
                    {
                        break;
                    }
                }
                else
                {
                    break;
                }
                idx += UPRIGHT;
            }
            idx = i + DOWNLEFT;
            while (idx > OUTOFBOUNDSLOW && idx % COLUMN != COL8)
            {
                if (board.IsValidMove(white, idx))
                {
                    temp = board.Move(i, idx);
                    if (allowCheck || !InCheck(temp, white))
                    {
                        moves.Add(temp, idx);
                    }
                    if (board.TakesOpponentPiece(white, idx))
                    {
                        break;
                    }
                }
                else
                {
                    break;
                }
                idx += DOWNLEFT;
            }
            idx = i + DOWNRIGHT;
            while (idx > OUTOFBOUNDSLOW && idx % COLUMN != 0)
            {
                if (board.IsValidMove(white, idx))
                {
                    temp = board.Move(i, idx);
                    if (allowCheck || !InCheck(temp, white))
                    {
                        moves.Add(temp, idx);
                    }
                    if (board.TakesOpponentPiece(white, idx))
                    {
                        break;
                    }
                }
                else
                {
                    break;
                }
                idx += DOWNRIGHT;
            }
        }
 public static void AddPawnMoves(this byte[] board, bool white, int i, ref LeafList moves, bool allowCheck)
 {
     byte[] temp;
     if (!white)
     {
         if (i / COLUMN == 1)
         {
             if (board[i + UPUP] == _ && board[i + UP] == _)
             {
                 temp = board.MovePawn(i, i + UPUP, white);
                 if (allowCheck || allowCheck || !InCheck(temp, white))
                     moves.Add(temp, i + UPUP);
             }
         }
         if (board[i + UP] == _)
         {
             temp = board.MovePawn(i, i + UP, white);
             if (allowCheck || !InCheck(temp, white))
                 moves.Add(temp, i + UP);
         }
         if (board[i + UPLEFT].IsUpper() && (i + UPLEFT) % COLUMN != COL8)
         {
             temp = board.MovePawn(i, i + UPLEFT, white);
             if (allowCheck || !InCheck(temp, white))
                 moves.Add(temp, i + UPLEFT);
         }
         if (i < 54 && board[i + UPRIGHT].IsUpper() && (i + UPRIGHT) % COLUMN != COL1)
         {
             temp = board.MovePawn(i, i + UPRIGHT, white);
             if (allowCheck || !InCheck(temp, white))
                 moves.Add(temp, i + UPRIGHT);
         }
     }
     else
     {
         if (i / COLUMN == COL7)
         {
             if (board[i + DOWNDOWN] == _ && board[i + DOWN] == _)
             {
                 temp = board.MovePawn(i, i + DOWNDOWN, white);
                 if (allowCheck || !InCheck(temp, white))
                     moves.Add(temp, i + DOWNDOWN);
             }
         }
         if (board[i + DOWN] == _)
         {
             temp = board.MovePawn(i, i + DOWN, white);
             if (allowCheck || !InCheck(temp, white))
                 moves.Add(temp, i + DOWN);
         }
         if (board[i + DOWNRIGHT].IsLower() && (i + DOWNRIGHT) % COLUMN != COL1)
         {
             temp = board.MovePawn(i, i + DOWNRIGHT, white);
             if (allowCheck || !InCheck(temp, white))
                 moves.Add(temp, i + DOWNRIGHT);
         }
         if (i > 8 && board[i + DOWNLEFT].IsLower() && (i + DOWNLEFT) % COLUMN != COL8)
         {
             temp = board.MovePawn(i, i + DOWNLEFT, white);
             if (!InCheck(temp, white))
                 moves.Add(temp, i + DOWNLEFT);
         }
     }
 }
 public static void AddKingMoves(this byte[] board, bool white, int i, ref LeafList moves, bool allowCheck)
 {
     byte[] temp;
     int idx = i + UPLEFT;
     if (idx < OUTOFBOUNDSHIGH)
     {
         if (idx % COLUMN != COL8 && board.IsValidMove(white, idx))
         {
             temp = board.Move(i, idx);
             if (allowCheck || !InCheck(temp, white))
                 moves.Add(temp, idx);
         }
         if (board.IsValidMove(white, ++idx))
         {
             temp = board.Move(i, idx);
             if (allowCheck || !InCheck(temp, white))
                 moves.Add(temp, idx);
         }
         if (++idx % COLUMN != COL1 && board.IsValidMove(white, idx))
         {
             temp = board.Move(i, idx);
             if (allowCheck || !InCheck(temp, white))
                 moves.Add(temp, idx);
         }
     }
     idx = i + RIGHT;
     if (idx % COLUMN != COL1 && board.IsValidMove(white, idx))
     {
         temp = board.Move(i, idx);
         if (allowCheck || !InCheck(temp, white))
             moves.Add(temp, idx);
     }
     idx = i + LEFT;
     if (idx % COLUMN != COL8 && board.IsValidMove(white, idx))
     {
         temp = board.Move(i, idx);
         if (allowCheck || !InCheck(temp, white))
             moves.Add(temp, idx);
     }
     idx = i + DOWNRIGHT;
     if (idx > -1)
     {
         if (i % COLUMN != COL8 && board.IsValidMove(white, idx))
         {
             temp = board.Move(i, idx);
             if (allowCheck || !InCheck(temp, white))
                 moves.Add(temp, idx);
         }
         if (board.IsValidMove(white, --idx))
         {
             temp = board.Move(i, idx);
             if (allowCheck || !InCheck(temp, white))
                 moves.Add(temp, idx);
         }
         if (i % COLUMN != COL1 && board.IsValidMove(white, --idx))
         {
             temp = board.Move(i, idx);
             if (allowCheck || !InCheck(temp, white))
                 moves.Add(temp, idx);
         }
     }
 }
 public static void AddKnightMoves(this byte[] board, bool white, int i, ref LeafList moves, bool allowCheck)
 {
     int originRow = i % COLUMN;
     int idx = i + UPUPRIGHT;
     byte[] temp;
     if (idx < OUTOFBOUNDSHIGH && originRow < COL8 && board.IsValidMove(white, idx))
     {
         temp = board.Move(i, idx);
         if (allowCheck || !InCheck(temp, white))
             moves.Add(temp, idx);
     }
     idx = i + UPUPLEFT;
     if (idx < OUTOFBOUNDSHIGH && originRow > COL1 && board.IsValidMove(white, idx))
     {
         temp = board.Move(i, idx);
         if (allowCheck || !InCheck(temp, white))
             moves.Add(temp, idx);
     }
     idx = i + UPRIGHTRIGHT;
     if (idx < OUTOFBOUNDSHIGH && originRow < COL7 && board.IsValidMove(white, idx))
     {
         temp = board.Move(i, idx);
         if (allowCheck || !InCheck(temp, white))
             moves.Add(temp, idx);
     }
     idx = i + UPLEFTLEFT;
     if (idx < OUTOFBOUNDSHIGH && originRow > COL2 && board.IsValidMove(white, idx))
     {
         temp = board.Move(i, idx);
         if (allowCheck || !InCheck(temp, white))
             moves.Add(temp, idx);
     }
     idx = i + DOWNDOWNLEFT;
     if (idx > OUTOFBOUNDSLOW && originRow > COL1 && board.IsValidMove(white, idx))
     {
         temp = board.Move(i, idx);
         if (allowCheck || !InCheck(temp, white))
             moves.Add(temp, idx);
     }
     idx = i + DOWNDOWNRIGHT;
     if (idx > OUTOFBOUNDSLOW && originRow < COL8 && board.IsValidMove(white, idx))
     {
         temp = board.Move(i, idx);
         if (allowCheck || !InCheck(temp, white))
             moves.Add(temp, idx);
     }
     idx = i + DOWNLEFTLEFT;
     if (idx > OUTOFBOUNDSLOW && originRow > COL2 && board.IsValidMove(white, idx))
     {
         temp = board.Move(i, idx);
         if (allowCheck || !InCheck(temp, white))
             moves.Add(temp, idx);
     }
     idx = i + DOWNRIGHTRIGHT;
     if (idx > OUTOFBOUNDSLOW && originRow < COL7 && board.IsValidMove(white, idx))
     {
         temp = board.Move(i, idx);
         if (allowCheck || !InCheck(temp, white))
             moves.Add(temp, idx);
     }
 }
 public static void AddDiagonalMaps(this byte[] board, bool white, int i, ref LeafList moves, bool allowCheck)
 {
     byte[] temp;
     int idx = i + UPLEFT;
     while (idx < OUTOFBOUNDSHIGH && idx % COLUMN != COL8)
     {
         if (IsValidMove(board, white, idx))
         {
             temp = board.Move(i, idx);
             if (allowCheck || !InCheck(temp, white))
                 moves.Add(temp, idx);
             if (board.TakesOpponentPiece(white, idx))
                 break;
         }
         else break;
         idx += UPLEFT;
     }
     idx = i + UPRIGHT;
     while (idx < OUTOFBOUNDSHIGH && idx % COLUMN != COL1)
     {
         if (IsValidMove(board, white, idx))
         {
             temp = board.Move(i, idx);
             if (allowCheck || !InCheck(temp, white))
                 moves.Add(temp, idx);
             if (board.TakesOpponentPiece(white, idx))
                 break;
         }
         else break;
         idx += UPRIGHT;
     }
     idx = i + DOWNLEFT;
     while (idx > OUTOFBOUNDSLOW && idx % COLUMN != COL8)
     {
         if (board.IsValidMove(white, idx))
         {
             temp = board.Move(i, idx);
             if (allowCheck || !InCheck(temp, white))
                 moves.Add(temp, idx);
             if (board.TakesOpponentPiece(white, idx))
                 break;
         }
         else break;
         idx += DOWNLEFT;
     }
     idx = i + DOWNRIGHT;
     while (idx > OUTOFBOUNDSLOW && idx % COLUMN != 0)
     {
         if (board.IsValidMove(white, idx))
         {
             temp = board.Move(i, idx);
             if (allowCheck || !InCheck(temp, white))
                 moves.Add(temp, idx);
             if (board.TakesOpponentPiece(white, idx))
                 break;
         }
         else break;
         idx += DOWNRIGHT;
     }
 }