コード例 #1
0
ファイル: Program.cs プロジェクト: alanjg/MajorDomo
        public static void CardComparerTest()
        {
            GameModel model = new GameModel();
            BaseAIStrategy s = new OpeningBookRandomizedAIStrategy(model);
            DiscardCardComparer comp = new DiscardCardComparer((BaseAIChooser)s.Chooser, GameSegment.Early);
            int result = comp.Compare(new Estate(), new Copper());
            Console.WriteLine(result);
            result = comp.Compare(new Copper(), new Silver());
            Console.WriteLine(result);
            result = comp.Compare(new Spoils(), new Silver());
            Console.WriteLine(result);

            PriorityCardPlayComparer c = new PriorityCardPlayComparer();
            result = c.Compare(new AbandonedMine(), new Adventurer());
            Console.WriteLine(result);
            List<CardModel> sorted = new List<CardModel>();
            sorted.Add(new AbandonedMine());
            sorted.Add(new Militia());
            foreach(CardModel cm in sorted.OrderBy(cc => cc, c).Reverse())
            {
                Console.Write(cm.Name + " ");
            }
            Console.WriteLine();
        }
コード例 #2
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);
                }
            }
        }