Пример #1
0
 public static void draw(Player p, int draws)
 {
     for (int i = 0; i < draws; i++)
     {
         p.getHand().draw(p.getDeck());
     }
 }
Пример #2
0
 public void setUp()
 {
     this.p = new Player(0);
     p1 = new Player(1);
     p2 = new Player(2);
     this.game = new Game(4);
 }
Пример #3
0
 public static void bureaucratAction(Player p)
 {
     p.getDeck().addCardToFront(p.getGame().getBuyables()[1].buyOne());
     p.setOtherPlayerList();
     foreach (Player other in p.getOtherPlayers())
     {
         if (!other.getHand().hasDefenseCard())
         {
             Card c = other.getHand().getFirstVictoryCard();
             if (c == null)
             {
                 p.getGame().addToGameMessage(other.getName() + Internationalizer.getMessage("RevealNoVict"));
             }
             else
             {
                 other.getDeck().addCardToFront(other.getHand().remove(c));
                 p.getGame().addToGameMessage(other.getName() + Internationalizer.getMessage("BureaucratMsg1") + c.getName() + Internationalizer.getMessage("BureaucratMsg2"));
             }
         }
         else
         {
             p.getGame().addToGameMessage(other.getName() + Internationalizer.getMessage("Defended"));
         }
     }
 }
Пример #4
0
 public static void councilRoomAction(Player p)
 {
     p.setOtherPlayerList();
     foreach (Player other in p.getOtherPlayers())
     {
         other.addDelayedFunction(new DelayedFunction(other, 0));
     }
 }
Пример #5
0
 public static void gainCardFeast(Player p, StatusObject o)
 {
     p.setGain(true);
     p.setGainsLeft(p.getGainsLeft() + 1);
     //You gain a card worth 5 which is 1 more than cost of feast.
     p.setCurrencyForGain(5);
     p.getPlayed().Remove(CardMother.Feast());
     o.setTrashedCorrectly(true);
 }
Пример #6
0
 private PlayerAction ActionPhase(Player player)
 {
     IList<CardModel> availableActions = (from card in player.Hand where card.Is(CardType.Action) select card).ToList();
     if (availableActions.Count == 0)
     {
         return new PlayerAction() { ActionType = ActionType.EnterBuyPhase };
     }
     return new PlayerAction()
     {
         ActionType = ActionType.PlayCard,
         Card = availableActions[Randomizer.Next(availableActions.Count)]
     };
 }
Пример #7
0
        private PlayerAction BuyPhase(Player player)
        {
            if (player.HasBasicTreasures)
            {
                return new PlayerAction() { ActionType = ActionType.PlayBasicTreasures };
            }

            foreach (CardModel card in player.Hand)
            {
                if (card.Is(CardType.Treasure))
                {
                    return new PlayerAction() { ActionType = ActionType.PlayCard, Card = card };
                }
            }

            PlayerAction playerAction = null;
            if (this.TryBuyCard(player, typeof(Colony), out playerAction)) { return playerAction; }
            if (this.TryBuyCard(player, typeof(Platinum), out playerAction)) { return playerAction; }
            if (this.TryBuyCard(player, typeof(Province), out playerAction)) { return playerAction; }
            if (this.TryBuyCard(player, typeof(Gold), out playerAction)) { return playerAction; }
            if (this.TryBuyCard(player, typeof(Silver), out playerAction)) { return playerAction; }
            return new PlayerAction() { ActionType = ActionType.EndTurn };
        }
Пример #8
0
        public GameRecord ToGameRecord(Player player)
        {
            GameRecord record = new GameRecord();
            record.Name = player.Name;
            record.Won = this.ResultMap[player].Won;

            foreach (LogTurn turn in player.GameModel.TextLog.Turns)
            {
                foreach (string line in turn.Lines)
                {
                    record.Log.Add(line.Trim());
                }
            }

            foreach (Player p in player.GameModel.Players)
            {
                PlayerRecord playerRecord = new PlayerRecord();
                playerRecord.Name = p.Name;
                playerRecord.Score = this.ResultMap[p].Score;
                playerRecord.Deck = Log.FormatSortedCards(p.AllCardsInDeck);
                record.Players.Add(playerRecord);
            }
            return record;
        }
Пример #9
0
 public DelayedFunction(Player p, int functionNumber)
 {
     this.p = p;
     this.funcNum = functionNumber;
 }
Пример #10
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));
        }
Пример #11
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);
        }
Пример #12
0
 internal void TrashCard(CardModel chosenCard, Player owner)
 {
     this.Trash.Add(chosenCard);
     chosenCard.OnTrash(this, owner);
     foreach (CardModel card in owner.Hand.Where(c => c is MarketSquare).ToArray())
     {
         int choice = owner.Chooser.ChooseOneEffect(EffectChoiceType.DiscardMarketSquare, "You may discard Market Square to gain a Gold", marketSquareChoices, marketSquareChoices);
         if (choice == 0)
         {
             owner.DiscardCard(card);
             owner.GainCard(typeof(Gold));
         }
     }
 }
Пример #13
0
 public void testEqualFailStringName()
 {
     p.setName("George");
     Player two = new Player(0);
     two.setName("Fred");
     Assert.IsFalse(p.Equals(two));
 }
