コード例 #1
0
ファイル: Program.cs プロジェクト: alanjg/MajorDomo
        public static void LogCheck()
        {
            int max = 1000;
            for (int i = 0; i < max; i++)
            {
                GameModel model = new GameModel();

                RandomAIStrategy player1 = new RandomAIStrategy(model);
                BaseAIStrategy player2 = new OpeningBookRandomizedAIStrategy(model);
                GameViewModel viewModel = new GameViewModel(model);
                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(new RandomAllCardSet(GameSets.Any).CardCollection, null, GameSets.Any, 2);
                model.InitializeGameState(kingdom);
                try
                {
                    model.PlayGame(250);
                    if (model.GameOver)
                    {
                        GameRecord record = model.Result.ToGameRecord(p1);
                        var s = new System.Xml.Serialization.XmlSerializer(typeof(GameRecord));
                        StringWriter w = new StringWriter();
                        s.Serialize(w, record);
                        GameRecord g2 = (GameRecord)s.Deserialize(new StringReader(w.ToString()));
                        if (record.Name != g2.Name)
                        {
                            Console.WriteLine("Error");
                        }
                        if (record.Won != g2.Won)
                        {
                            Console.WriteLine("Error");
                        }

                        if (record.Players.Count != g2.Players.Count)
                        {
                            Console.WriteLine("Error");
                        }
                        else
                        {
                            for (int j = 0; j < record.Players.Count; j++)
                            {
                                if (record.Players[j].Name != g2.Players[j].Name)
                                {
                                    Console.WriteLine("Error");
                                }
                                if (record.Players[j].Score != g2.Players[j].Score)
                                {
                                    Console.WriteLine("Error");
                                }
                                if (record.Players[j].Deck != g2.Players[j].Deck)
                                {
                                    Console.WriteLine("Error");
                                }
                            }
                        }
                        if (record.Log.Count != g2.Log.Count)
                        {
                            Console.WriteLine("Error");
                        }
                        else
                        {
                            for (int j = 0; j < record.Log.Count; j++)
                            {
                                if (record.Log[j].Replace(Environment.NewLine, "\n") != g2.Log[j])
                                {
                                    Console.WriteLine("Error");
                                }
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("error!");
                    Console.WriteLine(e.Message);
                    Console.WriteLine(e.StackTrace);
                    Debugger.Launch();
                }
                if (i % (max / 100) == 0)
                {
                    Console.WriteLine(i / (double)max);
                }
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: alanjg/MajorDomo
 public static void CrashCheckWorker()
 {
     int max = 1000000;
     for (int i = 0; i < max; i++)
     {
         GameModel model = new GameModel();
         using (model.TextLog.SuppressLogging())
         {
             RandomAIStrategy player1 = new RandomAIStrategy(model);
             //BaseAIStrategy player2 = new OpeningBookRandomizedAIStrategy(model);
             BuyListTrainingAIStrategy player2 = new BuyListTrainingAIStrategy(model, 4, 2, 4, 2, false);
             player2.UseSearch = true;
             player2.SearchNodes = 20;
             player2.SearchThreshold = 0.05;
             player2.SearchKeepsHandInfo = true;
             player2.SearchConfirm = true;
             GameViewModel viewModel = new GameViewModel(model);
             Player p1 = new Player("player1", player1, model);
             Player p2 = new Player("player2", player2, model);
             model.Players.Add(p1);
             model.Players.Add(p2);
             IEnumerable<CardModel> cards = new RandomAllCardSet(GameSets.Any).CardCollection;
             List<CardModel> cardList = cards.ToList();
             if (!cardList.Any(c => c is Prince))
             {
                 cardList.RemoveAt(0);
                 cardList.Add(new Prince());
             }
             Kingdom kingdom = new Kingdom(cardList, null, null, GameSets.Any, 2);
             model.InitializeGameState(kingdom);
             try
             {
                 model.PlayGame(100);
             }
             catch (Exception e)
             {
                 Console.WriteLine("error!");
                 Console.WriteLine(e.Message);
                 Console.WriteLine(e.StackTrace);
                 Debugger.Launch();
                 Console.WriteLine("error!");
                 Console.WriteLine(e.Message);
                 Console.WriteLine(e.StackTrace);
             }
             if (i % (max / 100) == 0)
             {
                 Console.WriteLine(i / (double)max);
             }
         }
     }
 }