public void RunGame() { bool exited = false; _boardState.Reset(); _pieceManager.FirstMover = _pieceManager.GetRandomPlayerType(); if (_pieceManager.FirstMover == PlayerType.Computer) { _computerPlayer.DoMove(_pieceManager.GetPiece(PlayerType.Computer), _boardState); } _boardState.PrintBoard(); while (!_boardState.IsFinished()) { exited = _humanPlayer.DoMove(_pieceManager.GetPiece(PlayerType.Human), _boardState) == -100; if (exited) { break; } _computerPlayer.DoMove(_pieceManager.GetPiece(PlayerType.Computer), _boardState); _boardState.PrintBoard(); } if (!exited) { _boardState.PrintWinner(); } }
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 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)); }