Exemple #1
0
        public GameResult(GameModel model)
        {
            this.ResultMap = new Dictionary<Player, PlayerResult>();
            this.Results = new List<PlayerResult>();
            this.Winners = new List<Player>();
            int highScore = int.MinValue;
            int minTurns = int.MaxValue;
            foreach (Player player in model.Players)
            {
                int points = player.Points;
                if(points > highScore || points == highScore && player.TurnCount < minTurns)
                {
                    highScore = points;
                    minTurns = player.TurnCount;
                }
            }

            foreach (Player player in model.Players)
            {
                int points = player.Points;
                bool won = points == highScore && player.TurnCount == minTurns;
                PlayerResult result = new PlayerResult() { Player = player, Score = points, Turns = player.TurnCount, Won = won };
                this.Results.Add(result);
                this.ResultMap[player] = result;
                if(won)
                {
                    this.Winners.Add(player);
                }
            }
        }
Exemple #2
0
        public static IList<Pile> CreatePiles(GameModel gameModel, IEnumerable<CardModel> cards, CardModel bane)
        {
            List<Pile> piles = new List<Pile>();

            foreach (CardModel cardModel in cards)
            {
                int count = 10;
                if (cardModel.Is(CardType.Victory))
                {
                    if (gameModel.Players.Count < 3)
                    {
                        count = 8;
                    }
                    else
                    {
                        count = 12;
                    }
                }
                if (cardModel is Rats)
                {
                    count = 20;
                }
                piles.Add(new Pile(count, gameModel, cardModel.GetType()));
            }
            if (bane != null)
            {
                gameModel.Bane = bane;
            }
            return piles;
        }
 public ServerPlayerStrategy(string name, GameModel gameModel, Connection connection)
     : base(gameModel, new ServerChooser())
 {
     this.name = name;
     this.connection = connection;
     ((ServerChooser)this.Chooser).Strategy = this;
     this.connection.GameMessage += new GameMessageEventHandler(connection_GameMessage);
 }
Exemple #4
0
 public GameViewModel(GameModel gameModel)
 {
     this.gameModel = gameModel;
     this.log = new LogViewModel(this.gameModel.TextLog);
     this.gameModel.ModelUpdated += new EventHandler(gameModel_ModelUpdated);
     this.gameModel.RefreshUI += new EventHandler(gameModel_RefreshUI);
     //	this.gameModel.ItemBought += new EventHandler<Dominion.GameModel.ItemBoughtEventArgs>(gameModel_ItemBought);
     this.gameModel.GameInitialized += new EventHandler(gameModel_GameInitialized);
     this.gameModel.PropertyChanged += new PropertyChangedEventHandler(gameModel_PropertyChanged);
 }
 public BuyListTrainingAIStrategy(GameModel gameModel, int generations, int leaders, int challengers, int gamesPerMatchup, bool mutateFinalThreshold)
     : base(gameModel)
 {
     ((BaseAIChooser)this.Chooser).SetStrategy(this);
     this.generations = generations;
     this.leaders = leaders;
     this.challengers = challengers;
     this.gamesPerMatchup = gamesPerMatchup;
     this.mutateFinalThreshold = true;
 }
Exemple #6
0
 public GameViewModel(GameModel gameModel)
 {
     this.gameModel = gameModel;
     this.log = new LogViewModel(this.gameModel.TextLog);
     this.gameModel.PileBuyStatusChanged += new EventHandler(gameModel_PileBuyStatusChanged);
     this.gameModel.PlayerActionsAndPhaseUpdated += new EventHandler(gameModel_PlayerActionsAndPhaseUpdated);
     this.gameModel.GameInitialized += new EventHandler(gameModel_GameInitialized);
     this.gameModel.PropertyChanged += new PropertyChangedEventHandler(gameModel_PropertyChanged);
     this.gameModel.OnGameOver += gameModel_OnGameOver;
 }
Exemple #7
0
        public MainWindow()
        {
            InitializeComponent();

            this.viewModel = new GameModel();
            //this.DataContext = this.viewModel;
            this.synchronizer = new ServerStateSynchronizer(this.viewModel);
            this.PlayArea.Visibility = Visibility.Hidden;
            this.ServerLobby.Visibility = Visibility.Hidden;
            this.GameSelect.Visibility = Visibility.Visible;

            this.AddressText.Text = Dns.GetHostName();
        }
Exemple #8
0
        public Pile(int count, GameModel gameModel, Type cardType, CardModel instance)
        {
            this.gameModel = gameModel;
            this.cardType = cardType;
            this.instance = instance;
            this.CostsPotion = this.instance.CostsPotion;
            this.Contrabanded = false;
            this.originalCost = gameModel.GetCost(this.instance);
            this.Cost = this.originalCost;
            this.Count = count;
            this.EmbargoCount = 0;
            this.TradeRouteCount = 0;
            this.name = instance.Name;

            if (this.instance.Is(CardType.Knight))
            {
                List<CardModel> cards = new List<CardModel>();
                cards.AddRange(Knights.AllKnights);

                this.uniqueCards = new Stack<CardModel>();
                foreach (CardModel card in cards.OrderBy(c => Randomizer.Next()))
                {
                    this.uniqueCards.Push(card);
                }
                this.TopCard = this.uniqueCards.Peek();
            }
            else if (this.instance.Is(CardType.Ruins))
            {
                List<CardModel> cards = new List<CardModel>();
                for (int i = 0; i < 10; i++)
                {
                    cards.Add(new AbandonedMine());
                    cards.Add(new RuinedLibrary());
                    cards.Add(new RuinedMarket());
                    cards.Add(new RuinedVillage());
                    cards.Add(new Survivors());
                }

                this.uniqueCards = new Stack<CardModel>();
                foreach (CardModel card in cards.OrderBy(c => Randomizer.Next()))
                {
                    this.uniqueCards.Push(card);
                }
                this.TopCard = this.uniqueCards.Peek();
            }
            else
            {
                this.TopCard = this.instance;
            }
            this.UpdateCost();
        }
Exemple #9
0
        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();
        }
Exemple #10
0
        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);
                }
            }
        }
Exemple #11
0
 public static void EffectCardTest()
 {
     GameModel model = new GameModel();
     List<CardModel> cardList = new List<CardModel>();
     cardList.Add(new Masquerade());
     Kingdom kingdom = new Kingdom(cardList, null, GameSets.Any, 2);
     model.InitializeGameState(kingdom);
     BaseAIChooser chooser = new BaseAIChooser(model);
     List<CardModel> choices = new List<CardModel>();
     choices.Add(new Masquerade());
     choices.Add(new Duchy());
     CardModel chosen = chooser.ChooseOneCard(Dominion.Model.Chooser.CardChoiceType.Masquerade, string.Empty, Dominion.Model.Chooser.ChoiceSource.FromHand, choices);
 }
