Exemplo n.º 1
0
        public static void Main(string[] args)
        {
            var dir = new DirectoryInfo(ConfigurationManager.AppSettings["Bots.Dir"]);

            if (args != null && args.Length > 0)
            {
                dir = new DirectoryInfo(args[0]);
            }

            var arena = new CompetitionRunner(dir);

            try
            {
                arena.GameSettings = Settings.Load(dir);
            }
            // No valid settings, so write them down.
            catch
            {
                arena.GameSettings.Save(dir);
            }
            try
            {
                arena.Bots = Bots.Load(dir);
            }
            catch { }

            while (arena.Run())
            {
            }
        }
        /// <summary>Scans the directory.</summary>
        /// <returns>
        /// Return true if at least two bots are active.
        /// </returns>
        private bool ScanDirectory()
        {
            int active = 0;

            BotLocations.Clear();
            // Disable all.
            foreach (var bot in Bots)
            {
                bot.Info = bot.Info.SetIsActive(true);
            }

            foreach (var dir in RootDirectory.GetDirectories().Where(d => d.Name != "bin" && d.Name != "zips"))
            {
                BotInfo info;
                if (BotInfo.TryCreate(dir, out info))
                {
                    var bot = Bots.GetOrCreate(info);
                    if (!info.Inactive)
                    {
                        BotLocations[bot.Info] = dir;
                        active++;
                    }
                }
            }
            return(active > 1);
        }
        public bool Run()
        {
            if (!ScanDirectory())
            {
                return(false);
            }
            UpdateScreen();
            this.Games++;

            Bot[] pair = Bots.CreatePair(this.Rnd, ArenaConfig.KStabalizer * 1.1);
            this.Player1 = pair[0];
            this.Player2 = pair[1];

            var result = PlayMatch(this.Player1, this.Player2);

            CalculateNewElos(this.Player1, this.Player2, result);

            Bots.Save(ArenaConfig.BotsDirectory);

            return(true);
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            var dir = new DirectoryInfo(ConfigurationManager.AppSettings["Bots.Dir"]);

            if (args != null && args.Length > 0)
            {
                dir = new DirectoryInfo(args[0]);
            }

            var arena = new CompetitionRunner(dir);

            try
            {
                arena.Bots = Bots.Load(new DirectoryInfo("."));
            }
            catch { }

            while (true)
            {
                arena.RunGame();
            }
        }
Exemplo n.º 5
0
        public void RunGame()
        {
            ScanDirectory();

            if (Bots.Count(bot => !bot.Info.Inactive) < 2)
            {
                return;
            }

            Bot player1 = Bots.GetRandom(Rnd);
            Bot player2 = Bots.GetRandom(Rnd);

            while (player1.Equals(player2))
            {
                player2 = Bots.GetRandom(Rnd);
            }

            // Fix standard in and out issues.
            //using (var p1 = Process.Start(BotLocations[player1.Info].GetFiles("*.exe").FirstOrDefault().FullName))
            //{
            //	using (var p2 = Process.Start(BotLocations[player2.Info].GetFiles("*.exe").FirstOrDefault().FullName))
            //	{
            //		var p1Settings = this.GameSettings.Copy(PlayerType.player1);
            //		var p2Settings = this.GameSettings.Copy(PlayerType.player2);

            //		// send instructions.
            //		foreach (var instruction in p1Settings.ToInstructions())
            //		{
            //			p1.StandardInput.WriteLine(instruction);
            //		}
            //		foreach (var instruction in p2Settings.ToInstructions())
            //		{
            //			p2.StandardInput.WriteLine(instruction);
            //		}
            //	}
            //}

            var elo1 = player1.Rating;
            var elo2 = player2.Rating;
            var k1   = player1.K;
            var k2   = player2.K;

            // TODO: run an actual game.
            var rnd1   = Rnd.Next(6);
            var rnd2   = Rnd.Next(6);
            var score1 = 0.0;

            if (rnd1 == rnd2)
            {
                player1.Draws++;
                player2.Draws++;
                score1 = 0.5;
            }
            else if (rnd1 > rnd2)
            {
                player1.Wins++;
                player2.Losses++;
                score1 = 1.0;
            }
            else
            {
                player1.Losses++;
                player2.Wins++;
            }
            var score2 = 1.0 - score1;

            player1.Rating = player1.Rating.GetNew(elo2, score1, k1);
            player2.Rating = player2.Rating.GetNew(elo1, score2, k2);

            player1.K = NewK(k1, k2);
            player2.K = NewK(k2, k1);

            Bots.Save(new DirectoryInfo("."));
        }