Example #1
0
        static void Main(string[] args)
        {
            try
            {
                Log("Client started " + args[0]);
                var punterName = args[0];
                var server     = args.Length > 1 ? args[1] : "localhost";
                var port       = args.Length > 2 ? args[2] : "7777";
                var isKonturRu = args.Length > 3;

                if (isKonturRu)
                {
                    var interaction = new OnlineInteraction(int.Parse(port));
                    interaction.Start();
                    interaction.RunGame((IAi)UberfullessnessAi.All.FirstOrDefault(
                                            x => x.Name ==
                                            "FutureIsNowSetupStrategyoptions-FutureIsNowStrategyoptions-ExtendComponentStrategyoptions-SumGreedyStrategyUberAi") ??
                                        new ConnectClosestMinesAi());
                    return;
                }

                var punter = PunterFactory.Create(punterName);
                var client = new OnlineClient(punter);
                client.Start(server, port);
                Console.ReadLine();
            }
            catch (Exception e)
            {
                Log("Error:" + e);
                throw;
            }
        }
Example #2
0
        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);
        }