Exemple #12
0
        public static void TrainerCompareAITest()
        {
            DateTime start = DateTime.Now;

            Kingdom kingdom = new Kingdom(new BigMoney().CardCollection, null, null, GameSets.Any, 2, CardUseType.DoNotUse, CardUseType.DoNotUse, StartingHandType.FourThreeSplit);
            /*
            BuyListTrainer trainer = new BuyListTrainer(kingdom, true);
            BuyListTrainer.GamesPerMatchup = 5;
            BuyListTrainer.MaxChallengerCount = 60;
            BuyListTrainer.MaxLeaderCount = 5;
            List<BuyListEntry> best = trainer.Train(20);
            Console.WriteLine("Trained");
            BuyList buyList1 = best.Last().BuyList;
            Console.WriteLine(buyList1.ToString(true));

            List<BuyListEntry> best2 = trainer.TrainThresholds();
            BuyList buyList2 = best2.Last().BuyList;
            Console.WriteLine(buyList2.ToString(true));
            */

            BuyList buyList1 = new BuyList();
            buyList1.OpeningBuy1 = typeof(Silver);
            buyList1.OpeningBuy2 = typeof(Moneylender);
            buyList1.List.Add(new BuyListItem(typeof(Adventurer), 1));
            buyList1.List.Add(new BuyListItem(typeof(Gold), 2));
            buyList1.List.Add(new BuyListItem(typeof(Province), 99));
            buyList1.List.Add(new BuyListItem(typeof(Adventurer), 2));
            buyList1.List.Add(new BuyListItem(typeof(Gold), 99));
            buyList1.List.Add(new BuyListItem(typeof(Laboratory), 6));
            buyList1.List.Add(new BuyListItem(typeof(Moneylender), 1));
            buyList1.List.Add(new BuyListItem(typeof(Silver), 99));

            BuyList buyList2 = buyList1.Clone();
            buyList2.EstateBuyThreshold = 2;
            buyList2.DuchyBuyThreshold = 5;
            buyList2.ProvinceBuyThreshold = 7;
            buyList2.ColonyBuyThreshold = 0;

            int wins = 0;
            int games = 0;
            for (int p = 0; p < 25600; p++)
            {
                GameModel gameModel = new GameModel();
                BuyListAIStrategy player1 = new BuyListAIStrategy(gameModel);
                player1.BuyList = buyList1.Clone();

                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, p % 2);
                gameModel.PlayGame(200);
                //Console.WriteLine(gameModel.TextLog.Text);
                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++;
                }

            }
            double ratio = wins / (double)games;
            Console.WriteLine(ratio);
        }
Exemple #13
0
        public static void TournamentTest2()
        {
            Randomizer.SetRandomSeed(123456789);
            CardModel[] cards = new CardModel[]
            {
                new Familiar(),
                new Wharf(),
                new FishingVillage(),
                new Smugglers(),
                new Warehouse(),
                new NomadCamp(),
                new Laboratory(),
                new Rabble(),
                new Nobles(),
                new KingsCourt()
            };
            Kingdom kingdom = new Kingdom(cards, null, null, GameSets.Any, 2, CardUseType.DoNotUse, CardUseType.DoNotUse, StartingHandType.FourThreeSplit);

            GameModel model = new GameModel();
            using (model.TextLog.SuppressLogging())
            {
                List<BuyList> lists = new List<BuyList>();
                BuyList list = new BuyList();

                list.ProvinceBuyThreshold = 5;
                list.DuchyBuyThreshold = 5;
                list.EstateBuyThreshold = 2;
                list.OpeningBuy1 = typeof(FishingVillage);
                list.OpeningBuy2 = typeof(FishingVillage);
                list.List.Add(new BuyListItem(typeof(Wharf), 4));
                list.List.Add(new BuyListItem(typeof(Gold), 1));
                list.List.Add(new BuyListItem(typeof(Province), 99));
                list.List.Add(new BuyListItem(typeof(Gold), 99));
                list.List.Add(new BuyListItem(typeof(Silver), 99));
                lists.Add(list);

                list = new BuyList();
                list.ProvinceBuyThreshold = 5;
                list.DuchyBuyThreshold = 5;
                list.EstateBuyThreshold = 2;
                list.OpeningBuy1 = typeof(Silver);
                list.OpeningBuy2 = typeof(Potion);
                list.List.Add(new BuyListItem(typeof(Familiar), 3));
                list.List.Add(new BuyListItem(typeof(Gold), 1));
                list.List.Add(new BuyListItem(typeof(Province), 99));
                list.List.Add(new BuyListItem(typeof(Gold), 99));
                list.List.Add(new BuyListItem(typeof(Silver), 99));
                lists.Add(list);

                int[] wins = new int[lists.Count];
                int[] losses = new int[lists.Count];
                int[] games = new int[lists.Count];
                BuyList[] listsArray = new BuyList[wins.Length];
                for (int i = 0; i < lists.Count; i++)
                {
                    listsArray[i] = lists[i];
                }

                for (int i = 0; i < 100; i++)
                {
                    for (int j = 0; j < lists.Count; j++)
                    {
                        for (int k = j + 1; k < lists.Count; k++)
                        {
                            int res = PlayGame(kingdom, listsArray[j], listsArray[k]);
                            if (res == -1)
                            {
                                wins[j]++;
                                losses[k]++;
                            }
                            else if (res == 1)
                            {
                                losses[j]++;
                                wins[k]++;
                            }

                            res = PlayGame(kingdom, listsArray[k], listsArray[j]);
                            if (res == -1)
                            {
                                wins[k]++;
                                losses[j]++;
                            }
                            else if (res == 1)
                            {
                                losses[k]++;
                                wins[j]++;
                            }
                            games[j] += 2;
                            games[k] += 2;
                        }
                    }
                }

                for (int i = 0; i < listsArray.Length; i++)
                {
                    Console.WriteLine(wins[i].ToString() + "/" + losses[i].ToString() + "/" + games[i].ToString());
                    Console.WriteLine(listsArray[i]);
                }
            }
        }
Exemple #14
0
 public Pile(int count, GameModel gameModel, Type cardType)
     : this(count, gameModel, cardType, (CardModel)Activator.CreateInstance(cardType))
 {
 }