Пример #14
0
 public void testEqualFailID()
 {
     Player two = new Player(2);
     Assert.IsFalse(two.Equals(p));
 }
Пример #15
0
 public void testPlayThroneRoomAndMilitia()
 {
     Game g = new Game(2);
     Player p = g.getCurrentPlayer();
     p.getHand().getHand().Add(CardMother.Militia());
     p.getHand().getHand().Add(CardMother.ThroneRoom());
     StatusObject o = p.play(CardMother.ThroneRoom());
     o = p.play(CardMother.Militia());
     Assert.AreEqual(9, p.getCurrency());
     p = g.nextTurnPlayer();
     Assert.AreEqual(1, p.functionsToCall.Count);
 }
Пример #16
0
        public void startGame()
        {
            int PlayerCount = 1; //TEMPORARY!!*****
            store = new Store();

            //adds players to game
            for (int i = 0; i < PlayerCount; i++)
            {
                Player p = new Player();
                p.Store = store;
                _controller = new Controller(p);
                p.Buys = 10;
                p.Coins = 6;
                for (int j = 0; j < 7; j++)
                {
                    CopperCard cc = new CopperCard();
                    store.buyCard(p, cc);
                }

                for (int k = 0; k < 3; k++)
                {

                    EstateCard ec = new EstateCard();
                    store.buyCard(p, ec);
                }

                p.name = ("Player " + (i+1).ToString());
                players.Add(p);
            }

            foreach (Player p in players)
            {
                p.shuffleDeck();
                p.endTurn();
            }
            currentPlayerIndex = 0;
            bAction.player = (players[currentPlayerIndex]);
        }
Пример #17
0
 public void setUp()
 {
     this.p = new Player(0);
 }
Пример #18
0
 public Player PlayerLeftOf(Player player)
 {
     int thisPlayer = this.players.IndexOf(player);
     int left = (thisPlayer + 1) % players.Count;
     return this.players[left];
 }
Пример #19
0
 public Player PlayerRightOf(Player player)
 {
     int thisPlayer = this.players.IndexOf(player);
     int right = (thisPlayer - 1 + players.Count) % players.Count;
     return this.players[right];
 }
Пример #20
0
 public void testEqualsPass()
 {
     String name = "Paige";
     Player two = new Player(0);
     Assert.IsTrue(two.Equals(p));
     p.setName(name);
     two.setName(name);
     Assert.IsTrue(p.Equals(two));
 }
Пример #21
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);
             }
         }
     }
 }
Пример #22
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");
        }
Пример #23
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);
                }
            }
        }
Пример #24
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");
        }
Пример #25
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);
        }
Пример #26
0
 public void testPlayBureaucrat()
 {
     Game g = new Game(3);
     Player p = g.getCurrentPlayer();
     p.getHand().getHand().Add(CardMother.Bureaucrat());
     g.getPlayers()[1].getHand().getHand().Add(CardMother.Duchy());
     p.play(CardMother.Bureaucrat());
     Assert.AreEqual(CardMother.Silver(), p.getDeck().getInDeck()[0]);
     p = g.nextTurnPlayer();
     Assert.AreEqual(CardMother.Duchy(), p.getDeck().getInDeck()[0]);
     p = g.nextTurnPlayer();
     Assert.AreEqual(CardMother.Copper(), p.getDeck().getInDeck()[0]);
     Console.Write(g.getGameStatus());
 }
Пример #27
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));
                }
            }
        }
Пример #28
0
 public void testPlayCouncilRoom()
 {
     Game g = new Game(2);
     Player p = g.getCurrentPlayer();
     p.getHand().getHand().Add(CardMother.CouncilRoom());
     p.play(CardMother.CouncilRoom());
     Assert.AreEqual(9, p.getHand().size());
     Assert.AreEqual(2, p.getBuysLeft());
     p = g.nextTurnPlayer();
     p.callDelayedFunctions();
     Assert.AreEqual(6, p.getHand().size());
 }
Пример #29
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;
            }
        }
Пример #30
0
 public void testPlayMilitiaSetup()
 {
     Game g = new Game(2);
     Player p = g.getCurrentPlayer();
     p.getHand().getHand().Add(CardMother.Militia());
     StatusObject o = p.play(CardMother.Militia());
     Assert.IsTrue(o.wasPlayedProperly());
     Assert.AreEqual(7, p.getCurrency());
     p = g.nextTurnPlayer();
     Assert.AreEqual(1, p.functionsToCall.Count);
     o = p.callDelayedFunctions();
     Assert.IsTrue(o.wasMilitiaPlayed());
     Assert.IsTrue(o.needToContinueWithDelayedFunctions());
     List<Card> cards = new List<Card>();
     o = p.militiaDiscardEffect(cards);
     Assert.IsTrue(o.wasMilitiaPlayed());
     cards.Add(CardMother.Copper());
     cards.Add(CardMother.Copper());
     o = p.militiaDiscardEffect(cards);
     Assert.IsFalse(o.wasMilitiaPlayed());
     Assert.IsTrue(o.needToContinueWithDelayedFunctions());
     o = p.callDelayedFunctions();
     Assert.IsFalse(o.needToContinueWithDelayedFunctions());
 }