예제 #1
0
파일: UI.cs 프로젝트: softpsyche/TicTacToe
        private void RunGame()
        {
            var game = _gameFactory.NewGame();

            while (game.GameIsOver == false)
            {
                MakeHumanMove(game);
            }

            RenderGameOver(game);
        }
예제 #2
0
        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);
        }
예제 #3
0
        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);
        }