Exemple #15
0
        public static void MonteCarloTreeSearchTest2()
        {
            CardModel[] cards = new CardModel[]
            {
                new Steward(),
                new DeathCart(),
                new Spy(),
                new Counterfeit(),
                new IllGottenGains(),
                new Laboratory(),
                new RoyalSeal(),
                new Stables(),
                new Venture(),
                new HuntingGrounds()
            };
            GameModel gameModel = new GameModel();
            Kingdom kingdom = new Kingdom(cards, null, null, GameSets.Any, 2, CardUseType.DoNotUse, CardUseType.DoNotUse, StartingHandType.FourThreeSplit);

            BuyList bigMoney = new BuyList();
            bigMoney.List.Add(new BuyListItem(typeof(IllGottenGains), 1));
            bigMoney.List.Add(new BuyListItem(typeof(Province), 8));
            bigMoney.List.Add(new BuyListItem(typeof(Gold), 99));
            bigMoney.List.Add(new BuyListItem(typeof(Silver), 99));
            bigMoney.ProvinceBuyThreshold = 5;
            bigMoney.DuchyBuyThreshold = 5;
            bigMoney.EstateBuyThreshold = 2;

            BuyListAIStrategy player1 = new BuyListAIStrategy(gameModel);
            BuyListAIStrategy player2 = new BuyListAIStrategy(gameModel);
            player1.BuyList = bigMoney.Clone();
            player2.BuyList = bigMoney.Clone();

            Player p1 = new Player("player1", player1, gameModel);
            Player p2 = new Player("player2", player2, gameModel);
            gameModel.Players.Add(p1);
            gameModel.Players.Add(p2);
            player1.FinalizeBuyList();
            player2.FinalizeBuyList();
            gameModel.InitializeGameState(kingdom, 0);
            p1.Hand.Clear();
            p2.Hand.Clear();
            for (int i = 0; i < 5; i++)
            {
                p1.Deck.Draw();
                p2.Deck.Draw();
            }
            for (int i = 0; i < 6; i++)
            {
                gameModel.PileMap[typeof(Province)].DrawCard();
                gameModel.PileMap[typeof(IllGottenGains)].DrawCard();
            }
            // skip opening book logic
            gameModel.HandlePlayerAction(new PlayerAction(ActionType.EndTurn));
            gameModel.HandlePlayerAction(new PlayerAction(ActionType.EndTurn));
            gameModel.HandlePlayerAction(new PlayerAction(ActionType.EndTurn));
            gameModel.HandlePlayerAction(new PlayerAction(ActionType.EndTurn));

            //human had 18 points, computer had 21 points
            // computer had 8 coins worth of stuff in hand
            // human had 5 coins worth of stuff in hand
            // 2 provinces left
            //6 duchys left
            // 8 estates left
            // 4 curses & ill gotten gains left
            // computer bought ill gotten gains, then reshuffled.
            p1.Hand.Add(new Copper());
            p1.Hand.Add(new Silver());
            p1.Hand.Add(new Gold());
            p1.Hand.Add(new Silver());
            p1.Hand.Add(new Estate());

            List<CardModel> d1 = new List<CardModel>();
            for (int i = 0; i < 6; i++) d1.Add(new Copper());
            for (int i = 0; i < 6; i++) d1.Add(new Curse());
            d1.Add(new Duchy());
            d1.Add(new Duchy());
            for (int i = 0; i < 3; i++) d1.Add(new Province());
            for (int i = 0; i < 2; i++) d1.Add(new Estate());
            for (int i = 0; i < 5; i++) d1.Add(new Silver());
            d1.Add(new HuntingGrounds());
            d1.Add(new Venture());
            d1.Add(new Venture());
            p1.Discard.AddRange(d1);

            List<CardModel> d2 = new List<CardModel>();
            for (int i = 0; i < 7; i++) d2.Add(new Copper());
            for (int i = 0; i < 5; i++) d2.Add(new IllGottenGains());
            for (int i = 0; i < 2; i++) d2.Add(new Province());

            d2.Add(new Silver());
            d2.Add(new Steward());
            d2.Add(new Steward());

            p2.Hand.Add(new Copper());
            p2.Hand.Add(new Copper());
            p2.Hand.Add(new Copper());
            p2.Hand.Add(new IllGottenGains());
            p2.Hand.Add(new Province());
            p2.Deck.Populate(d2);
            gameModel.HandlePlayerAction(new PlayerAction(ActionType.EnterBuyPhase));
            gameModel.HandlePlayerAction(new PlayerAction(ActionType.PlayBasicTreasures));

            MonteCarloTreeSearch search = new MonteCarloTreeSearch(gameModel, bigMoney.Clone(), false, 320);
            search.DoMCTS();
            DominionTreeNode node = search.Root;
            DominionTreeNode bestChild = null;
            DominionTreeNode defaultChild = null;
            foreach (DominionTreeNode child in node.Children.OrderByDescending(c => c.TotalValue / c.VisitCount))
            {
                Console.WriteLine(child.Action.ToString() + " " + child.TotalValue + " / " + child.VisitCount + " " + (child.TotalValue / child.VisitCount));
                if (bestChild == null || (child.TotalValue / child.VisitCount) > (bestChild.TotalValue / bestChild.VisitCount))
                {
                    bestChild = child;
                }
                if (child.Action.Pile != null && child.Action.Pile.Card is Province)
                {
                    defaultChild = child;
                }
            }

            PlayerAction defaultAction = defaultChild.Action;
            PlayerAction searchedAction = bestChild.Action;
            if (!defaultAction.Equals(searchedAction))
            {
                Console.WriteLine("difference!!!!!");

                MonteCarloTreeSearch refinedSearch = new MonteCarloTreeSearch(gameModel, bigMoney.Clone(), true, 310);
                refinedSearch.Root.Expand();
                for (int i = refinedSearch.Root.Children.Count - 1; i >= 0; i--)
                {
                    if (!(refinedSearch.Root.Children[i].Action.Equals(defaultAction) || refinedSearch.Root.Children[i].Action.Equals(searchedAction)))
                    {
                        refinedSearch.Root.Children.RemoveAt(i);
                    }
                }
                refinedSearch.DoMCTS();
                DominionTreeNode defaultActionChild = null, searchedActionChild = null;
                foreach (DominionTreeNode child in refinedSearch.Root.Children)
                {
                    if (child.Action.Equals(defaultAction))
                    {
                        defaultActionChild = child;
                    }
                    else if (child.Action.Equals(searchedAction))
                    {
                        searchedActionChild = child;
                    }
                    else
                    {
                        Debug.Assert(false);
                    }
                }
                double defaultWinRate = defaultActionChild.TotalValue / defaultActionChild.VisitCount;
                double searchedWinRate = searchedActionChild.TotalValue / searchedActionChild.VisitCount;

                foreach (DominionTreeNode child in refinedSearch.Root.Children.OrderByDescending(c => c.TotalValue / c.VisitCount))
                {
                    Console.WriteLine(child.Action.ToString() + " " + child.TotalValue + " / " + child.VisitCount + " " + (child.TotalValue / child.VisitCount));
                }
            }
        }
