public void TestAllMaps() { var maps = MapLoader.LoadDefaultMaps().OrderBy(m => m.Map.Rivers.Length).ToList(); foreach (var map in maps) { var gamers = new List <IAi> { new GreedyAi(), }; var gameSimulator = new GameSimulatorRunner(new SimpleScoreCalculator()); Console.WriteLine($"MAP: {map.Name}"); var results = gameSimulator.SimulateGame( gamers, map.Map, new Settings()); foreach (var gameSimulationResult in results) { Console.Write($"{gameSimulationResult.Gamer.Name} "); } Console.WriteLine(); foreach (var gameSimulationResult in results) { Console.Write($"{gameSimulationResult.Score} "); } Console.WriteLine(); Console.Out.Flush(); } }
public void Test1() { var gamers = new List <IAi> { new LochDinicKillerAi(), new LochDinicKillerAi(), new LochDinicKillerAi(), new OptAntiLochDinicKillerAi() }; var gameSimulator = new GameSimulatorRunner(new SimpleScoreCalculator()); var results = gameSimulator.SimulateGame( gamers, MapLoader.LoadMapByName("lambda.json").Map, new Settings()); foreach (var gameSimulationResult in results) { Console.Out.WriteLine( "gameSimulationResult = {0}:{1}", gameSimulationResult.Gamer.Name, gameSimulationResult.Score); } }
public void Check(AiFactory factory) { var gamers = new List <IAi> { factory.Create(), factory.Create() }; var gameSimulator = new GameSimulatorRunner(new SimpleScoreCalculator()); var results = gameSimulator.SimulateGame( gamers, MapLoader.LoadMapByName(MapName).Map, new Settings()); foreach (var gameSimulationResult in results) { Console.Out.WriteLine( "gameSimulationResult = {0}:{1}", gameSimulationResult.Gamer.Name, gameSimulationResult.Score); } }
public void Test1() { var gamers = new List <IAi> { new CrazyAi(), new ConnectClosestMinesAi() }; var gameSimulator = new GameSimulatorRunner(new SimpleScoreCalculator()); var results = gameSimulator.SimulateGame( gamers, MapLoader.LoadMapByName("edge.json").Map, new Settings()); foreach (var gameSimulationResult in results) { Console.Out.WriteLine( "gameSimulationResult = {0}:{1}", gameSimulationResult.Gamer.Name, gameSimulationResult.Score); } }
static void Main2(string[] args) { if (args[0] == @"\merge") { if (args.Length == 1) { Merge(Environment.CurrentDirectory); } else { Merge(args[1]); } return; } Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; int minMapPlayersCount = 2; int maxMapPlayersCount = int.Parse(args[0]); int roundsCount = int.Parse(args[1]); bool failOnExceptions = true; //var ais = AiFactoryRegistry.ForOnlineRunsFactories var ais = UberfullessnessAi.All.Select(x => new AiFactory(x.Name, () => x)).ToList() //var ais = new List<AiFactory>() //{ //AiFactoryRegistry.CreateFactory<OptAntiLochDinicKillerAi>(), //AiFactoryRegistry.CreateFactory<AntiLochDinicKillerAi_0>(), //AiFactoryRegistry.CreateFactory<AntiLochDinicKillerAi_005>(), //AiFactoryRegistry.CreateFactory<AntiLochDinicKillerAi_01>(), //AiFactoryRegistry.CreateFactory<AntiLochDinicKillerAi_02>(), //AiFactoryRegistry.CreateFactory<AntiLochDinicKillerAi_03>(), //AiFactoryRegistry.CreateFactory<AntiLochDinicKillerAi_04>(), //AiFactoryRegistry.CreateFactory<AntiLochDinicKillerAi_05>(), //AiFactoryRegistry.CreateFactory<AntiLochDinicKillerAi_1>(), //AiFactoryRegistry.CreateFactory<FutureIsNowAi>(), //AiFactoryRegistry.CreateFactory<ConnectClosestMinesAi>(), //AiFactoryRegistry.CreateFactory<AntiLochDinicKillerAi>(), //AiFactoryRegistry.CreateFactory<LochDinicKillerAi>(), //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") .Where(map => args.Length == 2 || args.Contains(map.Name)) .ToList(); var r = Enumerable.Range(0, roundsCount) .AsParallel() .Select(i => { return(maps .AsParallel() .Select(map => { var matchPlayers = ais.Select(a => a.Clone()).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.Maps.Add(map.Name); 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); } return matchPlayers; }) .Aggregate(new List <PlayerTournamentResult>(), (l, d) => { l.AddRange(d); return l; })); }) .Aggregate(new List <PlayerTournamentResult>(), (l, d) => { l.AddRange(d); return(l); }); r = PlayerTournamentResult.Merge(r).ToList(); ShowStatus(r, maps.Select(m => m.Name).ToList()); File.WriteAllText($"{Guid.NewGuid()}.json", JsonConvert.SerializeObject(r), Encoding.UTF8); }
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); } } }