Beispiel #1
0
        public void constructor_blackPawn()
        {
            Piece        piece = new BlackPawn(new Point(7, 7), new ChessBoard());
            PieceManager pm    = new PieceManager(piece, new Game());

            Assert.AreEqual(pm.Owner, Players.BlackPlayer);
            Assert.AreEqual(pm.Type, PieceTypes.Pawn);
        }
Beispiel #2
0
        public void constructor_correct(int x, int y)
        {
            ChessBoard board     = new ChessBoard();
            Piece      blackPawn = new BlackPawn(new Point(x, y), board);

            Assert.AreEqual(blackPawn.Color, "Black");
            Assert.AreEqual(blackPawn.Name, "Pawn");
            Assert.IsTrue(blackPawn is SlowPiece);
            Assert.IsFalse(blackPawn.WasMoved);
            Assert.AreSame(board.GetPiece(new Point(x, y)), blackPawn);
            Assert.AreEqual(blackPawn.Position, new Point(x, y));
        }
Beispiel #3
0
 public void SetUp()
 {
     _chessBoard  = new ChessBoard();
     _blackBishop = new Bishop(PieceColor.Black, _chessBoard);
     _whiteRook   = new Rook(PieceColor.White, _chessBoard);
     _whitePawn   = new WhitePawn(_chessBoard);
     _blackKing   = new BlackKing(_chessBoard);
     _whiteKing   = new WhiteKing(_chessBoard);
     _blackPawn   = new BlackPawn(_chessBoard);
     _chessBoard.Add(_blackKing, 4, 7);
     _chessBoard.Add(_whiteKing, 4, 0);
 }
Beispiel #4
0
 public void SetUp()
 {
     _chessBoard  = new ChessBoard();
     _blackBishop = new Bishop(PieceColor.Black, _chessBoard);
     _whiteQueen  = new Queen(PieceColor.White, _chessBoard);
     _whiteKnight = new Knight(PieceColor.White, _chessBoard);
     _blackPawn   = new BlackPawn(_chessBoard);
     _blackKing   = new BlackKing(_chessBoard);
     _whiteKing   = new WhiteKing(_chessBoard);
     _chessBoard.Add(_blackKing, 4, 7);
     _chessBoard.Add(_whiteKing, 4, 0);
 }
Beispiel #5
0
        public void move_for_the_first_time(int x, int y)
        {
            ChessBoard board = new ChessBoard();

            new WhitePawn(new Point(3, 4), board);
            new WhitePawn(new Point(5, 4), board);
            Piece blackPawn = new BlackPawn(new Point(4, 5), board);

            Assert.AreEqual(blackPawn.MoveSet[0], new Point(0, -1));
            Assert.AreEqual(blackPawn.MoveSet[1], new Point(0, -2));
            Assert.IsFalse(blackPawn.WasMoved);
            blackPawn.moveTo(new Point(x, y));
            Assert.AreEqual(blackPawn.MoveSet[0], new Point(0, -1));
            Assert.IsTrue(blackPawn.WasMoved);
        }
Beispiel #6
0
        /// <summary>
        /// Gets a board in the starting position.
        /// </summary>
        /// <returns></returns>
        public static Board GetStartingBoard()
        {
            var squares = new Piece[SquareNo];
            var status  = new BoardStatus();

            squares[A8] = new BlackRook();
            squares[B8] = new BlackKnight();
            squares[C8] = new BlackBishop();
            squares[D8] = new BlackQueen();
            squares[E8] = new BlackKing();
            squares[F8] = new BlackBishop();
            squares[G8] = new BlackKnight();
            squares[H8] = new BlackRook();

            for (var sqIndex = SideSquareNo; sqIndex < SideSquareNo * 2; sqIndex++)
            {
                squares[sqIndex] = new BlackPawn();
            }

            for (var sqIndex = SideSquareNo * (SideSquareNo - 2); sqIndex < SideSquareNo * (SideSquareNo - 1); sqIndex++)
            {
                squares[sqIndex] = new WhitePawn();
            }

            squares[A1] = new WhiteRook();
            squares[B1] = new WhiteKnight();
            squares[C1] = new WhiteBishop();
            squares[D1] = new WhiteQueen();
            squares[E1] = new WhiteKing();
            squares[F1] = new WhiteBishop();
            squares[G1] = new WhiteKnight();
            squares[H1] = new WhiteRook();

            status.WhiteTurn            = true;
            status.WhiteCouldCastleLong = status.WhiteCouldCastleShort = status.BlackCouldCastleLong = status.BlackCouldCastleShort = true;
            status.EnPassantTarget      = null;
            status.Ply   = 0;
            status.Moves = 1;

            return(new Board(squares, status));
        }