Exemple #16
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);
        }
Exemple #17
0
        public static int PlayGame(Kingdom kingdom, BuyList a, BuyList b)
        {
            GameModel model = new GameModel();
            BuyListAIStrategy player1 = new BuyListAIStrategy(model);
            BuyListAIStrategy player2 = new BuyListAIStrategy(model);
            player1.BuyList = a;
            player2.BuyList = b;
            Player p1 = new Player("player1", player1, model);
            Player p2 = new Player("player2", player2, model);
            model.Players.Add(p1);
            model.Players.Add(p2);

            model.InitializeGameState(kingdom, 0);

            model.PlayGame(100);

            if(!model.GameOver || model.Result.Winners.Count == 2)
            {
                return 0;
            }
            else if (model.Result.ResultMap[p1].Won)
            {
                return -1;
            }
            else
            {
                return 1;
            }
        }
Exemple #18
0
 public Logger(GameModel gameModel, int playerCount)
 {
     this.globalLog = new Log();
     this.playerLogs = new List<Log>();
     for(int i=0;i<playerCount;i++)
     {
         this.playerLogs.Add(new Log());
     }
 }
Exemple #19
0
 public RandomAIStrategy(GameModel gameModel)
     : base(gameModel, new RandomAIChooser(gameModel))
 {
 }
Exemple #20
0
        public static void Main(string[] args)
        {
            int port = 4502;

            string host = Dns.GetHostName();

            Socket s = ConnectSocket(host, port);

            Console.Write("Enter id:");
            string id = Console.ReadLine();

            Send("CONNECT " + id, s);
            string result = GetNextMessage(s);
            Console.WriteLine(result);
            string authentication = result.Substring(13);
            string command;
            DateTime lastChat = DateTime.Now;
            GameModel gameModel = new GameModel();
            ServerStateSynchronizer synchronizer = new ServerStateSynchronizer(gameModel);
            do
            {
                Console.WriteLine("Command(sendchat, viewchat, users, game, quit, accept, decline, check):");
                command = Console.ReadLine();
                if (command.StartsWith("sendchat"))
                {
                    string chat = command.Substring(9);
                    Send("SYSTEM|SENDCHAT " + chat, s);
                }
                else if (command.StartsWith("viewchat"))
                {
                    Send("SYSTEM|GETCHAT " + lastChat.ToString(), s);
                    lastChat = DateTime.Now;
                    string chat = GetNextMessage(s);
                    // starts with GETCHAT
                    if (chat != "NOCHAT")
                    {
                        Console.WriteLine(chat.Substring(8));
                    }
                }
                else if (command.StartsWith("users"))
                {
                    Send("SYSTEM|GETUSERS", s);
                    string users = GetNextMessage(s);
                    Console.WriteLine(users);
                }
                else if (command.StartsWith("game"))
                {
                    Send("SYSTEM|REQUESTGAME" + command.Substring(4), s);
                }
                else if(command.StartsWith("check"))
                {
                    string cmd = GetNextMessage(s);
                    Console.WriteLine(cmd);
                }
                else if(command.StartsWith("decline"))
                {
                    Send("SYSTEM|DECLINEGAME", s);
                }
                else if (command == "accept")
                {
                    Send("SYSTEM|ACCEPTGAME", s);
                    //string conn = GetNextMessage(s);
                    string conn = "";
                    //Console.WriteLine("GOT: " + conn);
                    while (conn != GameMessages.GamePrefix + GameMessages.GameEnded)
                    {
                        if (conn.StartsWith("GAME|"))
                        {
                            string msg = conn.Substring(5);
                            if (msg == GameMessages.RequestAction)
                            {
                                PrintClientState(gameModel, id);
                                Console.WriteLine("waiting for action");
                                string req = Console.ReadLine();
                                Send("GAME|" + req, s);
                            }
                            else if (msg.StartsWith(GameMessages.RequestChoice))
                            {
                                int q1 = msg.IndexOf('\"') + 1;
                                int q2 = msg.IndexOf('\"', q1);
                                string choiceText = msg.Substring(q1, q2 - q1);
                                int s1 = q2 + 2;
                                int s2 = msg.IndexOf(' ', s1+1);

                                string choiceType = msg.Substring(s1, s2 - s1);
                                if (choiceType == "CARDPILE")
                                {
                                    string[] c = msg.Substring(s2 + 1).Split(' ');
                                    string choiceSource = c[0];
                                    int minChoices = int.Parse(c[1]);
                                    int maxChoices = int.Parse(c[2]);
                                    int nChoices = int.Parse(c[3]);
                                    Debug.Assert(nChoices == c.Length - 4);
                                    Console.WriteLine(choiceText);
                                    Console.WriteLine("Choose between " + minChoices + " and " + maxChoices);
                                    for (int i = 4; i < c.Length; i++)
                                    {
                                        Console.Write(c[i] + " ");
                                    }
                                    Console.WriteLine();
                                    string input = Console.ReadLine();
                                    Send("GAME|" + input, s);
                                }
                                else
                                {
                                    Debug.Assert(choiceType == "EFFECT");
                                    s1 = s2 + 1;
                                    s2 = msg.IndexOf(' ', s1);
                                    int minChoices = int.Parse(msg.Substring(s1, s2 - s1));

                                    s1 = s2 + 1;
                                    s2 = msg.IndexOf(' ', s1);
                                    int maxChoices = int.Parse(msg.Substring(s1, s2 - s1));

                                    s1 = s2 + 1;
                                    s2 = msg.IndexOf(' ', s1);
                                    int numChoices = int.Parse(msg.Substring(s1, s2 - s1));

                                    Console.WriteLine(choiceText);
                                    Console.WriteLine("Choose between " + minChoices + " and " + maxChoices);
                                    for (int i = 0; i < numChoices; i++)
                                    {
                                        s1 = s2 + 1;
                                        s2 = msg.IndexOf(' ', s1 + 1);
                                        string ci = msg.Substring(s1, s2 - s1);

                                        q1 = msg.IndexOf('\"', s2) + 1;
                                        q2 = msg.IndexOf('\"', q1);
                                        string cdi = msg.Substring(q1, q2 - q1);
                                        s2 = q2;
                                        Console.WriteLine(cdi + " " + ci);
                                    }
                                    Console.WriteLine();
                                    string input = Console.ReadLine();
                                    Send("GAME|" + input, s);
                                }
                            }
                            else if (msg.StartsWith(GameMessages.SupplyPileInfo))
                            {
                                Console.WriteLine("The available cards are " + msg.Substring(GameMessages.SupplyPileInfo.Length));
                        //		synchronizer.HandleClientStateMessage(msg);
                            }
                            else if (msg.StartsWith(GameMessages.PlayerInfo))
                            {
                                Console.WriteLine("The players are " + msg.Substring(GameMessages.PlayerInfo.Length));
                        //		synchronizer.HandleClientStateMessage(msg);
                            }
                            else if (msg.StartsWith(GameMessages.PlayerState) || msg.StartsWith(GameMessages.PileState) || msg.StartsWith(GameMessages.CardPileState))
                            {
                        //		synchronizer.HandleClientStateMessage(msg);
                            }
                            else if (msg.StartsWith(GameMessages.Log))
                            {
                                Console.WriteLine(msg.Substring(GameMessages.Log.Length));
                            }
                        }
                        conn = GetNextMessage(s);
                    }
                }
            } while (command != "quit");

            Send("SYSTEM|DISCONNECT", s);
            s.Close();
        }
