Beispiel #1
0
        public static void MonteCarloTreeSearchCompareAITestCheckAll()
        {
            string log = "";

            DateTime start = DateTime.Now;
            int overallWins = 0;
            int overallGames = 0;
            CardSetsModel cardSets = new CardSetsModel(GameSets.Any);
            foreach (CardSetGroup group in cardSets.CardSetGroups)
            {
                foreach (CardSetViewModel cardSet in group.CardSets)
                {
                    Kingdom kingdom = new Kingdom(cardSet.CardSet.CardCollection, null, cardSet.CardSet.BaneCard, GameSets.Any, 2, CardUseType.DoNotUse, CardUseType.DoNotUse, StartingHandType.FourThreeSplit);

                    Console.WriteLine("start train");
                    BuyListTrainer trainer = new BuyListTrainer(kingdom, true);
                    BuyListTrainer.GamesPerMatchup = 4;
                    BuyListTrainer.MaxChallengerCount = 15;
                    BuyListTrainer.MaxLeaderCount = 3;
                    List<BuyListEntry> best = trainer.Train(8);
                    BuyList buyList2 = best.Last().BuyList;
                    Console.WriteLine("end train");
                    int wins = 0;
                    int ties = 0;
                    int games = 0;
                    while(games < 2560)
                    {
                        GameModel gameModel = new GameModel();
                        BuyListAIStrategy player1 = new BuyListAIStrategy(gameModel);
                        player1.BuyList = buyList2.Clone();
                        player1.UseSearch = true;
                        player1.SearchThreshold = 0.05;
                        //player1.SearchThreshold = 1.0;
                        player1.SearchNodes = 320;
                        player1.SearchKeepsHandInfo = true;
                        BuyListAIStrategy player2 = new BuyListAIStrategy(gameModel);
                        player2.BuyList = buyList2.Clone();
                        Player p1 = new Player("player1", player1, gameModel);
                        Player p2 = new Player("player2", player2, gameModel);
                        gameModel.Players.Add(p1);
                        gameModel.Players.Add(p2);
                        gameModel.InitializeGameState(kingdom, games % 2);
                        using (gameModel.TextLog.SuppressLogging())
                        {
                            gameModel.PlayGame();
                        }
                        if (gameModel.Result.Winners.Count == 2)
                        {
                            ties++;
                            games++;
                        }
                        else if (gameModel.Result.Winners.Contains(p1) && !gameModel.Result.Winners.Contains(p2))
                        {
                            wins++;
                            games++;
                        }
                        else if (gameModel.Result.Winners.Contains(p2) && !gameModel.Result.Winners.Contains(p1))
                        {
                            games++;
                        }
                    }

                    DateTime end2 = DateTime.Now;
                    Console.WriteLine((end2 - start).TotalSeconds + " seconds");

                    double ratio = wins / (double)(games-ties);
                    Console.WriteLine(Log.FormatSortedCards(cardSet.CardSet.CardCollection));
                    Console.WriteLine(buyList2.ToString());
                    Console.WriteLine(wins + " / " + games);
                    Console.WriteLine((wins +ties) + " / " + games);
                    Console.WriteLine(ratio);
                    Console.WriteLine();

                    log += Log.FormatSortedCards(cardSet.CardSet.CardCollection);
                    log += buyList2.ToString();
                    log += wins + " / " + games;
                    log += ratio;
                    log += Environment.NewLine;

                    overallWins += wins;
                    overallGames += games;
                }
            }
            double overallRatio = overallWins / (double)overallGames;

            Console.WriteLine(overallWins + " / " + overallGames);
            Console.WriteLine(overallRatio);

            log += overallWins + " / " + overallGames;
            log += overallRatio;

            DateTime end = DateTime.Now;
            Console.WriteLine((end - start).TotalSeconds + " seconds");

            File.WriteAllText("output.txt", log);
        }
Beispiel #2
0
        public static void PerfTest()
        {
            Randomizer.SetRandomSeed(123456789);
            int games = 0;
            DateTime start = DateTime.Now;
            CardSetsModel cardSets = new CardSetsModel(GameSets.Any);
            foreach (CardSetGroup group in cardSets.CardSetGroups)
            {
                foreach(CardSetViewModel cardSet in group.CardSets)
                {
                    for (int k = 0; k < 800; k++)
                    {
                        games++;
                        GameModel model = new GameModel();
                        using (model.TextLog.SuppressLogging())
                        {
                            BuyList list = new BuyList();
                            list.DuchyBuyThreshold = 5;
                            list.EstateBuyThreshold = 3;
                            list.List.Add(new BuyListItem(typeof(Gold), 99));
                            foreach (CardModel card in cardSet.CardSet.CardCollection)
                            {
                                list.List.Add(new BuyListItem(card.GetType(), 1));
                            }
                            list.List.Add(new BuyListItem(typeof(Silver), 99));

                            BuyListAIStrategy player1 = new BuyListAIStrategy(model);
                            player1.BuyList = list;
                            BuyListAIStrategy player2 = new BuyListAIStrategy(model);
                            player2.BuyList = list;
                            Player p1 = new Player("player1", player1, model);
                            Player p2 = new Player("player2", player2, model);
                            model.Players.Add(p1);
                            model.Players.Add(p2);

                            Kingdom kingdom = new Kingdom(cardSet.CardSet.CardCollection, null, GameSets.Any, 2);
                            model.InitializeGameState(kingdom);
                            model.PlayGame(100);
                        }
                    }
                }
            }
            TimeSpan elapsed = DateTime.Now - start;
            Console.WriteLine("total time = " + elapsed.TotalSeconds);
            Console.WriteLine("Total games = " + games);
            Console.WriteLine("games / sec = " + (games / elapsed.TotalSeconds));
        }
Beispiel #3
0
        public static void TuneAllDefaultSets()
        {
            Randomizer.SetRandomSeed(123456789);

            CardSetsModel cardSets = new CardSetsModel(GameSets.Any);
            foreach (CardSetGroup group in cardSets.CardSetGroups)
            {
                foreach (CardSetViewModel cardSet in group.CardSets)
                {
                    Kingdom kingdom = new Kingdom(cardSet.CardSet.CardCollection, null, cardSet.CardSet.BaneCard, GameSets.Any, 2, CardUseType.DoNotUse, CardUseType.DoNotUse, StartingHandType.FourThreeSplit);

                    BuyListTrainer trainer = new BuyListTrainer(kingdom, true);
                    List<BuyListEntry> winners = trainer.Train(32, Console.Out);
                    Console.WriteLine(winners.Last().BuyList.ToString());
                }
            }
        }