public void Run() { var board = new Board(); var aiPlayer = new AiPlayer(this._aiMark); Console.Clear(); var winner = RunUntilWin(board, aiPlayer); PrintEndMessage(board, winner); }
public void StartGame(bool withAi) { var player1 = new Player(CellSign.X, turnController); IPlayer player2; if (withAi) { player2 = new AiPlayer(CellSign.O); } else { player2 = new Player(CellSign.O, turnController); } session = new GameSessionManager(player1, player2, GameField.MinFieldSize); fieldController.SetSession(session); session.StartGame(); }
private Mark RunUntilWin(Board board, AiPlayer aiPlayer) { var continueGame = true; Mark?winner = null; while (continueGame) { ReprintBoard(board); winner = board.GetWinner(); if (winner != null) { break; } DoHumanMove(board); ReprintBoard(board); continueGame = aiPlayer.TryMove(board); } return((Mark)(winner ?? Mark.Empty)); }