Пример #1
0
        public void IsLastMoveSmash_NotSmash_ShouldReturnFalse()
        {
            // arrange
            var board = new OrdinaryChessBoard();
            var startBlackPawnPosition  = new Position(1, 5);
            var oneHopBlackPawnPosition = new Position(3, 5);
            var startWhitePawnPosition  = new Position(6, 4);
            var oneHopWhitePawnPosition = new Position(4, 4);

            var blackPawn = board.RemoveFigure(startBlackPawnPosition);

            blackPawn.Move(oneHopBlackPawnPosition);
            board.SetFigure(blackPawn, oneHopBlackPawnPosition);

            var whitePawn = board.RemoveFigure(startWhitePawnPosition);

            whitePawn.Move(oneHopWhitePawnPosition);
            board.SetFigure(whitePawn, oneHopWhitePawnPosition);

            var validator  = new OrdinaryBoardMoveValidator(board);
            var verifier   = new OrdinaryBoardCheckVerifier(board, validator);
            var lastMoveVm = new LastMoveViewModel(whitePawn, startWhitePawnPosition, oneHopWhitePawnPosition, null);
            var moveResult = new ValidMoveResult(board, verifier, null, lastMoveVm, null);

            // act
            var result = moveResult.IsLastMoveSmash();

            // assert
            Assert.False(result);
        }
Пример #2
0
        public void IsCheckMate_OnlyCheck_CulpritMayBeKilled_ShouldReturnFalse()
        {
            // arrange
            var board = new OrdinaryChessBoard();

            var blackPawnStartPosition  = new Position(1, 7);
            var blackPawnMiddlePosition = new Position(2, 7);
            var blackPawnEndPosition    = new Position(3, 7);

            var whiteKnightStartPosition     = new Position(7, 1);
            var whiteKnightFirstHopPosition  = new Position(5, 2);
            var whiteKnightSecondHopPosition = new Position(3, 3);
            var whiteKnightEndPosition       = new Position(2, 5);

            var blackPawn = board.RemoveFigure(blackPawnStartPosition);

            blackPawn.Move(blackPawnMiddlePosition);
            board.SetFigure(blackPawn, blackPawnMiddlePosition);
            board.RemoveFigure(blackPawnMiddlePosition);
            blackPawn.Move(blackPawnEndPosition);
            board.SetFigure(blackPawn, blackPawnEndPosition);
            var whiteKnight = board.RemoveFigure(whiteKnightStartPosition);

            whiteKnight.Move(whiteKnightFirstHopPosition);
            board.SetFigure(whiteKnight, whiteKnightFirstHopPosition);
            board.RemoveFigure(whiteKnightFirstHopPosition);
            whiteKnight.Move(whiteKnightSecondHopPosition);
            board.SetFigure(whiteKnight, whiteKnightSecondHopPosition);
            board.RemoveFigure(whiteKnightSecondHopPosition);
            whiteKnight.Move(whiteKnightEndPosition);
            board.SetFigure(whiteKnight, whiteKnightEndPosition);

            var validator  = new OrdinaryBoardMoveValidator(board);
            var verifier   = new OrdinaryBoardCheckVerifier(board, validator);
            var lastMoveVm =
                new LastMoveViewModel(whiteKnight, whiteKnightSecondHopPosition, whiteKnightEndPosition, null);
            var moveResult =
                new ValidMoveResult(board, verifier, validator, lastMoveVm, null);

            var team1 = TeamColor.White;
            var team2 = TeamColor.Black;
            // act

            var result1 = moveResult.IsCheck(team1);
            var result2 = moveResult.IsCheck(team2);
            var result3 = moveResult.IsCheckMate(team1);
            var result4 = moveResult.IsCheckMate(team2);

            // assert
            Assert.True(result1);
            Assert.False(result2);
            Assert.False(result3);
            Assert.False(result4);
        }
