public void CheckIfKingLostWhenDoesntMeetTheConditions()
        {
            IFigure kingFigure = new KingFigure("K");
            IPosition kingPosition = new Position(5, 7);
            IBoard board = new Board(8, 8);
            board.AddFigure(kingFigure, kingPosition);
            PawnFigure pawnA = new PawnFigure(Constants.FirstPawnDisplaySign);
            board.AddFigure(pawnA, new Position(4, 6));

            PawnFigure pawnB = new PawnFigure(Constants.SecondPawnDisplaySign);
            board.AddFigure(pawnB, new Position(7, 3));

            PawnFigure pawnC = new PawnFigure(Constants.ThirdPawnDisplaySign);
            board.AddFigure(pawnC, new Position(6, 4));

            PawnFigure pawnD = new PawnFigure(Constants.FourthPawnDisplaySign);
            board.AddFigure(pawnD, new Position(7, 7));

            var kingPlayer = new Player("king");
            kingPlayer.AddFigure(new MoveableFigure(kingFigure));

            var pawnPlayer = new Player("pawn");
            pawnPlayer.AddFigure(new MoveableFigure(pawnA));
            pawnPlayer.AddFigure(new MoveableFigure(pawnB));
            pawnPlayer.AddFigure(new MoveableFigure(pawnC));
            pawnPlayer.AddFigure(new MoveableFigure(pawnD));

            var players = new List<IPlayer>()
            {
                kingPlayer,
                pawnPlayer
            };
            var winningConditions = new WinningConditions();
            var isKingWin = winningConditions.KingLost(players, board);
            Assert.AreEqual(isKingWin, false);
        }
Exemple #2
0
        public void CheckIfAnExceptionIsThrownWhenTheCommandIsNotExactlyThreeSymbolsAndThePlayerIsPawn()
        {
            var player = new Player("Serafim");

            var pawn = new PawnAFigure();
            player.AddFigure(pawn);

            var board = new Board();
            var position = new Position(Constants.InitialKingRow, Constants.InitialKingColumn);
            board.AddFigure(pawn, position);

            var commandFactory = new CommandFactory();
            var commandContext = new CommandContext(new BoardMemory(), board, player);
            player.ExecuteCommand(commandContext, "aaaa");
        }
Exemple #3
0
        public void CheckIfAnExceptionIsThrownWhenTheCommandIsThreeSymbolsLongButStillNotCorrect()
        {
            var player = new Player("Serafim");

            var king = new KingFigure();
            player.AddFigure(king);

            var board = new Board();
            var position = new Position(Constants.InitialKingRow, Constants.InitialKingColumn);
            board.AddFigure(king, position);

            var commandFactory = new CommandFactory();
            var commandContext = new CommandContext(new BoardMemory(), board, player);
            player.ExecuteCommand(commandContext, "aaa");
        }
        public void CheckIfKingWinWhenAllPawnAreOnTheLastRow()
        {
            IFigure kingFigure = new KingFigure("K");
            IPosition kingPosition = new Position(1, 2);
            IBoard board = new Board(8, 8);
            board.AddFigure(kingFigure, kingPosition);
            PawnFigure pawnA = new PawnFigure(Constants.FirstPawnDisplaySign);
            board.AddFigure(pawnA, new Position(7, 1));

            PawnFigure pawnB = new PawnFigure(Constants.SecondPawnDisplaySign);
            board.AddFigure(pawnB, new Position(7, 3));

            PawnFigure pawnC = new PawnFigure(Constants.ThirdPawnDisplaySign);
            board.AddFigure(pawnC, new Position(7, 5));

            PawnFigure pawnD = new PawnFigure(Constants.FourthPawnDisplaySign);
            board.AddFigure(pawnD, new Position(7, 7));

            var kingPlayer = new Player("king");
            kingPlayer.AddFigure(new MoveableFigure(kingFigure));

            var pawnPlayer = new Player("pawn");
            pawnPlayer.AddFigure(new MoveableFigure(pawnA));
            pawnPlayer.AddFigure(new MoveableFigure(pawnB));
            pawnPlayer.AddFigure(new MoveableFigure(pawnC));
            pawnPlayer.AddFigure(new MoveableFigure(pawnD));

            var players = new List<IPlayer>()
            {
                kingPlayer,
                pawnPlayer
            };
            var winningConditions = new WinningConditions();
            var isKingWin = winningConditions.KingWon(players, board);
            Assert.AreEqual(isKingWin, true);
        }
Exemple #5
0
        public void CheckIfTheKdlDirectionThrowsWhenThePositionIsNotValid()
        {
            var player = new Player("Serafim");

            var king = new KingFigure();
            player.AddFigure(king);

            var board = new Board();
            var position = new Position(Constants.InitialKingRow, Constants.InitialKingColumn);
            board.AddFigure(king, position);

            var commandContext = new CommandContext(new BoardMemory(), board, player);
            player.ExecuteCommand(commandContext, "kdl");
        }
