public void WhenUserEntersValidMove_ThenMoveIsSetCoordinates_a1_is_00() { HumanPlayer userMove = new HumanPlayer(null); userMove.Input = "a2"; Assert.AreEqual(1, userMove.MoveCoordinatesX); // 2-->1 Assert.AreEqual(0, userMove.MoveCoordinatesY); // a-->0 }
public void DoMoveTest_WhenExitIsEntered_ThenConstEXITIsReturned() { var reader = new InputReaderFake(); reader.SetUserInput("exit"); var target = new HumanPlayer(reader); int retValue = target.DoMove(Piece.X, null); Assert.AreEqual(-100, retValue); }
public TicTacToeGame(TicTacToeObjects ticTacToeObjects) { _inputReader = ticTacToeObjects.InputReader; _boardState = ticTacToeObjects.BoardState; _humanPlayer = ticTacToeObjects.HumanPlayer; _computerPlayer = ticTacToeObjects.ComputerPlayer; _pieceManager = ticTacToeObjects.PieceManager; }
public void DoMoveTest_WhenAnIllegalMoveIsEntered_ThenUserMustEnterALegalMove() { var reader = new InputReaderFake(); reader.SetUserInput("a2"); reader.SetUserInput("a2"); reader.SetUserInput("a1"); var target = new HumanPlayer(reader); var boardState = new BoardState(null); var board = new Piece[3, 3]; board[0, 0] = Piece.Empty; board[1, 0] = Piece.X; board[2, 0] = Piece.Empty; board[0, 1] = Piece.Empty; board[1, 1] = Piece.Empty; board[2, 1] = Piece.Empty; board[0, 2] = Piece.Empty; board[1, 2] = Piece.Empty; board[2, 2] = Piece.Empty; boardState.Board = board; int retValue = target.DoMove(Piece.O, boardState); Assert.AreEqual(0, retValue); Assert.AreEqual(Piece.O, boardState.GetPiece(0, 0)); }
//Starts a new game of tic tac toe. //Creates/resets the gameboard and keeps track of scores. public bool nextRound() { bool donePlaying = false; //Setup Board if (gameBoard == null) gameBoard = new GameBoard(); else gameBoard.resetBoard(); //Only Human players atm for (int i = 0; i < numPlayers; i++) { playerList[i] = new HumanPlayer(gameBoard); } do { playGame(); Console.WriteLine("Play Another? (y/n)"); if (Console.ReadLine().Equals("y")) { donePlaying = false; gameBoard.resetBoard(); } else { donePlaying = true; } } while (!donePlaying); return donePlaying; }
} //end GameBoardTests public bool humanPlayerTests() { bool result = true; bool doneTesting = false; GameBoard gameBoard = new GameBoard(); Player player1 = new HumanPlayer(gameBoard); while (!doneTesting) { player1.takeTurn(); gameBoard.printBoard(); Console.WriteLine("Continue testing Human input? (y/n)"); if (Console.ReadLine().Equals("n")) { doneTesting = true; } } return result; }
void SetupGame() { Player p1 = new HumanPlayer("Joe", Board.Pieces.X); // Create a computer player // You can create varying degrees of difficulty by creating computer // players that build bigger game trees // uncomment desired player and comment all other player 2s // create a computer player with the default game tree search depth Player p2 = new ComputerPlayer("HAL", Board.Pieces.O); // Create a computer player that only looks ahead 1 move // i.e only considers their immediate move and not any subsequent moves // by their opponent. // this is a very poor player // Player p2 = new ComputerPlayer(Board.Pieces.X, f, 1); // Creates an advanced computer player that looks ahead 5 moves // Player p2 = new ComputerPlayer("Advanced HAL", Board.Pieces.X, 5); AddPlayer(p1); AddPlayer(p2); }
public void WhenUserEntersValidMove_ThenMoveIsSetValid() { HumanPlayer userMove = new HumanPlayer(null); userMove.Input = "a2"; Assert.AreEqual(true, userMove.IsInputValid()); }
public void WhenUserEntersInvalidMove_ThenMoveIsSetToInvalid() { HumanPlayer userMove = new HumanPlayer(null); userMove.Input = "h3"; Assert.AreEqual(false, userMove.IsInputValid()); }
public void WhenUserEntersExit_ThenGameIsFinished() { HumanPlayer userMove = new HumanPlayer(null); userMove.Input = "Exit"; Assert.AreEqual(true, userMove.IsFinished()); }