Пример #3
0
        public void IsCheckMate_CheckMateWhiteTeam()
        {
            // arrange
            var board = new OrdinaryChessBoard();

            var whitePawn1StartPosition = new Position(6, 5);
            var whitePawn1EndPosition   = new Position(5, 5);
            var whitePawn2StartPosition = new Position(6, 6);
            var whitePawn2EndPosition   = new Position(4, 6);
            var blackPawnStartPosition  = new Position(1, 4);
            var blackPawnEndPosition    = new Position(3, 4);
            var blackQueenStartPosition = new Position(0, 3);
            var blackQueenEndPosition   = new Position(4, 7);

            var whitePawn1 = board.RemoveFigure(whitePawn1StartPosition);

            whitePawn1.Move(whitePawn1EndPosition);
            board.SetFigure(whitePawn1, whitePawn1EndPosition);
            var blackPawn = board.RemoveFigure(blackPawnStartPosition);

            blackPawn.Move(blackPawnEndPosition);
            board.SetFigure(blackPawn, blackPawnEndPosition);
            var whitePawn2 = board.RemoveFigure(whitePawn2StartPosition);

            whitePawn2.Move(whitePawn2EndPosition);
            board.SetFigure(whitePawn2, whitePawn2EndPosition);
            var blackQueen = board.RemoveFigure(blackQueenStartPosition);

            blackQueen.Move(blackQueenEndPosition);
            board.SetFigure(blackQueen, blackQueenEndPosition);

            var validator  = new OrdinaryBoardMoveValidator(board);
            var verifier   = new OrdinaryBoardCheckVerifier(board, validator);
            var lastMoveVm = new LastMoveViewModel(blackQueen, blackQueenStartPosition, blackPawnEndPosition, null);
            var moveResult =
                new ValidMoveResult(board, verifier, validator, lastMoveVm, null);

            var team1 = TeamColor.White;
            var team2 = TeamColor.Black;
            // act

            var result1 = moveResult.IsCheck(team1);
            var result2 = moveResult.IsCheck(team2);
            var result3 = moveResult.IsCheckMate(team1);
            var result4 = moveResult.IsCheckMate(team2);

            // assert
            Assert.False(result1);
            Assert.True(result2);
            Assert.False(result3);
            Assert.True(result4);
        }
        public void IsCheck_BlackTeam_BlackChecked_Bishop_ShouldReturnFalse()
        {
            // arrange
            var board = new OrdinaryChessBoard();
            var blackPawnDeletePosition  = new Position(1, 3);
            var whiteBishopStartPosition = new Position(7, 5);
            var whiteBishopEndPosition   = new Position(4, 0);

            board.RemoveFigure(blackPawnDeletePosition);
            var bishop = board.RemoveFigure(whiteBishopStartPosition);

            bishop.Move(whiteBishopEndPosition);
            board.SetFigure(bishop, whiteBishopEndPosition);

            var moveValidator = new OrdinaryBoardMoveValidator(board);
            var verifier      = new OrdinaryBoardCheckVerifier(board, moveValidator);

            TeamColor teamColor = TeamColor.Black;

            // act
            var result = verifier.IsCheck(teamColor);

            // assert
            Assert.False(result);
        }
        public void VerifyMoveCauseCheck_BlackKingChecked_MoveToSavePosition_ShouldReturnFalse()
        {
            // arrange
            var board = new OrdinaryChessBoard();

            var blackPawnRemove1Postion = new Position(1, 3);
            var blackPawnRemove2Postion = new Position(1, 4);
            var startWhiteQueenPosition = new Position(7, 3);
            var endWhiteQueenPosition   = new Position(4, 0);
            var blackKingStartPosition  = new Position(0, 4);
            var blackKingEndPosition    = new Position(1, 4);

            board.RemoveFigure(blackPawnRemove1Postion);
            board.RemoveFigure(blackPawnRemove2Postion);

            var whiteQueen = board.RemoveFigure(startWhiteQueenPosition);

            whiteQueen.Move(endWhiteQueenPosition);
            board.SetFigure(whiteQueen, endWhiteQueenPosition);

            var moveValidator = new OrdinaryBoardMoveValidator(board);
            var verifier      = new OrdinaryBoardCheckVerifier(board, moveValidator);

            // act
            var result = verifier.VerifyMoveCauseCheck(blackKingStartPosition, blackKingEndPosition);

            // assert
            Assert.False(result);
        }
Пример #6
0
        public void IsCheckMate_NotCheck_ShouldReturnFalse()
        {
            // arrange
            var board = new OrdinaryChessBoard();

            var pawnStartPosition = new Position(1, 0);
            var pawnEndPosition   = new Position(2, 0);

            var pawn = board.RemoveFigure(pawnStartPosition);

            pawn.Move(pawnEndPosition);
            board.SetFigure(pawn, pawnEndPosition);

            var validator  = new OrdinaryBoardMoveValidator(board);
            var verifier   = new OrdinaryBoardCheckVerifier(board, validator);
            var lastMoveVm = new LastMoveViewModel(pawn, pawnStartPosition, pawnEndPosition, null);
            var moveResult =
                new ValidMoveResult(board, verifier, validator, lastMoveVm, null);

            var team1 = TeamColor.Black;
            var team2 = TeamColor.White;
            // act

            var result1 = moveResult.IsCheck(team1);
            var result2 = moveResult.IsCheck(team2);
            var result3 = moveResult.IsCheckMate(team1);
            var result4 = moveResult.IsCheckMate(team2);

            // assert
            Assert.False(result1);
            Assert.False(result2);
            Assert.False(result3);
            Assert.False(result4);
        }