Exemple #21
0
 private static void PrintClientState(GameModel gameModel, string clientName)
 {
     Console.WriteLine("Game state");
     if (!(gameModel.Bane is YoungWitch))
     {
         Console.WriteLine("Bane: " + gameModel.Bane.Name);
     }
     Console.WriteLine("Current Phase: " + gameModel.CurrentPhase);
     Console.WriteLine("Current Player: " + gameModel.Players[gameModel.CurrentPlayerIndex].Name);
     Console.WriteLine("Turn: " + gameModel.TurnCount);
     foreach (Player player in gameModel.Players)
     {
         Console.WriteLine("Player: " + player.Name);
         if (player.Name == clientName)
         {
             Console.Write("Hand:");
             foreach (CardModel card in player.Hand)
             {
                 Console.Write(" " + card.Name);
             }
             Console.WriteLine();
         }
         else
         {
             Console.WriteLine("Hand: {0} cards", player.Hand.Count);
         }
         Console.WriteLine("Actions: " + player.Actions);
         Console.WriteLine("Buys: " + player.Buys);
         Console.WriteLine("Coin: " + player.Coin);
         Console.WriteLine("Potions: " + player.Potions);
         Console.WriteLine("VP Chips: " + player.VPChips);
         Console.WriteLine("Coin Tokens: " + player.CoinTokens);
     }
     Console.WriteLine("Piles");
     foreach (Pile pile in gameModel.SupplyPiles)
     {
         Console.WriteLine("{0}.  Cost {1}{2}.  Count {3}.", pile.Card.Name, pile.Cost, pile.CostsPotion ? "P" : "", pile.Count);
     }
 }
Exemple #22
0
 public static KeyValuePair<Pile, Pile> GetOpening(bool is34, GameModel gameModel)
 {
     foreach (KeyValuePair<string, string> cards in openings)
     {
         Pile a = gameModel.SupplyPiles.FirstOrDefault(p => p.Card.ID == cards.Key);
         Pile b = gameModel.SupplyPiles.FirstOrDefault(p => p.Card.ID == cards.Value);
         if (a != null && (string.IsNullOrEmpty(cards.Value) || b != null))
         {
             if (a.GetCost() == 5 && is34)
             {
                 continue;
             }
             if (b != null && b.GetCost() > 2 && !is34)
             {
                 continue;
             }
             return new KeyValuePair<Pile,Pile>(a, b);
         }
     }
     return new KeyValuePair<Pile, Pile>(null, null);
 }
