Example #1
0
 public bool checkCheck(ChessSquare[,] b, side s, AttacksTable t)
 {
     for (int i = 2; i < 10; i++)
     {
         for (int j = 2; j < 10; j++)
         {
             if (b[i, j].pieceSquare == piece.King && b[i, j].sideSquare == s && t.isAttacked(i, j))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Example #2
0
    public bool select(int i, int j)
    {
        Deselect();

        if (board[i, j].pieceSquare == piece.None || board[i, j].pieceSquare == piece.OutOfBoard)
        {
            return(false);
        }
        if (board[i, j].sideSquare == side.Black && white)
        {
            return(false);
        }
        if (board[i, j].sideSquare == side.White && !white)
        {
            return(false);
        }


        selectedJ = j;
        selectedI = i;

        board[i, j].obj.GetComponent <Bouncy>().bounce();

        switch (board[i, j].pieceSquare)
        {
        case piece.Bishop:
            lightBishop(i, j);
            break;

        case piece.King:
            lightKing(i, j);
            break;

        case piece.Rook:
            lightRook(i, j);
            break;

        case piece.Queen:
            lightRook(i, j);
            lightBishop(i, j);
            break;

        case piece.Knight:
            lightKnight(i, j);
            break;

        case piece.Pawn:
            lightPawn(i, j);
            break;

        default:
            break;
        }

        /* Comprobacion Castling */
        AttacksTable t = attacksWhite;

        if (board[i, j].sideSquare == side.White)
        {
            t = attacksBlack;
        }
        if (board[i, j].pieceSquare == piece.King && board[i, j].moved == false && !t.isAttacked(i, j))
        {
            leftCastling = true;
            if (board[i, 2].pieceSquare != piece.Rook || board[i, 2].moved != false)
            {
                leftCastling = false;
            }

            for (int x = 3; x < j; x++)
            {
                if (board[i, x].pieceSquare != piece.None || t.isAttacked(i, x))
                {
                    leftCastling = false;
                }
            }

            rightCastling = true;
            if (board[i, 9].pieceSquare != piece.Rook || board[i, 9].moved != false)
            {
                rightCastling = false;
            }

            for (int x = 8; x > j; x--)
            {
                if (board[i, x].pieceSquare != piece.None || t.isAttacked(i, x))
                {
                    rightCastling = false;
                }
            }
        }

        return(true);
    }