Пример #7
0
        public void GetScore_AfterMovementBlack_BottomLeftPawnTwoFieldUp_WhiteTeam_ShouldBe_Minus1()
        {
            // arrange
            var       startingBoard     = new OrdinaryChessBoard();
            TeamColor team              = TeamColor.White;
            var       startPawnPosition = new Position(1, 0);
            var       endPawnPosition   = new Position(3, 0);

            var pawn = startingBoard.RemoveFigure(startPawnPosition);

            startingBoard.SetFigure(pawn, endPawnPosition);
            pawn.Move(endPawnPosition);
            var validator  = new OrdinaryBoardMoveValidator(startingBoard);
            var verifier   = new OrdinaryBoardCheckVerifier(startingBoard, validator);
            var lastMoveVm = new LastMoveViewModel(pawn, startPawnPosition, endPawnPosition, null);
            var moveResult =
                new ValidMoveResult(startingBoard, verifier, null, lastMoveVm, null);

            int expectedScore = -1;
            // act
            var result = moveResult.GetScore(team);

            // assert
            Assert.AreEqual(expectedScore, result);
        }
Пример #8
0
        public void IsCheckMate_OnlyCheck_PathMayBeBlocked_ShouldReturnFalse()
        {
            // arrange
            var board = new OrdinaryChessBoard();

            var blackPawnStartPosition  = new Position(1, 3);
            var blackPawnEndPosition    = new Position(2, 3);
            var whitePawnStartPosition  = new Position(6, 2);
            var whitePawnEndPosition    = new Position(5, 2);
            var whiteQueenStartPosition = new Position(7, 3);
            var whiteQueenEndPosition   = new Position(4, 0);


            var blackPawn1 = board.RemoveFigure(blackPawnStartPosition);

            blackPawn1.Move(blackPawnEndPosition);
            board.SetFigure(blackPawn1, blackPawnEndPosition);
            var whitePawn = board.RemoveFigure(whitePawnStartPosition);

            whitePawn.Move(whitePawnEndPosition);
            board.SetFigure(whitePawn, whitePawnEndPosition);
            var whiteQueen = board.RemoveFigure(whiteQueenStartPosition);

            whiteQueen.Move(whiteQueenEndPosition);
            board.SetFigure(whiteQueen, whiteQueenEndPosition);

            var validator  = new OrdinaryBoardMoveValidator(board);
            var verifier   = new OrdinaryBoardCheckVerifier(board, validator);
            var lastMoveVm = new LastMoveViewModel(whiteQueen, whiteQueenStartPosition, whitePawnEndPosition, null);
            var moveResult =
                new ValidMoveResult(board, verifier, validator, lastMoveVm, null);

            var team1 = TeamColor.White;
            var team2 = TeamColor.Black;
            // act

            var result1 = moveResult.IsCheck(team1);
            var result2 = moveResult.IsCheck(team2);
            var result3 = moveResult.IsCheckMate(team1);
            var result4 = moveResult.IsCheckMate(team2);

            // assert
            Assert.True(result1);
            Assert.False(result2);
            Assert.False(result3);
            Assert.False(result4);
        }
