コード例 #1
0
ファイル: TicTacToeExample.cs プロジェクト: play3577/SharpRL
        /// <summary>
        /// Runs the example
        /// </summary>
        public static void Run()
        {
            int trainingEpisodes = 100000;
            var environment      = new BoardEnvironment(new Configuration(trainingEpisodes, new Random(1337)));

            var agent = new BoardAgent(BoardTileType.Cross);

            environment.AddAgent(agent);
            environment.TrainingStrategy = new MinimaxStrategy();
            environment.Initialize();

            //Train
            var startTime = DateTime.UtcNow;

            Simulate(environment, environment.Config.MaxEpisodes);
            Console.WriteLine("Training time: " + (DateTime.UtcNow - startTime));

            //Game
            environment.ResetScores();
            agent.Learner.FollowPolicy = true;

            int gameEpisodes = 300;

            Simulate(environment, gameEpisodes);

            Func <int, double> winRaito = wins => ((double)wins / gameEpisodes) * 100;

            Console.WriteLine("Cross wins: " + environment.CrossWins + " (" + winRaito(environment.CrossWins) + "%)");
            Console.WriteLine("Circle wins: " + environment.CircleWins + " (" + winRaito(environment.CircleWins) + "%)");
            Console.WriteLine("Ties: " + environment.Ties + " (" + winRaito(environment.Ties) + "%)");

            Console.ReadLine();
        }
コード例 #2
0
ファイル: TicTacToeExample.cs プロジェクト: play3577/SharpRL
        /// <summary>
        /// Simulates the environment for the given amount of episodes
        /// </summary>
        /// <param name="environment">The environment</param>
        /// <param name="episodes">The number of episodes</param>
        private static void Simulate(BoardEnvironment environment, int episodes)
        {
            for (int episode = 0; episode < episodes; episode++)
            {
                environment.Reset(episode);

                while (true)
                {
                    if (environment.Update(episode))
                    {
                        break;
                    }
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// Trains the environment
        /// </summary>
        /// <param name="environment">The environment</param>
        private void Train(BoardEnvironment environment)
        {
            for (int episode = 0; episode < environment.Config.MaxEpisodes; episode++)
            {
                environment.Reset(episode);

                while (true)
                {
                    if (environment.Update(episode))
                    {
                        break;
                    }
                }
            }
        }