示例#1
0
        //  [InlineData("d7", "d8Q", PieceColor.White)]
        public void PawnCapturesAndPromotesToQueen(string attackerCoords, string opponentCoords, string moveAN, PieceColor attackerColor)
        {
            //promote a pawn with no capture to Queen
            //Arrange
            var board         = new Board(false);
            var opponentColor = attackerColor == PieceColor.Black ? PieceColor.White : PieceColor.Black;

            board.AddPiece(attackerCoords, new Pawn(attackerColor));
            board.AddPiece(opponentCoords, new Rook(opponentColor));
            var list = board.Pieces;
            //Act
            var move = MoveNotationConverter.ParseMoveNotation(moveAN, attackerColor);

            //caut piesa care face capturarea
            board.FindPieceWhoNeedsToBeMoved(move);


            //determina celula destinatie
            //var cellDestination = board.TransformCoordonatesIntoCell(move.Coordinate);
            var cellDestination = board.CellAt(move.Coordinate);

            //cauta piesa oponenta
            var opponent = cellDestination.Piece;

            board.PlayMove(moveAN, attackerColor);

            Assert.Null(opponent.DestinationCell);
            Assert.IsType <Queen>(board.CellAt(move.Coordinate).Piece);
        }
        public void CheckIfParseIsCorrect()
        {
            var move = MoveNotationConverter.ParseMoveNotation("Pa4Q");

            Assert.False(move.IsCheckMate);
            Assert.True(move.IsPromotion);
        }
        public void CheckRegexForKingCastlingShouldReturnNewPiece()
        {
            var notation = "0-0";

            var move = MoveNotationConverter.ParseMoveNotation(notation);


            Assert.True(move.IsKingCastling);
            Assert.False(move.IsQueenCastling);
        }
        public void CheckRegexForMovePawnToPromotionShouldReturnNewPiece()
        {
            var notation = "Pe8Q++";
            var move     = MoveNotationConverter.ParseMoveNotation(notation);

            Assert.NotNull(move.Coordinate);
            Assert.True(move.IsPromotion);

            Assert.False(move.IsCheck);
            Assert.True(move.IsCheckMate);
        }
        public void CheckRegexForMoveBishopShouldReturn()
        {
            var notation = "Be5+";

            var move = MoveNotationConverter.ParseMoveNotation(notation);

            Assert.NotNull(move.Coordinate);
            Assert.False(move.IsPromotion);

            Assert.True(move.IsCheck);
            Assert.False(move.IsCheckMate);
        }
示例#6
0
        public void CheckRegexForMovePawnToPromotionShouldReturnNewPiece()
        {
            var notation = "e8Q++";
            var color    = PieceColor.White;
            var move     = MoveNotationConverter.ParseMoveNotation(notation, color);

            Assert.NotNull(move.Coordinate);
            Assert.NotNull(move.Promotion);
            Assert.IsType <Queen>(move.Promotion);
            Assert.Equal(color, move.Promotion.PieceColor);
            Assert.False(move.IsCheck);
            Assert.True(move.IsCheckMate);
        }
示例#7
0
        public void FindWhiteQueenOnAllRoutesWithObstacleShouldReturnNull(string queenCoords, string obstacleCoords, string moveAN, PieceColor currentPlayer)
        {
            //Arange
            var board = new Board(false);

            board.AddPiece(queenCoords, new Queen(currentPlayer));
            board.AddPiece(obstacleCoords, new Pawn(currentPlayer));

            var move  = MoveNotationConverter.ParseMoveNotation(moveAN, currentPlayer);
            var queen = board.FindPieceWhoNeedsToBeMoved(move);

            Assert.False(queen);
        }
示例#8
0
        public void CheckRegexForMoveBishopShouldReturn()
        {
            var notation = "Be5+";
            var color    = PieceColor.White;
            var move     = MoveNotationConverter.ParseMoveNotation(notation, color);

            Assert.NotNull(move.Coordinate);
            Assert.Null(move.Promotion);

            Assert.Equal(color, move.PieceColor);
            Assert.Equal(PieceName.Bishop, move.Name);
            Assert.True(move.IsCheck);
            Assert.False(move.IsCheckMate);
        }
示例#9
0
        public void MoveWhitePawnASquareForward()
        {
            var board = new Board();

            var pawn = board.CellAt("e2").Piece;

            var move = MoveNotationConverter.ParseMoveNotation("e4", PieceColor.White);

            move.MovePiece(pawn, board.CellAt("e4"));
            var isPawn = board.FindPieceWhoNeedsToBeMoved("e5", PieceColor.White);

            Assert.True(isPawn);
            Assert.Null(board.CellAt("e2").Piece);
        }
示例#10
0
        public void WhitePawnCannotMoveBackwords()
        {
            var board = new Board();

            var pawn = board.CellAt("e2").Piece;
            var cell = board.CellAt("e4");
            var move = MoveNotationConverter.ParseMoveNotation("e4", PieceColor.White);

            move.MovePiece(pawn, cell);

            Action exception = () => board.FindPieceWhoNeedsToBeMoved(move);

            Assert.Throws <InvalidOperationException>(exception);
        }
