static void Main(string[] args) { Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; int minMapPlayersCount = 1; int maxMapPlayersCount = 8; int roundsCount = 100000; bool failOnExceptions = false; //var ais = AiFactoryRegistry.ForOnlineRunsFactories var ais = new List <AiFactory>() { new AiFactory("final ai", CreateAi), AiFactoryRegistry.CreateFactory <AntiLochDinicKillerAi_0>(), AiFactoryRegistry.CreateFactory <AntiLochDinicKillerAi_01>(), AiFactoryRegistry.CreateFactory <FutureIsNowAi>(), AiFactoryRegistry.CreateFactory <LochDinicKillerAi>(), AiFactoryRegistry.CreateFactory <OptAntiLochDinicKillerAi>(), AiFactoryRegistry.CreateFactory <LochMaxVertexWeighterKillerAi>(), AiFactoryRegistry.CreateFactory <AllComponentsMaxReachableVertexWeightAi>(), AiFactoryRegistry.CreateFactory <MaxReachableVertexWeightAi>(), AiFactoryRegistry.CreateFactory <ConnectClosestMinesAi>(), AiFactoryRegistry.CreateFactory <GreedyAi>(), AiFactoryRegistry.CreateFactory <RandomEWAi>(), AiFactoryRegistry.CreateFactory <TheUberfullessnessAi>(), } .Select(f => new PlayerTournamentResult(f)).ToList(); var maps = MapLoader.LoadOnlineMaps() .Where(map => map.PlayersCount.InRange(minMapPlayersCount, maxMapPlayersCount)) //.Where(map => map.Name == "boston-sparse") .ToList(); for (int i = 0; i < roundsCount; i++) { foreach (var map in maps) { var matchPlayers = ais.Shuffle(random).Repeat().Take(map.PlayersCount).ToList(); var gameSimulator = new GameSimulatorRunner(new SimpleScoreCalculator(), true, !failOnExceptions); var gamers = matchPlayers.Select(p => p.Factory.Create()).ToList(); var results = gameSimulator.SimulateGame(gamers, map.Map, new Settings(true, true, true)); AssignMatchScores(results); foreach (var res in results) { int index = gamers.IndexOf(res.Gamer); var player = matchPlayers[index]; player.GamesPlayed++; player.OptionUsageRate.Add(res.OptionsUsed); player.NormalizedMatchScores.Add((double)res.MatchScore / matchPlayers.Count); player.GamesWon.Add(res.MatchScore == matchPlayers.Count ? 1 : 0); if (res.LastException != null) { player.ExceptionsCount++; } if (res.ScoreData.PossibleFuturesScore != 0) { player.GainFuturesScoreRate.Add((double)res.ScoreData.GainedFuturesScore / res.ScoreData.PossibleFuturesScore); } if (res.ScoreData.TotalFuturesCount != 0) { player.GainFuturesCountRate.Add((double)res.ScoreData.GainedFuturesCount / res.ScoreData.TotalFuturesCount); } player.TurnTime.AddAll(res.TurnTime); } ShowStatus(ais, maps); } } }
public static bool TryCompeteOnArena(string collectorId, string commitHash = "manualRun") { var portLocker = new PortLocker(); var match = ArenaMatch.EmptyMatch; try { var sw = Stopwatch.StartNew(); IAi ai; IServerInteraction interaction; lock (Locker) { var isPortOpen = false; do { match = GetNextMatch(); if (match == null) { Thread.Sleep(5000); log.Warn($"Collector {collectorId}: No matches found, sleeping 5 seconds..."); continue; } isPortOpen = portLocker.TryAcquire(match.Port); if (!isPortOpen) { log.Warn($"Collector {collectorId}: {match.Port} taken"); } } while (!isPortOpen); log.Info($"Collector {collectorId}: Take {match.Port}"); ai = AiFactoryRegistry.GetNextAi(true); log.Info($"Collector {collectorId}: Match on port {match.Port} for {GetBotName(ai.Name)}"); try { interaction = new OnlineInteraction(match.Port, GetBotName(ai.Name)); } catch (SocketException e) { log.Error(e); portLocker.Free(match.Port); return(false); } if (!interaction.Start()) { portLocker.Free(match.Port); return(false); } } log.Info($"Collector {collectorId}: Running game on port {match.Port}"); var metaAndData = interaction.RunGame(ai); metaAndData.Item1.CommitHash = commitHash; Repo.SaveReplay(metaAndData.Item1, metaAndData.Item2); log.Info($"Collector {collectorId}: Saved replay {metaAndData.Item1.Scores.ToDelimitedString(", ")}"); log.Info($"Collector {collectorId}: Elapsed {sw.ElapsedMilliseconds}"); } catch (Exception e) { log.Error(e, $"Collector {collectorId} failed: {e}"); } portLocker.Free(match.Port); return(true); }