Exemple #6
0
        public void CheckIfTheMoveMethodSetNewPositionsCorrectlywithTheDdrCommand()
        {
            var player = new Player("Serafim");

            var pawnA = new PawnAFigure();
            player.AddFigure(pawnA);

            var pawnB = new PawnBFigure();
            player.AddFigure(pawnB);

            var pawnC = new PawnCFigure();
            player.AddFigure(pawnC);

            var pawnD = new PawnDFigure();
            player.AddFigure(pawnD);

            var board = new Board();
            var position = new Position(Constants.PawnDInitialRow, Constants.PawnDInitialCol);

            board.AddFigure(pawnA, position);
            board.AddFigure(pawnB, position);
            board.AddFigure(pawnC, position);
            board.AddFigure(pawnD, position);

            var commandFactory = new CommandFactory();
            var playerCommand = commandFactory.CreatePlayerCommand("ddr");
            var commandContext = new CommandContext(new BoardMemory(), board, player);
            player.ExecuteCommand(commandContext, "ddr");

            var actualPosition = board.GetFigurePosition(pawnD);
            var expectedPosition = new Position(1, 7);

            Assert.AreEqual(expectedPosition.Row, actualPosition.Row);
            Assert.AreEqual(expectedPosition.Col, actualPosition.Col);
        }
Exemple #7
0
        public void CheckIfTheMoveMethodSetNewPositionsCorrectlywithTheAdrCommand()
        {
            var player = new Player("Serafim");

            var pawn = new PawnAFigure();
            player.AddFigure(pawn);

            var board = new Board();
            var position = new Position(Constants.PawnAInitialRow, Constants.PawnAInitialCol);
            board.AddFigure(pawn, position);

            var commandFactory = new CommandFactory();
            var commandContext = new CommandContext(new BoardMemory(), board, player);
            player.ExecuteCommand(commandContext, "adr");

            var actualPosition = board.GetFigurePosition(pawn);
            var expectedPosition = new Position(1, 1);

            Assert.AreEqual(expectedPosition.Row, actualPosition.Row);
            Assert.AreEqual(expectedPosition.Col, actualPosition.Col);
        }
Exemple #8
0
        public void CheckIfTheMoveMethodSetNewPositionsCorrectlywithTheAdlCommand()
        {
            var player = new Player("Serafim");

            var pawn = new PawnAFigure();
            player.AddFigure(pawn);

            var board = new Board();
            var position = new Position(0, 0);
            board.AddFigure(pawn, position);

            var commandFactory = new CommandFactory();

            var commandContext = new CommandContext(new BoardMemory(), board, player);
            player.ExecuteCommand(commandContext, "adl");
        }
Exemple #9
0
        public void CheckIfTheKurDirectionIsCorrectlyChanged()
        {
            var player = new Player("Serafim");

            var king = new KingFigure();
            player.AddFigure(king);

            var board = new Board();
            var position = new Position(Constants.InitialKingRow, Constants.InitialKingColumn);
            board.AddFigure(king, position);

            var commandContext = new CommandContext(new BoardMemory(), board, player);
            player.ExecuteCommand(commandContext, "kur");

            var actualPosition = board.GetFigurePosition(king);
            var expectedPosition = new Position(6, 4);

            Assert.AreEqual(expectedPosition.Row, actualPosition.Row);
            Assert.AreEqual(expectedPosition.Col, actualPosition.Col);
        }
        public void GameEngineShouldStartTheGameAndPrintWhenKinWon()
        {
            Mock<IRenderer> mockedRenderer = new Mock<IRenderer>();
            var mockedInput = new Mock<IInputProvider>();
            mockedRenderer.Setup(x => x.PrintMessage(It.IsAny<string>())).Verifiable();

            var board = new Board(8, 8);

            IFigure kingFigure = new KingFigure("K");
            IPosition kingPosition = new Position(0, 2);

            board.AddFigure(kingFigure, kingPosition);
            PawnFigure pawnA = new PawnFigure(Constants.FirstPawnDisplaySign);
            board.AddFigure(pawnA, new Position(1, 2));

            PawnFigure pawnB = new PawnFigure(Constants.SecondPawnDisplaySign);
            board.AddFigure(pawnB, new Position(1, 4));

            PawnFigure pawnC = new PawnFigure(Constants.ThirdPawnDisplaySign);
            board.AddFigure(pawnC, new Position(1, 6));

            PawnFigure pawnD = new PawnFigure(Constants.FourthPawnDisplaySign);
            board.AddFigure(pawnD, new Position(1, 0));

            var kingPlayer = new Player("king");
            kingPlayer.AddFigure(new MoveableFigure(kingFigure));

            var pawnPlayer = new Player("pawn");
            kingPlayer.AddFigure(new MoveableFigure(pawnA));
            kingPlayer.AddFigure(new MoveableFigure(pawnB));
            kingPlayer.AddFigure(new MoveableFigure(pawnC));
            kingPlayer.AddFigure(new MoveableFigure(pawnD));
            var players = new List<IPlayer>()
            {
                               kingPlayer,
                               pawnPlayer
            };

            var gameEngine = new KingSurvivalEngine(
                mockedRenderer.Object,
                mockedInput.Object,
                board,
                new WinningConditions(),
                players,
                new BoardMemory(),
                new CommandContext(new BoardMemory(), board, new Player("king")),
                new CommandFactory());

            gameEngine.StartGame();
            mockedRenderer.Verify(x => x.PrintMessage(It.Is<string>(y => y.Contains("won"))));
        }