Exemple #23
0
        public static void MonteCarloTreeSearchCompareAITest()
        {
            DateTime start = DateTime.Now;
            /*
            CardModel[] cards = new CardModel[]
            {
                new Chapel(),
                new ShantyTown(),
                new Militia(),
                new Moneylender(),
                new City(),
                new Mint(),
                new Goons(),
                new Hoard(),
                new Nobles(),
                new Expand()
            };

            BuyList buyList = new BuyList();
            buyList.OpeningBuy1 = typeof(Chapel);
            buyList.OpeningBuy2 = typeof(Silver);
            buyList.List.Add(new BuyListItem(typeof(Goons), 2));
            buyList.List.Add(new BuyListItem(typeof(City), 5));
            buyList.List.Add(new BuyListItem(typeof(Goons), 1));
            buyList.List.Add(new BuyListItem(typeof(Nobles), 4));
            buyList.List.Add(new BuyListItem(typeof(Militia), 1));
            buyList.List.Add(new BuyListItem(typeof(Nobles), 2));
            buyList.List.Add(new BuyListItem(typeof(City), 4));
            buyList.List.Add(new BuyListItem(typeof(Province), 8));
            buyList.List.Add(new BuyListItem(typeof(Nobles), 2));
            buyList.List.Add(new BuyListItem(typeof(Goons), 3));
            buyList.List.Add(new BuyListItem(typeof(Hoard), 5));
            buyList.List.Add(new BuyListItem(typeof(Gold), 99));
            buyList.List.Add(new BuyListItem(typeof(Silver), 99));
            */
            //Kingdom kingdom = new Kingdom(cards, null, GameSets.Any, 2, CardUseType.DoNotUse, CardUseType.DoNotUse, StartingHandType.FourThreeSplit);

            /*
            IList<CardModel> cards = new List<CardModel>(new BigMoney().CardCollection);
            BuyList buyList = new BuyList();
            buyList.OpeningBuy1 = typeof(Chancellor);
            buyList.OpeningBuy2 = typeof(Silver);
            buyList.List.Add(new BuyListItem(typeof(Gold), 1));
            buyList.List.Add(new BuyListItem(typeof(Laboratory), 2));
            buyList.List.Add(new BuyListItem(typeof(Province), 99));
            buyList.List.Add(new BuyListItem(typeof(Gold), 99));
            buyList.List.Add(new BuyListItem(typeof(Moneylender), 1));
            buyList.List.Add(new BuyListItem(typeof(Laboratory), 8));
            buyList.List.Add(new BuyListItem(typeof(Silver), 99));
            */

            IList<CardModel> cards = new List<CardModel>(new PoolsToolsAndFools().CardCollection);
            BuyList buyList = new BuyList();
            buyList.OpeningBuy1 = typeof(Silver);
            buyList.OpeningBuy2 = typeof(Silver);
            buyList.List.Add(new BuyListItem(typeof(ScryingPool), 2));
            buyList.List.Add(new BuyListItem(typeof(Golem), 8));
            buyList.List.Add(new BuyListItem(typeof(Nobles), 1));
            buyList.List.Add(new BuyListItem(typeof(Province), 99));
            buyList.List.Add(new BuyListItem(typeof(Gold), 3));
            buyList.List.Add(new BuyListItem(typeof(Nobles), 8));
            buyList.List.Add(new BuyListItem(typeof(Gold), 99));
            buyList.List.Add(new BuyListItem(typeof(ScryingPool), 2));
            buyList.List.Add(new BuyListItem(typeof(Silver), 99));
            buyList.List.Add(new BuyListItem(typeof(Potion), 1));
            buyList.List.Add(new BuyListItem(typeof(ScryingPool), 6));

            Kingdom kingdom = new Kingdom(cards, null, null, GameSets.Any, 2, CardUseType.DoNotUse, CardUseType.DoNotUse, StartingHandType.FourThreeSplit);

            /*
            BuyListTrainer trainer = new BuyListTrainer(kingdom, true);
            BuyListTrainer.GamesPerMatchup = 5;
            BuyListTrainer.MaxChallengerCount = 60;
            BuyListTrainer.MaxLeaderCount = 5;
            List<BuyListEntry> best = trainer.Train(20);
            Console.WriteLine("Trained");
            BuyList buyList2 = best.Last().BuyList;
            Console.WriteLine(buyList2.ToString());
            return;
            */
            int wins = 0;
            int games = 0;
            for (int p = 0; p < 256; p++)
            {
                GameModel gameModel = new GameModel();
                BuyListAIStrategy player1 = new BuyListAIStrategy(gameModel);
                player1.BuyList = buyList.Clone();
                player1.UseSearch = true;
                player1.SearchThreshold = 0.05;
                player1.SearchNodes = 320;
                player1.SearchConfirm = true;
                player1.SearchKeepsHandInfo = false;
                BuyListAIStrategy player2 = new BuyListAIStrategy(gameModel);
                player2.BuyList = buyList.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, p % 2);
                gameModel.PlayGame(200);
                //Console.WriteLine(gameModel.TextLog.Text);
                if (gameModel.Result.Winners.Contains(p1) && !gameModel.Result.Winners.Contains(p2))
                {
                    Console.WriteLine("won");
                    wins++;
                    games++;
                }
                else if(gameModel.Result.Winners.Contains(p2) && !gameModel.Result.Winners.Contains(p1))
                {
                    Console.WriteLine("lost");
                    games++;
                }

            }
            double ratio = wins / (double)games;
            Console.WriteLine(ratio);
            DateTime end = DateTime.Now;
            Console.WriteLine((end - start).TotalSeconds + " seconds");
        }
Exemple #24
0
 public GameModel Clone(bool keepHandInfo, Func<GameModel, GameModel, Player, BaseAIStrategy> strategyFactory)
 {
     GameModel clone = new GameModel();
     clone.allCardsInGame.AddRange(this.AllCardsInGame.Select(c => c.Clone()));
     clone.Bane = this.Bane.Clone();
     clone.BlackMarket.AddRange(this.BlackMarket.Select(c => c.Clone()));
     clone.CardModifiers.AddRange(this.CardModifiers.Select(cm => cm.Clone()));
     clone.currentPhase = this.currentPhase;
     clone.currentPlayerIndex = this.currentPlayerIndex;
     clone.extraPiles.AddRange(this.extraPiles.Select(p => p.Clone(clone)));
     clone.GameHasStash = this.GameHasStash;
     clone.GameHasContraband = this.GameHasContraband;
     clone.GameHasUrchin = this.GameHasUrchin;
     clone.UsesRuins = this.UsesRuins;
     clone.UsesShelters = this.UsesShelters;
     clone.gameOver = this.gameOver;
     clone.gameStarted = this.gameStarted;
     clone.players.AddRange(this.players.Select(p => p.Clone(clone)));
     foreach (Player player in clone.Players)
     {
         player.SetStrategy(strategyFactory(this, clone, player));
         if (!keepHandInfo)
         {
             if (player != clone.CurrentPlayer)
             {
                 int handCount = player.Hand.Count;
                 player.Deck.Populate(player.Hand);
                 player.Deck.Shuffle(true);
                 player.Hand.Clear();
                 player.Draw(handCount);
             }
             else
             {
                 player.Deck.Shuffle(true);
             }
         }
     }
     clone.prizes.AddRange(this.prizes.Select(p => p.Clone()));
     clone.supplyPiles.AddRange(this.supplyPiles.Select(p => p.Clone(clone)));
     clone.Ruins = clone.SupplyPiles.FirstOrDefault(p => p.Card.Is(CardType.Ruins));
     clone.tradeRouteCount = this.tradeRouteCount;
     clone.trash.AddRange(this.trash.Select(c => c.Clone()));
     clone.turnCount = this.turnCount;
     clone.InitializePileMap();
     return clone;
 }
