Example #1
0
            public void Returns_No_When_Destination_Is_Invalid()
            {
                var move = new MoveAttempt(_board, _whiteStart, new BoardCoordinate(2, 3));
                var moveResult = _referee.TryMove(move);

                Assert.AreEqual(MoveResult.Failed(), moveResult);
            }
Example #2
0
            public void Returns_No_When_Diagonal_Move_Is_Blocked()
            {
                _blackStart = new BoardCoordinate(4, 4);
                _board.AddPiece(_blackQueen, _blackStart);

                var move = new MoveAttempt(_board, _whiteStart, new BoardCoordinate(8, 8));
                var moveResult = _referee.TryMove(move);
                Assert.AreEqual(MoveResult.Failed(), moveResult);
            }
Example #3
0
            public void Returns_No_When_Diagonal_Move_Is_Blocked_From_Non_1_1_Start()
            {
                var newWhiteStart = new BoardCoordinate(2, 1);
                _board.RemovePiece(_whiteStart);
                _board.AddPiece(_whiteQueen, newWhiteStart);
                _blackStart = new BoardCoordinate(3, 2);
                _board.AddPiece(_blackQueen, _blackStart);

                var move = new MoveAttempt(_board, newWhiteStart, new BoardCoordinate(4, 3));
                var moveResult = _referee.TryMove(move);
                Assert.AreEqual(MoveResult.Failed(), moveResult);
            }
Example #4
0
            public void Returns_Capture_When_Capturing_Check()
            {
                var king = new King(PlayerColor.Black);
                var kingStart = new BoardCoordinate(1, 8);
                _board.AddPiece(king, kingStart);

                _blackStart = new BoardCoordinate(8, 1);
                _board.AddPiece(_blackQueen, _blackStart);

                var move = new MoveAttempt(_board, _blackStart, _whiteStart);
                var moveResult = _referee.TryMove(move);
                Assert.AreEqual(MoveResult.Captured(_whiteQueen), moveResult);
            }
Example #5
0
            public void Returns_No_When_Not_Solving_Check()
            {
                var king = new King(PlayerColor.Black);
                var kingStart = new BoardCoordinate(1, 8);
                _board.AddPiece(king, kingStart);

                _blackStart = new BoardCoordinate(2, 4);
                _board.AddPiece(_blackQueen, _blackStart);

                var move = new MoveAttempt(_board, _blackStart, new BoardCoordinate(2, 8));
                var moveResult = _referee.TryMove(move);
                Assert.AreEqual(MoveResult.Failed(), moveResult);
            }
Example #6
0
            public void Returns_Yes_Moving_King_Out_Of_Check()
            {
                var king = new King(PlayerColor.Black);
                var kingStart = new BoardCoordinate(1, 8);
                _board.AddPiece(king, kingStart);

                var move = new MoveAttempt(_board, kingStart, new BoardCoordinate(2, 8));
                var moveResult = _referee.TryMove(move);
                Assert.AreEqual(MoveResult.Succeeded(), moveResult);
            }
Example #7
0
            public void Returns_Capture_When_Move_To_Opponent_Occupied_Square()
            {
                _blackStart = new BoardCoordinate(1, 4);
                _board.AddPiece(_blackQueen, _blackStart);

                var move = new MoveAttempt(_board, _whiteStart, _blackStart);
                var moveResult = _referee.TryMove(move);
                var endPiece = _board.GetPiece(_blackStart);

                Assert.IsTrue(moveResult == MoveResult.Captured(_blackQueen) && endPiece == _whiteQueen);
            }
Example #8
0
            public void Returns_Yes_When_Moving_To_Unoccupied_Square()
            {
                _blackStart = new BoardCoordinate(1, 4);
                _board.AddPiece(_blackQueen, _blackStart);

                var destination = new BoardCoordinate(8, 1);
                var move = new MoveAttempt(_board, _whiteStart, destination);
                var moveResult = _referee.TryMove(move);
                var endPiece = _board.GetPiece(destination);

                Assert.IsTrue(moveResult == MoveResult.Succeeded() && endPiece == _whiteQueen);
            }
Example #9
0
            public void Returns_Yes_When_Knight_Move_Is_Blocked()
            {
                _blackStart = new BoardCoordinate(2, 2);
                _board.AddPiece(_blackQueen, _blackStart);

                var knight = new Knight(PlayerColor.White);
                var knightStart = new BoardCoordinate(2, 1);

                _board.AddPiece(knight, knightStart);

                var destination = new BoardCoordinate(3, 3);
                var move = new MoveAttempt(_board, knightStart, destination);
                var moveResult = _referee.TryMove(move);

                Assert.AreEqual(MoveResult.Succeeded(), moveResult);
            }
Example #10
0
 public MoveResult TryMove(MoveAttempt attempt)
 {
     _moveHandler.Handle(attempt);
     return _moveHandler.Result as MoveResult;
 }