Пример #1
0
    public static void ValidateInitialPiecePositions(Board b)
    {
        Board  board = (Board)b.Clone();
        int    x, y;
        Pawn   pawn        = new Pawn();
        Rook   rook        = new Rook();
        Knight knight      = new Knight();
        Bishop bishop      = new Bishop();
        King   king        = new King();
        Queen  queen       = new Queen();
        var    pawn_type   = pawn.GetType();
        var    rook_type   = rook.GetType();
        var    knight_type = knight.GetType();
        var    bishop_type = bishop.GetType();
        var    king_type   = king.GetType();
        var    queen_type  = queen.GetType();

        //Check white pieces
        for (y = ChessGlobals.BoardConstants.BOARD_MINIMUM; y < ChessGlobals.BoardConstants.TEAM_ROWS; ++y)
        {
            for (x = ChessGlobals.BoardConstants.BOARD_MINIMUM; x <= ChessGlobals.BoardConstants.BOARD_MAXIMUM; ++x)
            {
                if (y == 1)                                                                               //pawns
                {
                    Assert.AreEqual(board.IsOccupied(x, y), ChessGlobals.BoardConstants.OCCUPIED_SQUARE); //a piece should occupy here
                    Assert.AreEqual(board.GetPieceAt(x, y).GetTeam(), ChessGlobals.Teams.WHITE_TEAM);     //correct team
                    Assert.AreEqual(board.GetPieceAt(x, y).GetType(), pawn_type);                         //correct type of piece
                }
                else
                {
                    if (x == 0 || x == 7)
                    {
                        Assert.AreEqual(board.IsOccupied(x, y), ChessGlobals.BoardConstants.OCCUPIED_SQUARE);  //a piece should occupy here
                        Assert.AreEqual(board.GetPieceAt(x, y).GetTeam(), ChessGlobals.Teams.WHITE_TEAM);      //correct team
                        Assert.AreEqual(board.GetPieceAt(x, y).GetType(), rook_type);                          //correct type of piece
                    }
                    else if (x == 1 || x == 6)
                    {
                        Assert.AreEqual(board.IsOccupied(x, y), ChessGlobals.BoardConstants.OCCUPIED_SQUARE);    //a piece should occupy here
                        Assert.AreEqual(board.GetPieceAt(x, y).GetTeam(), ChessGlobals.Teams.WHITE_TEAM);        //correct team
                        Assert.AreEqual(board.GetPieceAt(x, y).GetType(), knight_type);                          //correct type of piece
                    }
                    else if (x == 2 || x == 5)
                    {
                        Assert.AreEqual(board.IsOccupied(x, y), ChessGlobals.BoardConstants.OCCUPIED_SQUARE);    //a piece should occupy here
                        Assert.AreEqual(board.GetPieceAt(x, y).GetTeam(), ChessGlobals.Teams.WHITE_TEAM);        //correct team
                        Assert.AreEqual(board.GetPieceAt(x, y).GetType(), bishop_type);                          //correct type of piece
                    }
                    else if (x == 3)
                    {
                        Assert.AreEqual(board.IsOccupied(x, y), ChessGlobals.BoardConstants.OCCUPIED_SQUARE);  //a piece should occupy here
                        Assert.AreEqual(board.GetPieceAt(x, y).GetTeam(), ChessGlobals.Teams.WHITE_TEAM);      //correct team
                        Assert.AreEqual(board.GetPieceAt(x, y).GetType(), king_type);                          //correct type of piece
                    }
                    else if (x == 4)
                    {
                        MonoBehaviour.print("Here");
                        Assert.AreEqual(board.IsOccupied(x, y), ChessGlobals.BoardConstants.OCCUPIED_SQUARE);   //a piece should occupy here
                        Assert.AreEqual(board.GetPieceAt(x, y).GetTeam(), ChessGlobals.Teams.WHITE_TEAM);       //correct team
                        Assert.AreEqual(board.GetPieceAt(x, y).GetType(), queen_type);                          //correct type of piece only this test fails
                    }
                }
            }
        }


        //Check black pieces
        for (y = ChessGlobals.BoardConstants.BOARD_MAXIMUM; y > ChessGlobals.BoardConstants.BOARD_MAXIMUM - ChessGlobals.BoardConstants.TEAM_ROWS; --y)
        {
            for (x = ChessGlobals.BoardConstants.BOARD_MINIMUM; x <= 7; ++x)
            {
                if (y == 6)
                {
                    Assert.AreEqual(board.IsOccupied(x, y), ChessGlobals.BoardConstants.OCCUPIED_SQUARE); //a piece should occupy here
                    Assert.AreEqual(board.GetPieceAt(x, y).GetTeam(), ChessGlobals.Teams.BLACK_TEAM);     //correct team
                    Assert.AreEqual(board.GetPieceAt(x, y).GetType(), pawn_type);                         //correct type of piece
                }
                else
                {
                    if (x == 0 || x == 7)
                    {
                        Assert.AreEqual(board.IsOccupied(x, y), ChessGlobals.BoardConstants.OCCUPIED_SQUARE);   //a piece should occupy here
                        Assert.AreEqual(board.GetPieceAt(x, y).GetTeam(), ChessGlobals.Teams.BLACK_TEAM);       //correct team
                        Assert.AreEqual(board.GetPieceAt(x, y).GetType(), rook_type);                           //correct type of piece
                    }
                    else if (x == 1 || x == 6)
                    {
                        Assert.AreEqual(board.IsOccupied(x, y), ChessGlobals.BoardConstants.OCCUPIED_SQUARE);     //a piece should occupy here
                        Assert.AreEqual(board.GetPieceAt(x, y).GetTeam(), ChessGlobals.Teams.BLACK_TEAM);         //correct team
                        Assert.AreEqual(board.GetPieceAt(x, y).GetType(), knight_type);                           //correct type of piece
                    }
                    else if (x == 2 || x == 5)
                    {
                        Assert.AreEqual(board.IsOccupied(x, y), ChessGlobals.BoardConstants.OCCUPIED_SQUARE);     //a piece should occupy here
                        Assert.AreEqual(board.GetPieceAt(x, y).GetTeam(), ChessGlobals.Teams.BLACK_TEAM);         //correct team
                        Assert.AreEqual(board.GetPieceAt(x, y).GetType(), bishop_type);                           //correct type of piece
                    }
                    else if (x == 3)
                    {
                        Assert.AreEqual(board.IsOccupied(x, y), ChessGlobals.BoardConstants.OCCUPIED_SQUARE);   //a piece should occupy here
                        Assert.AreEqual(board.GetPieceAt(x, y).GetTeam(), ChessGlobals.Teams.BLACK_TEAM);       //correct team
                        Assert.AreEqual(board.GetPieceAt(x, y).GetType(), king_type);                           //correct type of piece
                    }
                    else if (x == 4)
                    {
                        Assert.AreEqual(board.IsOccupied(x, y), ChessGlobals.BoardConstants.OCCUPIED_SQUARE);    //a piece should occupy here
                        Assert.AreEqual(board.GetPieceAt(x, y).GetTeam(), ChessGlobals.Teams.BLACK_TEAM);        //correct team
                        Assert.AreEqual(board.GetPieceAt(x, y).GetType(), queen_type);                           //correct type of piece
                    }
                }
            }
        }
    }