Esempio n. 1
0
 public void CheckIfCheckFigureOnTheWayWorksProperlyWhenFigureIsOnTheWay()
 {
     var board = new Board();
     var figure = new KingFigure();
     var position = new Position(1, 1);
     board.AddFigure(figure, position);
     Validator.CheckIfFigureOnTheWay(position, board, "Figure on the way");
 }
Esempio n. 2
0
        public void CheckfAddFigureMethodThrowsWhenPositionIsNotValid()
        {
            var board = new Board();
            var position = new Position(9, 9);
            IFigure king = new KingFigure();

            board.AddFigure(king, position);
        }
Esempio n. 3
0
 public void CheckIfAFigureIsAddedCorrectlyToTheBoard()
 {
     var board = new Board();
     var position = new Position(1, 1);
     var figure = new KingFigure();
     board.AddFigure(figure, position);
     Assert.AreEqual(figure, board.GetFigureAtPosition(position));
 }
Esempio n. 4
0
 public void CheckIfCheckFigureOnTheWayWorksProperlyWhenFigureIsOnTheWay()
 {
     IFigure king = new KingFigure("K");
     var position = new Position(Constants.InitialKingRow, Constants.InitialKingColumn);
     var board = new Board();
     board.AddFigure(king, position);
     Validator.CheckIfFigureOnTheWay(position, board);
 }
Esempio n. 5
0
        public void CheckIfGetFigureAtPositionWorkCorrectly()
        {
            var board = new Board();
            var figure = new KingFigure();
            board.AddFigure(figure, new Position(1, 1));
            var realFigure = board.GetFigureAtPosition(new Position(1, 1));

            Assert.AreEqual(figure, realFigure);
        }
Esempio n. 6
0
        public void CheckIfGetFigureAtPositionReturnsTheCorrectFigure()
        {
            var board = new Board();
            var position = new Position(1, 1);
            var figure = new KingFigure();
            board.AddFigure(figure, position);

            Assert.AreEqual(figure, board.GetFigureAtPosition(position));
        }
Esempio n. 7
0
        public void CheckIfAddFigureWorksCorrectlyWithCorrectFigureAndCorrectPosition()
        {
            var board = new Board();
            var position = new Position(3, 7);
            IFigure king = new KingFigure();

            board.AddFigure(king, position);
            Assert.AreSame(king, board.GetFigureAtPosition(position));
        }
Esempio n. 8
0
 public void CheckIfCheckFigureOnTheWayWorksProperlyWhenNoFigureOnTheWay()
 {
     IFigure king = new KingFigure("K");
     var board = new Board();
     var position = new Position(1, 1);
     board.AddFigure(king, position);
     var expectedPosition = new Position(2, 2);
     Validator.CheckIfFigureOnTheWay(expectedPosition, board);
 }
Esempio n. 9
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");
        }
Esempio n. 10
0
        public void ExecuteMoveCommandShouldThrowExceptionWhenKingIsTryingToExecuteBdr()
        {
            IFigure figure = new KingFigure("K");
            var position = new Position(3, 6);
            var boardMock = new Mock<IBoard>();
            boardMock.SetupGet(x => x.NumberOfColumns).Returns(8);
            boardMock.SetupGet(x => x.NumberOfRows).Returns(8);
            var figures = new Dictionary<string, IMoveableFigure>();
            figures.Add(figure.DisplaySign, new MoveableFigure(figure));
            var playerMock = new Mock<IPlayer>();
            playerMock.SetupGet(x => x.Figures).Returns(figures);
            var memoryMock = new Mock<BoardMemory>();
            Mock<ICommandContext> mockContext = new Mock<ICommandContext>();
            mockContext.SetupGet(b => b.Board).Returns(boardMock.Object);
            mockContext.SetupGet(p => p.Player).Returns(playerMock.Object);
            mockContext.SetupGet(p => p.Memory).Returns(memoryMock.Object);

            var pawnCommand = new PawnBDownLeftCommand();
            pawnCommand.Execute(mockContext.Object);
        }