Exemple #25
0
        public static void MonteCarloTreeSearchTest()
        {
            CardModel[] cards = new CardModel[]
            {
                new Chapel(),
                new ShantyTown(),
                new Militia(),
                new Moneylender(),
                new City(),
                new Mint(),
                new Goons(),
                new Hoard(),
                new Nobles(),
                new Expand()
            };
            GameModel gameModel = new GameModel();
            Kingdom kingdom = new Kingdom(cards, null, null, GameSets.Any, 2, CardUseType.DoNotUse, CardUseType.DoNotUse, StartingHandType.FourThreeSplit);

            BuyList bigMoney = new BuyList();
            bigMoney.List.Add(new BuyListItem(typeof(Province), 8));
            bigMoney.List.Add(new BuyListItem(typeof(Gold), 99));
            bigMoney.List.Add(new BuyListItem(typeof(Silver), 99));

            BuyListAIStrategy player1 = new BuyListAIStrategy(gameModel);
            BuyListAIStrategy player2 = new BuyListAIStrategy(gameModel);
            player1.BuyList = bigMoney.Clone();
            player2.BuyList = bigMoney.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);
            p1.Hand.Clear();
            p2.Hand.Clear();
            for (int i = 0; i < 5; i++)
            {
                p1.Deck.Draw();
                p2.Deck.Draw();
            }
            for (int i = 0; i < 6; i++)
            {
                gameModel.PileMap[typeof(Province)].DrawCard();
            }
            // skip opening book logic
            gameModel.HandlePlayerAction(new PlayerAction(ActionType.EndTurn));
            gameModel.HandlePlayerAction(new PlayerAction(ActionType.EndTurn));
            gameModel.HandlePlayerAction(new PlayerAction(ActionType.EndTurn));
            gameModel.HandlePlayerAction(new PlayerAction(ActionType.EndTurn));
            p1.Hand.Add(new Gold());
            p1.Hand.Add(new Gold());
            p1.Hand.Add(new Gold());
            p1.Hand.Add(new Gold());
            p1.Hand.Add(new Gold());
            p2.Hand.Add(new Gold());
            p2.Hand.Add(new Gold());
            p2.Hand.Add(new Gold());
            p2.Hand.Add(new Gold());
            p2.Hand.Add(new Estate());
            List<CardModel> d1 = new List<CardModel>();
            for(int i=0;i<5;i++) d1.Add(new Gold());
            List<CardModel> d2 = new List<CardModel>();
            for(int i=0;i<5;i++) d2.Add(new Gold());
            p1.Deck.Populate(d1);
            p2.Deck.Populate(d2);
            gameModel.HandlePlayerAction(new PlayerAction(ActionType.EnterBuyPhase));
            gameModel.HandlePlayerAction(new PlayerAction(ActionType.PlayBasicTreasures));
            MonteCarloTreeSearch search = new MonteCarloTreeSearch(gameModel, bigMoney, true, 320);
            search.DoMCTS();
            DominionTreeNode node = search.Root;
            PlayerAction action = node.BestChild.Action;
            Debug.Assert(action.Pile.Name != "Province");
        }
Exemple #26
0
 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);
             }
         }
     }
 }
Exemple #27
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));
        }
Exemple #28
0
 public Pile Clone(GameModel gameModel)
 {
     Pile clone = new Pile(this.count, gameModel, this.cardType, this.instance.Clone());
     clone.contrabanded = this.contrabanded;
     clone.cost = this.cost;
     clone.costsPotion = this.costsPotion;
     clone.embargoCount = this.embargoCount;
     clone.topCard = this.topCard.Clone();
     clone.tradeRouteCount = this.tradeRouteCount;
     if (this.uniqueCards != null)
     {
         foreach (CardModel card in this.uniqueCards.Reverse())
         {
             clone.uniqueCards.Push(card.Clone());
         }
     }
     return clone;
 }
