Ejemplo n.º 1
0
 public static void AddDiagonalMaps(this byte[] board, bool white, int i, ref BoardBuffer 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);
             bool cap = board.TakesOpponentPiece(white, idx);
             if (allowCheck || !InCheck(temp, white))
             {
                 if (cap)
                     moves.AddCapture(temp);
                 else if (PieceNotSafe(temp, idx, white))
                     moves.AddUnSafe(temp);
                 else if (DiagThreat(temp, idx))
                     moves.AddThreat(temp);
                 else if (!white)
                     moves.AddForward(temp);
                 else
                     moves.Add(temp);
             }
             if (cap)
                 break;
         }
         else break;
         idx += UPLEFT;
     }
     idx = i + UPRIGHT;
     while (idx < OUTOFBOUNDSHIGH && idx % COLUMN != COL1)
     {
         if (IsValidMove(board, white, idx))
         {
             temp = board.Move(i, idx);
             bool cap = board.TakesOpponentPiece(white, idx);
             if (allowCheck || !InCheck(temp, white))
             {
                 if (cap)
                     moves.AddCapture(temp);
                 else if (PieceNotSafe(temp, idx, white))
                     moves.AddUnSafe(temp);
                 else if (DiagThreat(temp, idx))
                     moves.AddThreat(temp);
                 else if (!white)
                     moves.AddForward(temp);
                 else
                     moves.Add(temp);
             }
             if (cap)
                 break;
         }
         else break;
         idx += UPRIGHT;
     }
     idx = i + DOWNLEFT;
     while (idx > OUTOFBOUNDSLOW && idx % COLUMN != COL8)
     {
         if (board.IsValidMove(white, idx))
         {
             temp = board.Move(i, idx);
             bool cap = board.TakesOpponentPiece(white, idx);
             if (allowCheck || !InCheck(temp, white))
             {
                 if (cap)
                     moves.AddCapture(temp);
                 else if (PieceNotSafe(temp, idx, white))
                     moves.AddUnSafe(temp);
                 else if (DiagThreat(temp, idx))
                     moves.AddThreat(temp);
                 else if (white)
                     moves.AddForward(temp);
                 else
                     moves.Add(temp);
             }
             if (cap)
                 break;
         }
         else break;
         idx += DOWNLEFT;
     }
     idx = i + DOWNRIGHT;
     while (idx > OUTOFBOUNDSLOW && idx % COLUMN != 0)
     {
         if (board.IsValidMove(white, idx))
         {
             temp = board.Move(i, idx);
             bool cap = board.TakesOpponentPiece(white, idx);
             if (allowCheck || !InCheck(temp, white))
             {
                 if (cap)
                     moves.AddCapture(temp);
                 else if (PieceNotSafe(temp, idx, white))
                     moves.AddUnSafe(temp);
                 else if (DiagThreat(temp, idx))
                     moves.AddThreat(temp);
                 else if (white)
                     moves.AddForward(temp);
                 else
                     moves.Add(temp);
             }
             if (cap)
                 break;
         }
         else break;
         idx += DOWNRIGHT;
     }
 }