Esempio n. 11
0
        public void ExecuteMoveCommandShouldWorkCorrectlyWhenTheCommandIsCorrect()
        {
            IFigure figure = new KingFigure("K");
            IPosition position = new Position(7, 3);
            IBoard board = new Board(8, 8);

            board.AddFigure(figure, position);
            var figures = new Dictionary<string, IMoveableFigure>();
            figures.Add(figure.DisplaySign, new MoveableFigure(figure));
            var playerMock = new Mock<IPlayer>();
            playerMock.SetupGet(x => x.Figures).Returns(figures);

            var memoryMock = new Mock<BoardMemory>();
            Mock<ICommandContext> mockContext = new Mock<ICommandContext>();
            mockContext.SetupGet(b => b.Board).Returns(board);
            mockContext.SetupGet(p => p.Player).Returns(playerMock.Object);
            mockContext.SetupGet(p => p.Memory).Returns(memoryMock.Object);

            var kingCommand = new KingUpRightCommand();
            kingCommand.Execute(mockContext.Object);
        }
        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);
        }
        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);
        }
        private void CreateFigures()
        {
            KingFigure kingFigure = new KingFigure();
            this.Board.AddFigure(kingFigure, new Position(Constants.InitialKingRow, Constants.InitialKingColumn));

            PawnAFigure pawnA = new PawnAFigure();
            this.Board.AddFigure(pawnA, new Position(Constants.PawnAInitialRow, Constants.PawnAInitialCol));

            PawnBFigure pawnB = new PawnBFigure();
            this.Board.AddFigure(pawnB, new Position(Constants.PawnBInitialRow, Constants.PawnBInitialCol));

            PawnCFigure pawnC = new PawnCFigure();
            this.Board.AddFigure(pawnC, new Position(Constants.PawnCInitialRow, Constants.PawnCInitialCol));

            PawnDFigure pawnD = new PawnDFigure();
            this.Board.AddFigure(pawnD, new Position(Constants.PawnDInitialRow, Constants.PawnDInitialCol));

            this.kingPlayer.AddFigure(kingFigure);

            this.pawnPlayer.AddFigure(pawnA);
            this.pawnPlayer.AddFigure(pawnB);
            this.pawnPlayer.AddFigure(pawnC);
            this.pawnPlayer.AddFigure(pawnD);
        }
Esempio n. 15
0
        public void CheckIfTheRemoveFigureMethodThrowsCorrectlyIndexOutOfRangeException()
        {
            var board = new Board();
            var position = new Position(9, 9);
            var figure = new KingFigure();

            board.RemoveFigure(figure, position);
        }
Esempio n. 16
0
 public void CheckIfSaveMementoSavesBoardCorrectly()
 {
     var board = new Board();
     var figure = new KingFigure();
     board.AddFigure(figure, new Position(1, 1));
     var actual = board.SaveMemento();
     Assert.AreEqual(actual.Board.GetLength(1), board.NumberOfColumns);
 }
Esempio n. 17
0
 public void CheckIfGetFigurePositionRowWorksCorrectlyWhenCorrectInput()
 {
     var board = new Board();
     var figure = new KingFigure();
     board.AddFigure(figure, new Position(1, 1));
     var actualPosition = board.GetFigurePosition(figure);
     var expectedPosition = new Position(1, 1);
     Assert.AreEqual(expectedPosition.Row, actualPosition.Row);
 }
Esempio n. 18
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");
        }
Esempio n. 19
0
 public void CheckIfRestoreMementoRestoresBoardCorrectly()
 {
     var board = new Board();
     var figure = new KingFigure();
     board.AddFigure(figure, new Position(1, 1));
     var memento = board.SaveMemento();
     board.RestoreMemento(memento);
     Assert.AreEqual(memento.Board.GetLength(1), board.NumberOfColumns);
 }
Esempio n. 20
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"))));
        }
        private void CreatePlayerFigures()
        {
            IFigure kingFigure = new KingFigure("K");
            this.Board.AddFigure(kingFigure, new Position(Constants.InitialKingRow, Constants.InitialKingColumn));

            PawnFigure pawnA = new PawnFigure(Constants.FirstPawnDisplaySign);
            this.Board.AddFigure(pawnA, new Position(Constants.PawnAInitialRow, Constants.PawnAInitialCol));

            PawnFigure pawnB = new PawnFigure(Constants.SecondPawnDisplaySign);
            this.Board.AddFigure(pawnB, new Position(Constants.PawnBInitialRow, Constants.PawnBInitialCol));

            PawnFigure pawnC = new PawnFigure(Constants.ThirdPawnDisplaySign);
            this.Board.AddFigure(pawnC, new Position(Constants.PawnCInitialRow, Constants.PawnCInitialCol));

            PawnFigure pawnD = new PawnFigure(Constants.FourthPawnDisplaySign);
            this.Board.AddFigure(pawnD, new Position(Constants.PawnDInitialRow, Constants.PawnDInitialCol));

            this.kingPlayer.AddFigure(new MoveableFigure(kingFigure));

            this.pawnPlayer.AddFigure(new MoveableFigure(pawnA));
            this.pawnPlayer.AddFigure(new MoveableFigure(pawnB));
            this.pawnPlayer.AddFigure(new MoveableFigure(pawnC));
            this.pawnPlayer.AddFigure(new MoveableFigure(pawnD));
        }
Esempio n. 23
0
        public void CheckIfRemoveFigureRemovesTheFigure()
        {
            var board = new Board();
            var position = new Position(1, 1);
            var figure = new KingFigure();
            board.AddFigure(figure, position);
            board.RemoveFigure(figure, position);

            Assert.AreNotEqual(figure, board.GetFigureAtPosition(position));
        }