Пример #9
0
        public void LastMoveFigureAndPositionFromAndDest_Smash()
        {
            // arrange
            var board = new OrdinaryChessBoard();
            var startBlackPawnPosition  = new Position(1, 5);
            var oneHopBlackPawnPosition = new Position(3, 5);
            var startWhitePawnPosition  = new Position(6, 4);
            var oneHopWhitePawnPosition = new Position(4, 4);

            var blackPawn = board.RemoveFigure(startBlackPawnPosition);

            blackPawn.Move(oneHopBlackPawnPosition);
            board.SetFigure(blackPawn, oneHopBlackPawnPosition);

            var whitePawn = board.RemoveFigure(startWhitePawnPosition);

            whitePawn.Move(oneHopWhitePawnPosition);
            board.SetFigure(whitePawn, oneHopWhitePawnPosition);

            board.RemoveFigure(oneHopWhitePawnPosition);
            blackPawn = board.RemoveFigure(oneHopBlackPawnPosition);
            blackPawn.Move(oneHopWhitePawnPosition);
            board.SetFigure(blackPawn, oneHopWhitePawnPosition);

            var validator  = new OrdinaryBoardMoveValidator(board);
            var verifier   = new OrdinaryBoardCheckVerifier(board, validator);
            var lastMoveVm =
                new LastMoveViewModel(blackPawn, oneHopBlackPawnPosition, oneHopWhitePawnPosition, whitePawn);
            var moveResult = new ValidMoveResult(board, verifier, null, lastMoveVm, null);

            var expectedLastMoveFigure       = blackPawn;
            var expectedLastMovePositionFrom = oneHopBlackPawnPosition;
            var expectedLastMovePositionDest = oneHopWhitePawnPosition;

            // act
            var result = moveResult.LastMoveFigureAndPositionFromAndDest();

            // assert
            Assert.AreEqual(expectedLastMoveFigure, result.Item1);
            Assert.AreEqual(expectedLastMovePositionFrom, result.Item2);
            Assert.AreEqual(expectedLastMovePositionDest, result.Item3);
        }
Пример #10
0
        public void SmashedFigure_SmashedWhitePawn_ShouldThisFigure()
        {
            // arrange
            var board = new OrdinaryChessBoard();
            var startBlackPawnPosition  = new Position(1, 5);
            var oneHopBlackPawnPosition = new Position(3, 5);
            var startWhitePawnPosition  = new Position(6, 4);
            var oneHopWhitePawnPosition = new Position(4, 4);

            var blackPawn = board.RemoveFigure(startBlackPawnPosition);

            blackPawn.Move(oneHopBlackPawnPosition);
            board.SetFigure(blackPawn, oneHopBlackPawnPosition);

            var whitePawn = board.RemoveFigure(startWhitePawnPosition);

            whitePawn.Move(oneHopWhitePawnPosition);
            board.SetFigure(whitePawn, oneHopWhitePawnPosition);

            board.RemoveFigure(oneHopWhitePawnPosition);
            blackPawn = board.RemoveFigure(oneHopBlackPawnPosition);
            blackPawn.Move(oneHopWhitePawnPosition);
            board.SetFigure(blackPawn, oneHopWhitePawnPosition);

            var validator  = new OrdinaryBoardMoveValidator(board);
            var verifier   = new OrdinaryBoardCheckVerifier(board, validator);
            var lastMoveVm =
                new LastMoveViewModel(blackPawn, oneHopBlackPawnPosition, oneHopWhitePawnPosition, whitePawn);
            var moveResult = new ValidMoveResult(board, verifier, null, lastMoveVm, null);

            var expected = whitePawn;

            // act
            var isSmash = moveResult.IsLastMoveSmash();
            var result  = moveResult.SmashedFigure();

            // assert
            Assert.True(isSmash);
            Assert.AreEqual(expected, result);
        }