Exemple #29
0
        public static void TournamentTest()
        {
            Randomizer.SetRandomSeed(123456789);
            CardModel[] cards = new CardModel[]
            {
                new Chapel(),
                new ShantyTown(),
                new Militia(),
                new Moneylender(),
                new City(),
                new Mint(),
                new Goons(),
                new Hoard(),
                new Nobles(),
                new Expand()
            };
            cards = new CardModel[]
            {
                new Pawn(),
                new Village(),
                new Swindler(),
                new Tournament(),
                new Watchtower(),
                new City(),
                new Duke(),
                new Festival(),
                new Mint(),
                new TradingPost()
            };

            /*
            CardSet cardSet = new TheGoodLife();
            IEnumerable<CardModel> cards = cardSet.CardCollection;

            new Contraband(),
            new CountingHouse(),
            new Hoard(),
            new Monument(),
            new Mountebank(),
            new Bureaucrat(),
            new Cellar(),
            new Chancellor(),
            new Gardens(),
            new Village()
             * */
            //Kingdom kingdom = new Kingdom(cards, null, 2, CardUseType.Use, CardUseType.DoNotUse, StartingHandType.FourThreeSplit);
            Kingdom kingdom = new Kingdom(cards, null, null, GameSets.Any, 2, CardUseType.DoNotUse, CardUseType.DoNotUse, StartingHandType.FourThreeSplit);

            GameModel model = new GameModel();
            using (model.TextLog.SuppressLogging())
            {
                List<BuyList> lists = new List<BuyList>();
                BuyList list = new BuyList();

                list.ProvinceBuyThreshold = 5;
                list.DuchyBuyThreshold = 5;
                list.EstateBuyThreshold = 2;
                list.OpeningBuy1 = typeof(Steward);
                list.OpeningBuy2 = typeof(Steward);
                list.List.Add(new BuyListItem(typeof(Platinum), 1));
                list.List.Add(new BuyListItem(typeof(Colony), 99));
                list.List.Add(new BuyListItem(typeof(Platinum), 99));
                list.List.Add(new BuyListItem(typeof(Mint), 1));
                list.List.Add(new BuyListItem(typeof(Province), 99));
                list.List.Add(new BuyListItem(typeof(Gold), 1));
                list.List.Add(new BuyListItem(typeof(Gold), 99));
                list.List.Add(new BuyListItem(typeof(Silver), 99));
                lists.Add(list);

                list = new BuyList();
                list.ProvinceBuyThreshold = 5;
                list.DuchyBuyThreshold = 5;
                list.EstateBuyThreshold = 2;
                list.OpeningBuy1 = typeof(Steward);
                list.OpeningBuy2 = typeof(Tournament);

                list.List.Add(new BuyListItem(typeof(Platinum), 1));
                list.List.Add(new BuyListItem(typeof(Mint), 1));
                list.List.Add(new BuyListItem(typeof(Tournament), 3));
                list.List.Add(new BuyListItem(typeof(Colony), 99));
                list.List.Add(new BuyListItem(typeof(Platinum), 99));
                list.List.Add(new BuyListItem(typeof(Gold), 1));
                list.List.Add(new BuyListItem(typeof(Province), 99));
                list.List.Add(new BuyListItem(typeof(Gold), 99));
                list.List.Add(new BuyListItem(typeof(Silver), 99));
                lists.Add(list);

                /*
                list.ProvinceBuyThreshold = 2;
                list.DuchyBuyThreshold = 2;
                list.EstateBuyThreshold = 1;
                list.List.Add(new BuyListItem(typeof(Colony), 99));
                list.List.Add(new BuyListItem(typeof(Platinum), 99));
                list.List.Add(new BuyListItem(typeof(Goons), 1));
                list.List.Add(new BuyListItem(typeof(Nobles), 8));
                list.List.Add(new BuyListItem(typeof(Gold), 99));
                list.List.Add(new BuyListItem(typeof(City), 10));
                list.List.Add(new BuyListItem(typeof(Militia), 1));
                list.List.Add(new BuyListItem(typeof(Silver), 1));
                list.List.Add(new BuyListItem(typeof(Chapel), 1));
                list.List.Add(new BuyListItem(typeof(ShantyTown), 7));
                list.List.Add(new BuyListItem(typeof(Silver), 99));
                lists.Add(list);

                list = new BuyList();
                list.ProvinceBuyThreshold = 3;
                list.DuchyBuyThreshold = 2;
                list.EstateBuyThreshold = 0;
                list.List.Add(new BuyListItem(typeof(Militia), 1));
                list.List.Add(new BuyListItem(typeof(Chapel), 1));
                list.List.Add(new BuyListItem(typeof(Goons), 1));
                list.List.Add(new BuyListItem(typeof(City), 8));
                list.List.Add(new BuyListItem(typeof(Nobles), 8));
                list.List.Add(new BuyListItem(typeof(Colony), 99));
                list.List.Add(new BuyListItem(typeof(Expand), 8));

                list.List.Add(new BuyListItem(typeof(Goons), 1));
                list.List.Add(new BuyListItem(typeof(City), 1));
                list.List.Add(new BuyListItem(typeof(Goons), 4));
                list.List.Add(new BuyListItem(typeof(Platinum), 8));
                list.List.Add(new BuyListItem(typeof(City), 1));
                list.List.Add(new BuyListItem(typeof(Goons), 4));
                list.List.Add(new BuyListItem(typeof(Platinum), 99));
                list.List.Add(new BuyListItem(typeof(Province), 99));
                list.List.Add(new BuyListItem(typeof(Gold), 1));
                list.List.Add(new BuyListItem(typeof(Gold), 99));
                list.List.Add(new BuyListItem(typeof(Silver), 99));
                lists.Add(list);
                 * */
                /*
                list = new BuyList();
                list.DuchyBuyThreshold = 5;
                list.EstateBuyThreshold = 3;
                list.List.Add(new BuyListItem(typeof(Platinum), 99));
                list.List.Add(new BuyListItem(typeof(Nobles), 8));
                list.List.Add(new BuyListItem(typeof(Gold), 99));
                list.List.Add(new BuyListItem(typeof(City), 10));
                list.List.Add(new BuyListItem(typeof(Militia), 2));
                list.List.Add(new BuyListItem(typeof(Chapel), 1));
                list.List.Add(new BuyListItem(typeof(ShantyTown), 8));
                list.List.Add(new BuyListItem(typeof(Silver), 99));
                lists.Add(list);

                list = new BuyList();
                list.DuchyBuyThreshold = 5;
                list.EstateBuyThreshold = 3;
                list.List.Add(new BuyListItem(typeof(Platinum), 99));
                list.List.Add(new BuyListItem(typeof(Goons), 1));
                list.List.Add(new BuyListItem(typeof(Nobles), 8));
                list.List.Add(new BuyListItem(typeof(Gold), 99));
                list.List.Add(new BuyListItem(typeof(City), 10));
                list.List.Add(new BuyListItem(typeof(Chapel), 1));
                list.List.Add(new BuyListItem(typeof(Silver), 99));
                lists.Add(list);

                list = new BuyList();

                list.ColonyBuyThreshold = 8;
                list.ProvinceBuyThreshold = 2;
                list.DuchyBuyThreshold = 2;
                list.EstateBuyThreshold = 1;
                list.List.Add(new BuyListItem(typeof(Colony), 12));
                list.List.Add(new BuyListItem(typeof(Platinum), 99));
                list.List.Add(new BuyListItem(typeof(Hoard), 1));
                list.List.Add(new BuyListItem(typeof(Nobles), 8));
                list.List.Add(new BuyListItem(typeof(Gold), 99));
                list.List.Add(new BuyListItem(typeof(City), 10));
                list.List.Add(new BuyListItem(typeof(Chapel), 1));
                list.List.Add(new BuyListItem(typeof(Silver), 99));
                lists.Add(list);

                list = new BuyList();
                list.ColonyBuyThreshold = 0;
                list.ProvinceBuyThreshold = 0;
                list.DuchyBuyThreshold = 0;
                list.EstateBuyThreshold = 0;
                list.List.Add(new BuyListItem(typeof(Militia), 1));
                list.List.Add(new BuyListItem(typeof(Chapel), 1));
                list.List.Add(new BuyListItem(typeof(Gold), 3));
                list.List.Add(new BuyListItem(typeof(City), 10));
                list.List.Add(new BuyListItem(typeof(Goons), 10));
                list.List.Add(new BuyListItem(typeof(Silver), 4));
                list.List.Add(new BuyListItem(typeof(Hoard), 2));
                list.List.Add(new BuyListItem(typeof(Nobles), 8));
                list.List.Add(new BuyListItem(typeof(Gold), 99));
                lists.Add(list);
                */

                int[] wins = new int[lists.Count];
                int[] losses = new int[lists.Count];
                int[] games = new int[lists.Count];
                BuyList[] listsArray = new BuyList[wins.Length];
                for (int i = 0; i < lists.Count; i++)
                {
                    listsArray[i] = lists[i];
                }

                for (int i = 0; i < 100; i++)
                {
                    for (int j = 0; j < lists.Count; j++)
                    {
                        for (int k = j + 1; k < lists.Count; k++)
                        {
                            int res = PlayGame(kingdom, listsArray[j], listsArray[k]);
                            if (res == -1)
                            {
                                wins[j]++;
                                losses[k]++;
                            }
                            else if (res == 1)
                            {
                                losses[j]++;
                                wins[k]++;
                            }

                            res = PlayGame(kingdom, listsArray[k], listsArray[j]);
                            if (res == -1)
                            {
                                wins[k]++;
                                losses[j]++;
                            }
                            else if (res == 1)
                            {
                                losses[k]++;
                                wins[j]++;
                            }
                            games[j] += 2;
                            games[k] += 2;
                        }
                    }
                }

                for (int i = 0; i < listsArray.Length; i++)
                {
                    Console.WriteLine(wins[i].ToString() + "/" + losses[i].ToString() + "/" + games[i].ToString());
                    Console.WriteLine(listsArray[i]);
                }
            }
        }
Exemple #30
0
 public IList<Pile> CreatePiles(GameModel gameModel)
 {
     return CardSet.CreatePiles(gameModel, this.cardCollection, this.BaneCard);
 }