Beispiel #7
0
        public void IsMoveValid_PawnTriesToMoveForwardButFriendlyPieceBlocksIt_ShouldReturnFalse(int destX, int destY, int friendlyPawnX, int friendlyPawnY)
        {
            // Arrange
            var movingPlayer  = new Player(PlayerColor.White);
            var waitingPlayer = new Player(PlayerColor.Black);

            var friendlyPiece = new BlackPawn(new Position(friendlyPawnX, friendlyPawnY));
            var movingPawn    = new WhitePawn(new Position(2, 0));
            var king          = new King(new Position(7, 7));

            movingPlayer.Pieces.Add(movingPawn);
            movingPlayer.Pieces.Add(king);
            movingPlayer.Pieces.Add(friendlyPiece);

            var dest = new Position(destX, destY);

            // Act
            var result = gameValidationService.ValidateMove(TODO, TODO);

            // Assert
            result.ShouldBe(false);
        }
    public void UndoMove()
    {
        Movement LastMove = allMoves[allMoves.Count - 1];

        if (LastMove.MovedTo.isSpecial)
        {
            if (LastMove.PieceMoved is King)
            {
                if (LastMove.MovedTo.theValidMove.indCol == 2)
                {
                    MovePieceTo(this.AllSquares[LastMove.PieceMoved.SquareOfPiece.indRow, 3].PieceInSquare, this.AllSquares[LastMove.PieceMoved.SquareOfPiece.indRow, 0]);
                    this.AllSquares[LastMove.PieceMoved.SquareOfPiece.indRow, 0].PieceInSquare.movesMade -= 2;
                }
                else
                {
                    MovePieceTo(this.AllSquares[LastMove.PieceMoved.SquareOfPiece.indRow, 5].PieceInSquare, this.AllSquares[LastMove.PieceMoved.SquareOfPiece.indRow, 7]);
                    this.AllSquares[LastMove.PieceMoved.SquareOfPiece.indRow, 7].PieceInSquare.movesMade -= 2;
                }
            }
            else if (LastMove.PieceMoved is WhitePawn)
            {
                GameObject tempObject    = LastMove.MovedTo.theValidMove.PieceInSquare.gameObject;
                int        tempMovesMade = LastMove.MovedTo.theValidMove.PieceInSquare.movesMade;

                DestroyImmediate(LastMove.MovedTo.theValidMove.PieceInSquare);
                LastMove.MovedTo.theValidMove.PieceInSquare = null;

                WhitePawn ReAddedPiece = tempObject.AddComponent <WhitePawn>();
                LastMove.MovedTo.theValidMove.PieceInSquare.gameObject.GetComponentInChildren <RawImage>().texture = Resources.Load("Pawns/whitepawn") as Texture;

                ReAddedPiece.Initialize(true, tempMovesMade);
            }
            else if (LastMove.PieceMoved is BlackPawn)
            {
                GameObject tempObject    = LastMove.MovedTo.theValidMove.PieceInSquare.gameObject;
                int        tempMovesMade = LastMove.MovedTo.theValidMove.PieceInSquare.movesMade;

                DestroyImmediate(LastMove.MovedTo.theValidMove.PieceInSquare);
                LastMove.MovedTo.theValidMove.PieceInSquare = null;

                BlackPawn ReAddedPiece = tempObject.AddComponent <BlackPawn>();
                LastMove.MovedTo.theValidMove.PieceInSquare.gameObject.GetComponentInChildren <RawImage>().texture = Resources.Load("Pawns/blackpawn") as Texture;

                ReAddedPiece.Initialize(false, tempMovesMade);
            }
        }



        LastMove.MovedTo.theValidMove.PieceInSquare.transform.SetParent(LastMove.MovedFrom.gameObject.transform, false);
        LastMove.MovedFrom.PieceInSquare = LastMove.MovedTo.theValidMove.PieceInSquare;
        LastMove.MovedFrom.SetPieceCoordinates();
        LastMove.MovedTo.theValidMove.PieceInSquare.SetSquareOfPiece();
        LastMove.MovedTo.theValidMove.PieceInSquare.movesMade -= 1;
        LastMove.MovedTo.theValidMove.PieceInSquare            = null;


        if (LastMove.CapturedPiece != null)
        {
            LastMove.CapturedPiece.transform.SetParent(LastMove.CapturedPiece.SquareOfPiece.transform, false);
            LastMove.CapturedPiece.GetComponent <Canvas>().enabled      = true;
            LastMove.CapturedPiece.GetComponent <Canvas>().sortingOrder = 1;
            LastMove.CapturedPiece.SquareOfPiece.PieceInSquare          = LastMove.CapturedPiece;
        }

        allMoves.RemoveAt(allMoves.Count - 1);
        --turnNumber;

        AllowSquareSelection   = false;
        CurrentPieceSelection  = null;
        CurrentSquareSelection = null;
        foreach (Square j in this.AllSquares)
        {
            j.GetComponentInParent <Image>().color = new Color(j.GetComponentInParent <Image>().color.r,
                                                               j.GetComponentInParent <Image>().color.g,
                                                               j.GetComponentInParent <Image>().color.b,
                                                               1
                                                               );
        }



        if (turnNumber == 1)
        {
            UndoBtn.SetActive(false);
        }
        if (isWhiteTurn)
        {
            isWhiteTurn = false;
            whoseTurnText.GetComponent <Text>().text = "Black's turn";
        }
        else
        {
            isWhiteTurn = true;
            whoseTurnText.GetComponent <Text>().text = "White's turn";
        }


        stateOfGame = CheckSituationOfBoard();
        //  StateOfGame = CheckSituationOfBoard();
    }
Beispiel #9
0
 public void constructor_throw_ArgumentException(int x, int y)
 {
     ChessBoard board     = new ChessBoard();
     Piece      blackPawn = new BlackPawn(new Point(x, y), board);
 }
Beispiel #10
0
 private Chessman GetNewCorrectPawn(ChessmenParameters chessmanParameters, Chessboard chessboard)
 {
     Chessman result;
     switch ((int)chessmanParameters.player)
     {
         case 0: result = new YellowPawn(chessmanParameters, chessboard);
             break;
         case 1: result = new RedPawn(chessmanParameters, chessboard);
             break;
         case 2: result = new BluePawn(chessmanParameters, chessboard);
             break;
         case 3: result = new BlackPawn(chessmanParameters, chessboard);
             break;
         default:
             {
                 result = null;
                 break;
             }
     }
     return result;
 }