예제 #1
0
        private bool MoveNext(Game.TickTackToe game)
        {
            var status = game.GetStatus();
            var move   = status.Player == Player.Player0 ? _player0.GetNextMove(status) : _player1.GetNextMove(status);

            var moveResult = game.Move(status.Player, move.X, move.Y);

            Moves.Add(new ExecutedMove(status, move, moveResult));

            status = game.GetStatus();
            return(status.GameStatus == GameStatus.InGame);
        }
예제 #2
0
        private TimeboxedTrainingResult TrainEpisode()
        {
            var game          = new Game.TickTackToe(_startPlayerDeterminer);
            var currentStatus = game.GetStatus();

            while (currentStatus.GameStatus == GameStatus.InGame)
            {
                var currentTrainer = currentStatus.Player == Player.Player0 ? _agent0 : _agent1;
                var otherTrainer   = currentStatus.Player == Player.Player0 ? _agent1 : _agent0;
                var move           = MeasureExecutionTimeAndStopAtMaxTime(currentTrainer.Player, () => currentTrainer.GetNextMove(currentStatus));

                if (move == null)
                {
                    return(currentStatus.Player == Player.Player0
                        ? TimeboxedTrainingResult.Agent0TookTooLong
                        : TimeboxedTrainingResult.Agent1TookTooLong);
                }

                var moveResult = game.Move(currentStatus.Player, move.X, move.Y);

                var oldStatus = currentStatus;
                currentStatus = game.GetStatus();

                var inTime = MeasureExecutionTimeAndStopAtMaxTime(currentTrainer.Player, () => currentTrainer.Observe(oldStatus, currentStatus, moveResult, move));
                if (!inTime)
                {
                    return(currentTrainer.Player == Player.Player0
                        ? TimeboxedTrainingResult.Agent0TookTooLong
                        : TimeboxedTrainingResult.Agent1TookTooLong);
                }

                inTime = MeasureExecutionTimeAndStopAtMaxTime(otherTrainer.Player, () => otherTrainer.Observe(oldStatus, currentStatus, moveResult, move));
                if (!inTime)
                {
                    return(otherTrainer.Player == Player.Player0
                        ? TimeboxedTrainingResult.Agent0TookTooLong
                        : TimeboxedTrainingResult.Agent1TookTooLong);
                }
            }

            return(TimeboxedTrainingResult.Done);
        }
예제 #3
0
        private void TrainEpisode()
        {
            var game          = new Game.TickTackToe(_startPlayerDeterminer);
            var currentStatus = game.GetStatus();

            while (currentStatus.GameStatus == GameStatus.InGame)
            {
                var currentAgent = currentStatus.Player == Player.Player0 ? _agent0 : _agent1;
                var otherAgent   = currentStatus.Player == Player.Player0 ? _agent1 : _agent0;
                var move         = currentAgent.GetNextMove(currentStatus);

                var moveResult = game.Move(currentStatus.Player, move.X, move.Y);

                var oldStatus = currentStatus;
                currentStatus = game.GetStatus();

                currentAgent.Observe(oldStatus, currentStatus, moveResult, move);
                otherAgent.Observe(oldStatus, currentStatus, moveResult, move);
            }
        }
예제 #4
0
        public Status RunGame()
        {
            var game = new Game.TickTackToe(_startPlayerDeterminer);

            Moves = new List <ExecutedMove>();
            bool canContinue;

            do
            {
                canContinue = MoveNext(game);
            } while (canContinue);

            return(game.GetStatus());
        }