Пример #11
0
        public void GetScore_AfterKilledWhite_BlackTeam_ShouldBe_Minus19()
        {
            // arrange
            var       board = new OrdinaryChessBoard();
            TeamColor team  = TeamColor.Black;
            var       startBlackPawnPosition  = new Position(1, 5);
            var       oneHopBlackPawnPosition = new Position(3, 5);
            var       startWhitePawnPosition  = new Position(6, 4);
            var       oneHopWhitePawnPosition = new Position(4, 4);

            var blackPawn = board.RemoveFigure(startBlackPawnPosition);

            blackPawn.Move(oneHopBlackPawnPosition);
            board.SetFigure(blackPawn, oneHopBlackPawnPosition);

            var whitePawn = board.RemoveFigure(startWhitePawnPosition);

            whitePawn.Move(oneHopWhitePawnPosition);
            board.SetFigure(whitePawn, oneHopWhitePawnPosition);

            board.RemoveFigure(oneHopWhitePawnPosition);
            blackPawn = board.RemoveFigure(oneHopBlackPawnPosition);
            blackPawn.Move(oneHopWhitePawnPosition);
            board.SetFigure(blackPawn, oneHopWhitePawnPosition);

            var validator = new OrdinaryBoardMoveValidator(board);
            var verifier  = new OrdinaryBoardCheckVerifier(board, validator);

            var lastMoveVm =
                new LastMoveViewModel(blackPawn, oneHopBlackPawnPosition, oneHopWhitePawnPosition, whitePawn);
            var moveResult = new ValidMoveResult(board, verifier, null, lastMoveVm, null);

            int expectedScore = -19;

            // act
            var result = moveResult.GetScore(team);

            // assert
            Assert.AreEqual(expectedScore, result);
        }
        public void StartGame_Black_Depth1_Breadth5()
        {
            // arrange
            var computer = new ComputerPlayer(TeamColor.Black, 1, 5);
            var board    = new OrdinaryChessBoard();
            var boardVm  = new BoardViewModel(board);

            // act
            var move = computer.NextMove(boardVm);

            // assert
            Assert.NotNull(move);
            Assert.Greater(move.Score, 9);

            var figure = board.RemoveFigure(move.From);

            figure.Move(move.Destination);
            board.SetFigure(figure, move.Destination);

            Assert.AreEqual(move.Score, board.GetScoreForTeam(TeamColor.Black));
        }
        public void VerifyMoveCauseCheck_MoveWhiteKnight_CheckBlackKing_ShouldReturnTrue()
        {
            // arrange
            var board = new OrdinaryChessBoard();
            var whiteKnightStartPosition  = new Position(7, 1);
            var whiteKnightMiddlePosition = new Position(4, 2);
            var whiteKnightEndPosition    = new Position(2, 3);

            var knight = board.RemoveFigure(whiteKnightStartPosition);

            knight.Move(whiteKnightMiddlePosition);
            board.SetFigure(knight, whiteKnightMiddlePosition);

            var moveValidator = new OrdinaryBoardMoveValidator(board);
            var verifier      = new OrdinaryBoardCheckVerifier(board, moveValidator);

            // act
            var result = verifier.VerifyMoveCauseCheck(whiteKnightMiddlePosition, whiteKnightEndPosition);

            // assert
            Assert.True(result);
        }
        public void IsCheck_WhiteTeam_NotCheck_ShouldReturnFalse()
        {
            // arrange
            var board = new OrdinaryChessBoard();
            var startBlackPawnPosition = new Position(1, 5);
            var endBlackPawnPosition   = new Position(3, 5);

            var blackPawn = board.RemoveFigure(startBlackPawnPosition);

            blackPawn.Move(endBlackPawnPosition);
            board.SetFigure(blackPawn, endBlackPawnPosition);
            var moveValidator = new OrdinaryBoardMoveValidator(board);
            var checkVerifier = new OrdinaryBoardCheckVerifier(board, moveValidator);

            TeamColor teamColor = TeamColor.White;

            // act
            var result = checkVerifier.IsCheck(teamColor);

            // assert
            Assert.False(result);
        }
        [Test] public void IsCheck_WhiteTeam_WhiteChecked_Knight_ShouldReturnFalse()
        {
            // arrange
            var board = new OrdinaryChessBoard();
            var knightStartPosition = new Position(0, 1);
            var knightEndPosition   = new Position(5, 3);

            var knight = board.RemoveFigure(knightStartPosition);

            knight.Move(knightEndPosition);
            board.SetFigure(knight, knightEndPosition);

            var moveValidator = new OrdinaryBoardMoveValidator(board);
            var verifier      = new OrdinaryBoardCheckVerifier(board, moveValidator);

            TeamColor teamColor = TeamColor.White;

            // act
            var result = verifier.IsCheck(teamColor);

            // assert
            Assert.False(result);
        }
        public void VerifyMoveCauseCheck_BlackPawn_RevealsTheBlackKing_ShouldReturnTrue()
        {
            // arrange
            var board = new OrdinaryChessBoard();

            var blackPawnStartPosition  = new Position(1, 3);
            var blackPawnEndPosition    = new Position(2, 3);
            var startWhiteQueenPosition = new Position(7, 3);
            var endWhiteQueenPosition   = new Position(4, 0);

            var whiteQueen = board.RemoveFigure(startWhiteQueenPosition);

            whiteQueen.Move(endWhiteQueenPosition);
            board.SetFigure(whiteQueen, endWhiteQueenPosition);

            var moveValidator = new OrdinaryBoardMoveValidator(board);
            var verifier      = new OrdinaryBoardCheckVerifier(board, moveValidator);

            // act
            var result = verifier.VerifyMoveCauseCheck(blackPawnStartPosition, blackPawnEndPosition);

            // assert
            Assert.True(result);
        }