예제 #1
0
        public static void Go(string botName, int numThreads)
        {
            var opponents = BotFactory.Names.Where(o => o.Equals(botName, StringComparison.OrdinalIgnoreCase) == false).ToList();

            opponents.Add(AIBotIdentifier);
            Console.WriteLine(botName + " opponents: " + opponents.JoinStrings(", "));


            if (numThreads == 1)
            {
                int gameNum = 0;
                while (true)
                {
                    foreach (var opp in opponents.OrderByRandom())
                    {
                        PlayGame(botName, opp, 0, gameNum++);
                    }
                }
            }
            else
            {
                AILog.DoLog = l => l == "Speeds";

                var threads = Enumerable.Range(0, numThreads).Select(threadNum => new Thread(() =>
                {
                    Thread.Sleep(100 * threadNum); //stagger them
                    int gameNum = 0;
                    while (true)
                    {
                        try
                        {
                            foreach (var opp in opponents.OrderByRandom())
                            {
                                PlayGame(botName, opp, threadNum, gameNum++);
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("Thread failed: " + ex);
                        }
                    }
                })).ToList();

                threads.ForEach(o => o.Start());

                while (true)
                {
                    Thread.Sleep(30000);
                    EntryPoint.LogSpeeds();
                }
            }
        }
예제 #2
0
        public static void Go(string[] args)
        {
            var botName    = args[0];
            var numThreads = args.Length > 1 ? int.Parse(args[1]) : 1;

            AILog.DoLog = log => log == "Speeds";

            if (numThreads == 1)
            {
                while (true)
                {
                    PlayGame(botName);
                    EntryPoint.LogSpeeds();
                }
            }
            else
            {
                var threads = Enumerable.Range(0, numThreads).Select(o => new Thread(() =>
                {
                    try
                    {
                        while (true)
                        {
                            PlayGame(botName);
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Thread failed: " + ex);
                    }
                })).ToList();

                threads.ForEach(o => o.Start());

                while (true)
                {
                    Thread.Sleep(30000);
                    EntryPoint.LogSpeeds();
                }
            }
        }