private void RunGame() { var game = _gameFactory.NewGame(); while (game.GameIsOver == false) { MakeHumanMove(game); } RenderGameOver(game); }
public void MakeMove(IGame game, bool randomlySelectIfMoreThanOne = true) { if (game.GameIsOver) { throw new GameException($"Unable to make a move because the game is over."); } //we make a copy because its polite to not inadvertantly mess up //someone elses object they pass in (in case of exceptions) var gameCopy = _ticTacToeFactory.NewGame(game.MoveHistory); var moveResults = FindMoveResultsRecursively(gameCopy); var bestMoves = SelectBestMovesForPlayer(moveResults, gameCopy.CurrentPlayer); var moveResult = randomlySelectIfMoreThanOne ? bestMoves.RandomFromListOrDefault(_random) : bestMoves.First(); game.Move(moveResult.MoveMade); }
public void PopulateMoveResponses(IGame game = null) { var moveResponses = _moveEvaluator.FindAllMoves(game ?? _ticTacToeFactory.NewGame()) .Select(a => new MoveResponse() { Board = a.BoardLayout, Outcome = a.MoveResult.GameStateAfterMove, Player = a.Player, Response = a.MoveResult.MoveMade }) .ToList(); _moveRepository.DeleteAllMoveResponses(); _moveRepository.InsertMoveResponses(moveResponses); }