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 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")))); }
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 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)); }