示例#11
0
        public void FindRookOnAllRoutesWithObstacleShouldReturnNull(string rookCoords, string obstacleCoords, string moveAN, PieceColor currentPlayer)
        {
            //Arange
            var board = new Board(false);

            board.AddPiece(rookCoords, new Bishop(currentPlayer));
            board.AddPiece(obstacleCoords, new Pawn(PieceColor.Black));

            var move = MoveNotationConverter.ParseMoveNotation(moveAN, currentPlayer);

            var rook = board.FindPieceWhoNeedsToBeMoved(move);

            Assert.False(rook);
        }
示例#12
0
        public void FindWhiteQueenOnAllRoutesNoObstacleShouldReturnQueen(string queenCoords, string moveAN, PieceColor currentPlayer)
        {
            //Arange
            var board = new Board(false);

            board.AddPiece(queenCoords, new Queen(currentPlayer));

            //find queen on diagonal right-down
            var move = MoveNotationConverter.ParseMoveNotation(moveAN, currentPlayer);

            //var queen = board.FindPieceWhoNeedsToBeMoved(move, PieceColor.White);
            var queen = board.PlayMove(moveAN, PieceColor.White);

            Assert.IsType <Queen>(queen);
        }
示例#13
0
        public void FindWhitePawnWhoNeedsToBeMovedTest()
        {
            var board  = new Board();
            var player = PieceColor.White;
            var move   = MoveNotationConverter.ParseMoveNotation("e3", player);
            var piece  = board.FindPieceWhoNeedsToBeMoved(move);

            Assert.True(piece);
            //Assert.IsType<Pawn>(piece);

            var piece2 = board.FindPieceWhoNeedsToBeMoved("e4", player);

            Assert.True(piece2);
            //Assert.IsType<Pawn>(piece2);
        }
示例#14
0
        public void PawnPromotesToQueen(string pawnCoord, string moveAN, PieceColor pieceColor)
        {
            //promote a pawn with no capture to Queen
            var board = new Board(false);

            var pawnBlack = board.AddPiece(pawnCoord, new Pawn(pieceColor));
            var cell      = board.CellAt(pawnCoord);

            Assert.Equal(pawnBlack, cell.Piece);

            var move = MoveNotationConverter.ParseMoveNotation(moveAN, pieceColor);
            var x    = board.PlayMove(moveAN, pieceColor);

            Assert.Null(pawnBlack.DestinationCell);
            Assert.IsType <Queen>(board.CellAt(move.Coordinate).Piece);
        }
示例#15
0
        public void MoveBishop(string bishopCoords, string moveAN, PieceColor currentPlayer)
        {
            //Arange
            var board = new Board(false);

            board.AddPiece(bishopCoords, new Bishop(currentPlayer));

            //Act
            var move = MoveNotationConverter.ParseMoveNotation(moveAN, currentPlayer);

            var bishop = board.PlayMove(moveAN, currentPlayer);

            //Assert
            Assert.Equal(bishop, board.CellAt(move.Coordinate).Piece);
            Assert.IsType <Bishop>(bishop);
        }
示例#16
0
        public void FindMoveRookWithNoObstacles(string rooksCoords, string moveAN, PieceColor currentPlayer)
        {
            //Arange
            var board = new Board(false);

            board.AddPiece(rooksCoords, new Rook(currentPlayer));

            //Act
            var move = MoveNotationConverter.ParseMoveNotation(moveAN, currentPlayer);

            var rook = board.PlayMove(moveAN, currentPlayer);

            //Assert
            Assert.Equal(rook, board.CellAt(move.Coordinate).Piece);
            Assert.IsType <Rook>(rook);
        }
示例#17
0
        public void MoveBishopWithCapture(string bishopCoords, string moveAN, PieceColor currentPlayer)
        {
            //Arange
            var board = new Board(false);

            board.AddPiece(bishopCoords, new Bishop(currentPlayer));
            board.AddPiece("d6", new Pawn(PieceColor.Black));

            //Act
            var move   = MoveNotationConverter.ParseMoveNotation(moveAN, currentPlayer);
            var list   = board.Pieces;
            var bishop = board.PlayMove(moveAN, currentPlayer);
            int x      = list.Count();

            //Assert
            Assert.Equal(bishop, board.CellAt(move.Coordinate).Piece);
            Assert.IsType <Bishop>(bishop);
        }
示例#18
0
        public void MoveRookWithCapture(string rookCoords, string moveAN, PieceColor currentPlayer)
        {
            //Arange
            var board = new Board(false);

            board.AddPiece(rookCoords, new Rook(currentPlayer));
            board.AddPiece("d5", new Pawn(PieceColor.White));

            //Act
            var move = MoveNotationConverter.ParseMoveNotation(moveAN, currentPlayer);

            var rook = board.PlayMove(moveAN, currentPlayer);

            //Assert
            Assert.Equal(rook, board.CellAt(move.Coordinate).Piece);
            Assert.Null(board.CellAt("f5").Piece);
            Assert.IsType <Rook>(rook);
        }