Ejemplo n.º 2
0
 public static void AddKnightMoves(this byte[] board, bool white, int i, ref BoardBuffer 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))
         {
             if (white ? board[idx].IsLower() : board[idx].IsUpper())
                 moves.AddCapture(temp);
             else if (PieceNotSafe(temp, idx, white))
                 moves.AddUnSafe(temp);
             else if (KnightThreat(temp, idx))
                 moves.AddThreat(temp);
             else if (!white)
                 moves.AddForward(temp);
             else
                 moves.Add(temp);
         }
     }
     idx = i + UPUPLEFT;
     if (idx < OUTOFBOUNDSHIGH && originRow > COL1 && board.IsValidMove(white, idx))
     {
         temp = board.Move(i, idx);
         if (allowCheck || !InCheck(temp, white))
         {
             if (white ? board[idx].IsLower() : board[idx].IsUpper())
                 moves.AddCapture(temp);
             else if (PieceNotSafe(temp, idx, white))
                 moves.AddUnSafe(temp);
             else if (KnightThreat(temp, idx))
                 moves.AddThreat(temp);
             else if (!white)
                 moves.AddForward(temp);
             else
                 moves.Add(temp);
         }
     }
     idx = i + UPRIGHTRIGHT;
     if (idx < OUTOFBOUNDSHIGH && originRow < COL7 && board.IsValidMove(white, idx))
     {
         temp = board.Move(i, idx);
         if (allowCheck || !InCheck(temp, white))
         {
             if (white ? board[idx].IsLower() : board[idx].IsUpper())
                 moves.AddCapture(temp);
             else if (PieceNotSafe(temp, idx, white))
                 moves.AddUnSafe(temp);
             else if (KnightThreat(temp, idx))
                 moves.AddThreat(temp);
             else if (!white)
                 moves.AddForward(temp);
             else
                 moves.Add(temp);
         }
     }
     idx = i + UPLEFTLEFT;
     if (idx < OUTOFBOUNDSHIGH && originRow > COL2 && board.IsValidMove(white, idx))
     {
         temp = board.Move(i, idx);
         if (allowCheck || !InCheck(temp, white))
         {
             if (white ? board[idx].IsLower() : board[idx].IsUpper())
                 moves.AddCapture(temp);
             else if (PieceNotSafe(temp, idx, white))
                 moves.AddUnSafe(temp);
             else if (KnightThreat(temp, idx))
                 moves.AddThreat(temp);
             else if (!white)
                 moves.AddForward(temp);
             else
                 moves.Add(temp);
         }
     }
     idx = i + DOWNDOWNLEFT;
     if (idx > OUTOFBOUNDSLOW && originRow > COL1 && board.IsValidMove(white, idx))
     {
         temp = board.Move(i, idx);
         if (allowCheck || !InCheck(temp, white))
         {
             if (white ? board[idx].IsLower() : board[idx].IsUpper())
                 moves.AddCapture(temp);
             else if (PieceNotSafe(temp, idx, white))
                 moves.AddUnSafe(temp);
             else if (KnightThreat(temp, idx))
                 moves.AddThreat(temp);
             else if (white)
                 moves.AddForward(temp);
             else
                 moves.Add(temp);
         }
     }
     idx = i + DOWNDOWNRIGHT;
     if (idx > OUTOFBOUNDSLOW && originRow < COL8 && board.IsValidMove(white, idx))
     {
         temp = board.Move(i, idx);
         if (allowCheck || !InCheck(temp, white))
         {
             if (white ? board[idx].IsLower() : board[idx].IsUpper())
                 moves.AddCapture(temp);
             else if (PieceNotSafe(temp, idx, white))
                 moves.AddUnSafe(temp);
             else if (KnightThreat(temp, idx))
                 moves.AddThreat(temp);
             else if (white)
                 moves.AddForward(temp);
             else
                 moves.Add(temp);
         }
     }
     idx = i + DOWNLEFTLEFT;
     if (idx > OUTOFBOUNDSLOW && originRow > COL2 && board.IsValidMove(white, idx))
     {
         temp = board.Move(i, idx);
         if (allowCheck || !InCheck(temp, white))
         {
             if (white ? board[idx].IsLower() : board[idx].IsUpper())
                 moves.AddCapture(temp);
             else if (PieceNotSafe(temp, idx, white))
                 moves.AddUnSafe(temp);
             else if (KnightThreat(temp, idx))
                 moves.AddThreat(temp);
             else if (white)
                 moves.AddForward(temp);
             else
                 moves.Add(temp);
         }
     }
     idx = i + DOWNRIGHTRIGHT;
     if (idx > OUTOFBOUNDSLOW && originRow < COL7 && board.IsValidMove(white, idx))
     {
         temp = board.Move(i, idx);
         if (allowCheck || !InCheck(temp, white))
         {
             if (white ? board[idx].IsLower() : board[idx].IsUpper())
                 moves.AddCapture(temp);
             else if (PieceNotSafe(temp, idx, white))
                 moves.AddUnSafe(temp);
             else if (KnightThreat(temp, idx))
                 moves.AddThreat(temp);
             else if (white)
                 moves.AddForward(temp);
             else
                 moves.Add(temp);
         }
     }
 }
Ejemplo n.º 3
0
 public static void AddAdjacentMaps(this byte[] board, bool white, int i, ref BoardBuffer moves, bool allowCheck)
 {
     int idx = i + UP;
     byte[] temp;
     while (idx < OUTOFBOUNDSHIGH)
     {
         if (board.IsValidMove(white, idx))
         {
             temp = board.Move(i, idx);
             bool cap = board.TakesOpponentPiece(white, idx);
             if (!InCheck(temp, white))
             {
                 if (cap)
                     moves.AddCapture(temp);
                 else if (PieceNotSafe(temp, idx, white))
                     moves.AddUnSafe(temp);
                 else if (AdjacentThreat(temp, idx))
                     moves.AddThreat(temp);
                 else if (!white)
                     moves.AddForward(temp);
                 else
                     moves.Add(temp);
             }
             if (cap)
                 break;
         }
         else break;
         idx += UP;
     }
     idx = i + DOWN;
     while (idx > OUTOFBOUNDSLOW)
     {
         if (IsValidMove(board, white, idx))
         {
             temp = board.Move(i, idx);
             bool cap = board.TakesOpponentPiece(white, idx);
             if (!InCheck(temp, white))
             {
                 if (cap)
                     moves.AddCapture(temp);
                 else if (PieceNotSafe(temp, idx, white))
                     moves.AddUnSafe(temp);
                 else if (AdjacentThreat(temp, idx))
                     moves.AddThreat(temp);
                 else if (white)
                     moves.AddForward(temp);
                 else
                     moves.Add(temp);
             }
             if (cap)
                 break;
         }
         else break;
         idx += DOWN;
     }
     idx = i % COLUMN;
     int bse = i - idx;
     while (--idx > -1)
     {
         int ix = bse + idx;
         if (IsValidMove(board, white, ix))
         {
             temp = board.Move(i, ix);
             bool cap = board.TakesOpponentPiece(white, ix);
             if (!InCheck(temp, white))
             {
                 if (cap)
                     moves.AddCapture(temp);
                 else if (PieceNotSafe(temp, ix, white))
                     moves.AddUnSafe(temp);
                 else if (AdjacentThreat(temp, ix))
                     moves.AddThreat(temp);
                 else
                     moves.Add(temp);
             }
             if (cap)
                 break;
         }
         else break;
     }
     idx = i % COLUMN;
     bse = i - idx;
     while (++idx < 8)
     {
         int ix = bse + idx;
         if (IsValidMove(board, white, ix))
         {
             temp = board.Move(i, ix);
             bool cap = board.TakesOpponentPiece(white, ix);
             if (!InCheck(temp, white))
             {
                 if (cap)
                     moves.AddCapture(temp);
                 else if (PieceNotSafe(temp, ix, white))
                     moves.AddUnSafe(temp);
                 else if (AdjacentThreat(temp, ix))
                     moves.AddThreat(temp);
                 else
                     moves.Add(temp);
             }
             if (cap)
                 break;
         }
         else break;
     }
 }