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); }
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(".")); }