Example #1
0
        public void IsMovePossible_PossibleMove_ReturnTrue(string pawnPositionsString, string moveString)
        {
            var pawn = (Pawn)_board[pawnPositionsString];
            var move = MoveParser.ParseMove(moveString, _board);

            Assert.IsTrue(pawn.IsMovePossible(move));
        }
Example #2
0
        public void IsMovePossible_PossibleMove_ReturnTrue(string bishopPositionString, string moveString)
        {
            var bishop = (Bishop)_board[bishopPositionString];
            var move   = MoveParser.ParseMove(moveString, _board);

            Assert.IsTrue(bishop.IsMovePossible(move));
        }
Example #3
0
        public void IsMovePossible_PossibleMove_ReturnTrue(string knightPositionString, string moveString)
        {
            var knight = (Knight)_board[knightPositionString];
            var move   = MoveParser.ParseMove(moveString, _board);

            Assert.IsTrue(knight.IsMovePossible(move));
        }
Example #4
0
        public void IsMovePossible_PossibleMove_ReturnTrue(string kingPositionString, string moveString)
        {
            var king = (King)_board[kingPositionString];
            var move = MoveParser.ParseMove(moveString, _board);

            Assert.IsTrue(king.IsMovePossible(move));
        }
Example #5
0
        public void IsMovePossible_PossibleMove_ReturnTrue(string rookPositionString, string moveString)
        {
            var rook = (Rook)_board[rookPositionString];
            var move = MoveParser.ParseMove(moveString, _board);

            Assert.IsTrue(rook.IsMovePossible(move));
        }
Example #6
0
        public static void ParseMove_CorrectNotation_ReturnExpectedEnPassant(string moveString,
                                                                             string expectedFromPositionString,
                                                                             string expectedToPositionString)
        {
            var expectedMove = new EnPassant((Pawn)_board[expectedFromPositionString], new Position(expectedToPositionString), _board);
            var move         = MoveParser.ParseMove(moveString, _board);

            Assert.That(move.Equals(expectedMove));
        }
Example #7
0
        private static IMove ReadMove(Board board)
        {
            var moveString = Console.ReadLine();

            try
            {
                return(MoveParser.ParseMove(moveString, board));
            }
            catch (Exception ex)
            {
                if (ex is FormatException || ex is ArgumentException)
                {
                    return(null);
                }
                throw;
            }
        }
Example #8
0
        public static void ParseMove_CorrectNotation_ReturnExpectedPromotion(string moveString,
                                                                             string expectedFromPositionString,
                                                                             string expectedToPositionString,
                                                                             char expectedPromotedPawn)
        {
            var pawn = _board[expectedFromPositionString];

            Assert.That(pawn is Pawn);

            var expectedMove = new Promotion((Pawn)_board[expectedFromPositionString], PieceParser.ParsePiece(expectedPromotedPawn, pawn.Color), new Position(expectedToPositionString), _board);
            var move         = MoveParser.ParseMove(moveString, _board);

            Assert.That(move is Promotion);
            var promotion = (Promotion)move;

            Assert.That(expectedMove.To == promotion.To);
            Assert.That(expectedMove.Piece == promotion.Piece);
            Assert.That(expectedMove.Board == promotion.Board);
            Assert.That(expectedMove.PromotedPawn.GetType() == promotion.PromotedPawn.GetType());
        }
Example #9
0
 public void ParseMove_IncorrectMove_ThrowArgumentException(string moveString)
 {
     Assert.Throws <ArgumentException>(() => MoveParser.ParseMove(moveString, _board));
 }
Example #10
0
 public void ParseMove_IncorrectNotation_ThrowFormatException(string moveString)
 {
     Assert.Throws <FormatException>(() => MoveParser.ParseMove(moveString, _board));
 }
Example #11
0
        public void ParseMove_CorrectNotation_ConvertsBackToSameStringRepresentation(string moveString)
        {
            var move = MoveParser.ParseMove(moveString, _board);

            Assert.AreEqual(moveString, move.ToString());
        }