public void Play_PlayerWinsOnTenthTurn_PlayerWins() { // arrange var player1 = CreateFakePlayer(); player1.Take10TurnsAt(BoardPosition.At(1, 1)); var player2 = CreateFakePlayer(); player2.TakeTurn(Arg.Any <IPlayerBoard>()). Returns( BoardPosition.At(0, 0), BoardPosition.At(0, 0), BoardPosition.At(0, 0), BoardPosition.At(0, 0), BoardPosition.At(0, 0), BoardPosition.At(0, 0), BoardPosition.At(0, 0), BoardPosition.At(0, 0), BoardPosition.At(0, 1), BoardPosition.At(0, 2)); var game = new Game(player1, player2); // act game.Play(); // assert Assert.That(game.Result, Is.EqualTo(GameStatus.Player2Wins)); }
public void Information_OutsideBoundary_ReturnsOutsideBoundaryMessage() { // arrange var move = new Move(new FakeBoard(), new FakePlayer(), BoardPosition.At(1, 2), MoveResult.OutsideBoardBoundary, moveNumber: 1); // act var output = move.Information(); // assert Assert.That(output, Is.EqualTo("Position is outside board")); }
public void MoveText_NormalMove_DisplaysMoveNormally() { // arrange var move = new Move(new FakeBoard(), new FakePlayer(), BoardPosition.At(1, 2), MoveResult.ValidMove, moveNumber: 1); // act var output = move.MoveText(); // assert Assert.That(output, Is.EqualTo("FakePlayer plays at [1,2]")); }
public void Information_PositionTaken_ReturnsPositionTakenMessage() { // arrange var move = new Move(new FakeBoard(), new FakePlayer(), BoardPosition.At(1, 2), MoveResult.PositionTaken, moveNumber: 1); // act var output = move.Information(); // assert Assert.That(output, Is.EqualTo("Position already taken")); }
public void Information_NormalMove_NoInformation() { // arrange var move = new Move(new FakeBoard(), new FakePlayer(), BoardPosition.At(1, 2), MoveResult.ValidMove, moveNumber: 1); // act var output = move.Information(); // assert Assert.That(output, Is.EqualTo(string.Empty)); }
public void MoveText_Exception_DisplaysFailedMove() { // arrange var move = new Move(new FakeBoard(), new FakePlayer(), BoardPosition.At(1, 2), MoveResult.Exception, 0, "Problems!!"); // act var output = move.MoveText(); // assert Assert.That(output, Is.EqualTo("FakePlayer failed to play")); }
public void MoveText_OutsideBoundary_DisplaysMoveNormally() { // arrange var move = new Move(new FakeBoard(), new FakePlayer(), BoardPosition.At(3, 4), MoveResult.OutsideBoardBoundary); // act var output = move.MoveText(); // assert Assert.That(output, Is.EqualTo("FakePlayer plays at [3,4]")); }
public void Information_Exception_DisplaysException() { // arrange var move = new Move(new FakeBoard(), new FakePlayer(), BoardPosition.At(1, 2), MoveResult.Exception, 0, "Problems!!"); // act var output = move.Information(); // assert Assert.That(output, Is.EqualTo("Exception: Problems!!")); }
public void Information_Timeout_DisplaysTimeoutMessage() { // arrange var move = new Move(new FakeBoard(), new FakePlayer(), BoardPosition.At(1, 2), MoveResult.Timeout); // act var output = move.Information(); // assert Assert.That(output, Is.EqualTo("Move timed out")); }
public BoardPosition TakeTurn(IPlayerBoard board) { // let's see if anyone's played at 0,0... if (board.TokenAt(BoardPosition.At(0, 0)) == PlayerToken.None) { // No? Sweet! Let's play there. return(BoardPosition.At(0, 0)); } // Sod it, I'm going to play there anyway.. return(BoardPosition.At(0, 0)); }
public void PlayTurn_PlayerTakesAges_MoveNotAccepted() { // arrange var player1 = CreateFakePlayerWhichTakesAgesToPlay(BoardPosition.At(2, 2)); var player2 = CreateFakePlayer(); var game = new Game(player1, player2); // act game.PlayTurn(); // assert Assert.That(game.Moves[0].Board.TokenAt(BoardPosition.At(2, 2)) != GameToken.Player1); }
public void PlayTurn_PlayerTakesAges_MoveResultSetToTimeout() { // arrange var player1 = CreateFakePlayerWhichTakesAgesToPlay(BoardPosition.At(2, 2)); var player2 = CreateFakePlayer(); var game = new Game(player1, player2); // act game.PlayTurn(); // assert Assert.That(game.Moves[0].Result, Is.EqualTo(MoveResult.Timeout)); }
public void PlayTurn_Called_PlayerGetsPersonalCopyOfBoard() { // arrange var player1 = CreateFakePlayer(); player1.TakeTurn(Arg.Any <IPlayerBoard>()).Returns(new BoardPosition(1, 1)); var player2 = CreateFakePlayer(); var game = new Game(player1, player2); // act game.PlayTurn(); // assert player2.Received().TakeTurn(Arg.Is <PlayerBoard>(x => x.TokenAt(BoardPosition.At(1, 1)) == PlayerToken.Opponent)); }
private static bool EmptySpacesExist(CrossesBoard board) { for (int rowIndex = 0; rowIndex < CrossesBoard.BOARD_SIZE; rowIndex++) { for (int columnIndex = 0; columnIndex < CrossesBoard.BOARD_SIZE; columnIndex++) { if (board.TokenAt(BoardPosition.At(columnIndex, rowIndex)) == GameToken.None) { return(true); } } } return(false); }
public void Play_GameStillRunningAfter10Rounds_GameMessageSet() { // arrange var player1 = CreateFakePlayer(); player1.Take10TurnsAt(BoardPosition.At(1, 1)); var player2 = CreateFakePlayer(); player2.Take10TurnsAt(BoardPosition.At(1, 1)); var game = new Game(player1, player2); // act game.Play(); // assert Assert.That(game.Message, Is.EqualTo("Game stopped after 10 rounds")); }
public void Play_GameStillRunningAfter10Rounds_DeclaredADraw() { // arrange var player1 = CreateFakePlayer(); player1.Take10TurnsAt(BoardPosition.At(1, 1)); var player2 = CreateFakePlayer(); player2.Take10TurnsAt(BoardPosition.At(1, 1)); var game = new Game(player1, player2); // act game.Play(); // assert Assert.That(game.Result, Is.EqualTo(GameStatus.Draw)); }
public IPlayerBoard For(GameToken player) { var playerTokenFor = new Dictionary <GameToken, PlayerToken> { { GameToken.Player1, player == GameToken.Player1 ? PlayerToken.Me : PlayerToken.Opponent }, { GameToken.Player2, player == GameToken.Player2 ? PlayerToken.Me : PlayerToken.Opponent }, { GameToken.None, PlayerToken.None } }; PlayerBoard boardForPlayer = new PlayerBoard(); for (int columns = 0; columns < BOARD_SIZE; columns++) { for (int rows = 0; rows < BOARD_SIZE; rows++) { var gameToken = _board[columns, rows]; boardForPlayer.SetToken(playerTokenFor[gameToken], BoardPosition.At(columns, rows)); } } return(boardForPlayer); }
public BoardPosition TakeTurn(IPlayerBoard board) { Console.WriteLine("************** I'm a ChattyBot, hear me ROAR! ************"); return(BoardPosition.At(2, 2)); }
public BoardPosition TakeTurn(IPlayerBoard board) { return(BoardPosition.At(0, 0)); }