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 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(); }
public override IEnumerable<CardModel> ChooseCards(CardChoiceType choiceType, CardModel cardInfo, string choiceText, ChoiceSource source, int minChoices, int maxChoices, IEnumerable<CardModel> choices) { switch(choiceType) { case CardChoiceType.Discard: List<CardModel> choiceList = new List<CardModel>(choices); List<CardModel> discardList = new List<CardModel>(); return choiceList.OrderBy(choice => this.parent.StaticEvalSimple(choice, this.parent.GetGamePhase())).Take(minChoices); } return base.ChooseCards(choiceType, cardInfo, choiceText, source, minChoices, maxChoices, choices); }
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)); } } }
public static void TuneBuyList() { Randomizer.SetRandomSeed(123456789); //IEnumerable<CardModel> cards = new RandomAllCardSet().CardCollection.ToList(); //IList<CardModel> cards = new AdventuresAbroad().CardCollection; /* CardModel[] cards = new CardModel[]{ new Chapel(), new Militia(), new Goons(), new City(), new ShantyTown(), new Moneylender(), new Mint(), new Hoard(), new Nobles(), new Expand() };*/ //IList<CardModel> cards = new AdventuresAbroad().CardCollection; CardModel[] cards = new CardModel[] { new Pawn(), new FishingVillage(), new Steward(), new Tournament(), new Watchtower(), new City(), new Duke(), new Festival(), new Mint(), new Prince() }; Kingdom kingdom = new Kingdom(cards, null, null, GameSets.Any, 2, CardUseType.Use, CardUseType.DoNotUse, StartingHandType.FourThreeSplit); BuyListTrainer trainer = new BuyListTrainer(kingdom, true); List<BuyListEntry> winners = trainer.Train(32, Console.Out); foreach(BuyListEntry entry in winners) { Console.WriteLine(entry.WinRatio); Console.WriteLine(entry.BuyList.ToString()); Console.WriteLine(); } }
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)); } } }
public void Play(CardModel cardModel) { if (this.GameStarted && !this.GameOver) { if (cardModel != null && cardModel.Is(CardType.Action) && this.CanPlayAction) { this.CurrentPlayer.PlayAction(cardModel); this.OnPropertyChanged("CanPlayAction"); } else if (cardModel != null && cardModel.Is(CardType.Treasure) && this.CanPlayTreasure) { this.CurrentPlayer.PlayTreasure(cardModel); } } }
public int GetCost(CardModel cardModel) { int cost = cardModel.GetBaseCost(); if (cardModel is Peddler && this.CurrentPhase == GamePhase.Buy) { cost = Math.Max(0, cost - 2 * this.CurrentPlayer.Played.Count(card => card.Is(CardType.Action))); } foreach (CardModifier cardModifier in this.CardModifiers) { cost = cardModifier.GetCost(cardModel, cost); } if (this.CurrentPlayer.FerryPile != null) { if (this.CurrentPlayer.FerryPile.Card.Name == cardModel.ThisAsTrashTarget.Name || this.CurrentPlayer.FerryPile.Card.Is(CardType.Ruins) && cardModel.Is(CardType.Ruins) || this.CurrentPlayer.FerryPile.Card.Is(CardType.Knight) && cardModel.Is(CardType.Knight)) { cost = Math.Max(0, cost - 2); } } return cost; }
public virtual int GetCoins(CardModel cardModel, int coins) { return coins; }
public override IEnumerable<CardModel> ChooseCards(CardChoiceType choiceType, CardModel cardInfo, string choiceText, ChoiceSource source, int minChoices, int maxChoices, IEnumerable<CardModel> choices) { return choices.Take(minChoices); }
public override IEnumerable<CardModel> ChooseCards(CardChoiceType choiceType, CardModel cardInfo, string choiceText, ChoiceSource source, int minChoices, int maxChoices, IEnumerable<CardModel> choices) { IEnumerable<string> chosen = this.MakeCardPileChoice(choiceText, (from c in choices select c.ID), minChoices, maxChoices, source, card: true, order: false); List<CardModel> chosenCards = new List<CardModel>(); Dictionary<string, int> seen = new Dictionary<string, int>(); foreach (string c in chosen) { int skip = 0; seen.TryGetValue(c, out skip); CardModel foundCard = null; int counter = skip; foreach (CardModel card in choices) { if (c == card.ID) { if (counter > 0) { counter--; } else { foundCard = card; break; } } } seen[c] = skip + 1; chosenCards.Add(foundCard); } return chosenCards; }
public override CardModel React(CardModel source, ReactionTrigger trigger, IEnumerable<CardModel> reactions) { throw new NotImplementedException(); }
public Kingdom(IList<CardModel> cards, IList<CardModel> prohibitedCards, CardModel bane, GameSets allowedSets, int numPlayers, CardUseType usesColonies, CardUseType usesShelters, StartingHandType startingHandType, bool useRandomCardsFromChosenSetsOnly) { this.Bane = bane; this.NumPlayers = numPlayers; this.AllowedSets = allowedSets; if (prohibitedCards == null) { prohibitedCards = new List<CardModel>(); } List<CardModel> newCards = new List<CardModel>(); if (cards != null) { newCards.AddRange(cards); } this.Cards = newCards; int need = 10 - this.Cards.Count; if (need > 0) { IEnumerable<CardModel> randomFilteredCards = RandomAllCardSet.RandomCardIDs.Where(c => !this.Cards.Any(cc => cc.Name == c.Name) && !prohibitedCards.Any(cc => cc.Name == c.Name) && (this.Bane == null || this.Bane.Name != c.Name) && (c.GameSet & this.AllowedSets) != 0).OrderBy(c => Randomizer.Next()); newCards.AddRange(randomFilteredCards.Take(need)); need = 10 - this.Cards.Count; if (need > 0) { IEnumerable<CardModel> randomAllCards = RandomAllCardSet.RandomCardIDs.Where(c => !this.Cards.Any(cc => cc.Name == c.Name) && (this.Bane == null || this.Bane.Name != c.Name)).OrderBy(c => Randomizer.Next()); newCards.AddRange(randomAllCards.Take(need)); } } this.InitializeBlackMarket(useRandomCardsFromChosenSetsOnly, prohibitedCards); if (this.Cards.Any(card => card is YoungWitch)) { if (this.Bane == null) { // add a bane card if it hasn't been set already IEnumerable<CardModel> baneCards = RandomAllCardSet.RandomCardIDs.Where(c => (c.GetBaseCost() == 2 || c.GetBaseCost() == 3) && !c.CostsPotion && !this.Cards.Any(cc => cc.Name == c.Name) && (this.BlackMarketDeck == null || !this.BlackMarketDeck.Any(cc => cc.Name == c.Name)) && (c.GameSet & this.AllowedSets) != 0); if (useRandomCardsFromChosenSetsOnly) { IEnumerable<CardModel> filteredBaneCards = baneCards.Where(c => this.Cards.Any(cc => c.GameSet == cc.GameSet) && !prohibitedCards.Any(cc => cc.Name == c.Name)); if(filteredBaneCards.Any()) { baneCards = filteredBaneCards; } } CardModel baneChoice = baneCards.ElementAt(Randomizer.Next(baneCards.Count())); this.Bane = baneChoice; } if (this.Bane is BlackMarket) { this.InitializeBlackMarket(useRandomCardsFromChosenSetsOnly, prohibitedCards); } this.Cards.Add(this.Bane); } newCards.Sort(new Comparison<CardModel>((CardModel lhs, CardModel rhs) => { if (lhs.CostsPotion && !rhs.CostsPotion) return 1; if (rhs.CostsPotion && !lhs.CostsPotion) return -1; if (lhs.GetBaseCost() != rhs.GetBaseCost()) return lhs.GetBaseCost() - rhs.GetBaseCost(); return lhs.Name.CompareTo(rhs.Name); })); switch (usesColonies) { case CardUseType.Random: this.UsesColonies = Randomizer.Next(2) == 1; break; case CardUseType.RandomByCardsFromSet: this.UsesColonies = this.Cards.Count(card => card is ProsperityCardModel) > Randomizer.Next(10); break; case CardUseType.Use: this.UsesColonies = true; break; case CardUseType.DoNotUse: this.UsesColonies = false; break; } switch (usesShelters) { case CardUseType.Random: this.UsesShelters = Randomizer.Next(2) == 1; break; case CardUseType.RandomByCardsFromSet: this.UsesShelters = this.Cards.Count(card => card is DarkAgesCardModel) > Randomizer.Next(10); break; case CardUseType.Use: this.UsesShelters = true; break; case CardUseType.DoNotUse: this.UsesShelters = false; break; } this.CreateStartingDecks(startingHandType); this.VictoryCardCount = this.NumPlayers < 3 ? 8 : 12; }
public Kingdom(IList<CardModel> cards, IList<CardModel> prohibitedCards, CardModel bane, GameSets allowedSets, int numPlayers, CardUseType usesColonies, CardUseType usesShelters, StartingHandType startingHandType) : this(cards, prohibitedCards, bane, allowedSets, numPlayers, usesColonies, usesShelters, startingHandType, false) { }
public Kingdom(IList<CardModel> cards, IList<CardModel> prohibitedCards, CardModel bane, GameSets allowedSets, int numPlayers) : this(cards, prohibitedCards, bane, allowedSets, numPlayers, CardUseType.RandomByCardsFromSet, CardUseType.RandomByCardsFromSet, StartingHandType.Random, false) { }
public CardViewModel(CardModel card) { this.card = card; this.order = -1; }
public PlayerAction(ActionType actionType, CardModel card) { this.ActionType = actionType; this.Card = card; }
public int GetCoins(CardModel cardModel) { int coins = cardModel.Coins; foreach (CardModifier cardModifier in this.CardModifiers) { coins = cardModifier.GetCoins(cardModel, coins); } return coins; }
public CardViewModel(CardModel card) { this.card = card; }
public virtual int GetCost(CardModel cardModel, int cost) { return cost; }
public virtual void OnOtherPlayerGainedCard(Player player, CardModel card) { }
public void TakePrize(CardModel prize) { this.Prizes.Remove(this.Prizes.First(card => card.Name == prize.Name)); }
public virtual void OnThisPlayerGainedCard(CardModel card) { }
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]); } } }
public override IEnumerable<CardModel> ChooseCards(CardChoiceType choiceType, CardModel cardInfo, string choiceText, ChoiceSource source, int minChoices, int maxChoices, IEnumerable<CardModel> choices) { maxChoices = Math.Min(maxChoices, choices.Count()); int howMany = Randomizer.Next(minChoices, maxChoices + 1); return choices.OrderBy(c => Randomizer.Next()).Take(howMany); }
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"); }
public void PutCardOnPile(CardModel card) { this.Count++; this.OnPropertyChanged("Count"); if (this.uniqueCards != null) { this.uniqueCards.Push(card); this.TopCard = card; this.OnPropertyChanged("TopCard"); this.OnPropertyChanged("Name"); this.UpdateCost(); } }
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]); } } }
protected double StaticEvalSimple(CardModel card, double gamePhase) { int actionCount = 0, buyCount = 0, coinCount = 0, cardCount = 0; foreach (CardModel deckCard in this.Player.Hand.Union(this.Player.Discard.Union(this.Player.Played))) { actionCount += deckCard.Actions; buyCount += deckCard.Buys; coinCount += this.GameModel.GetCoins(deckCard); cardCount += deckCard.Cards; } double openingValue = -1; double endgameValue = -0.5; openingValue += (card.Actions * card.Actions) * Lerp(this.Weights[(int)Values.actionValue], this.Weights[(int)Values.actionValue] + 0.15, 3, 10, actionCount, true) + (card.Buys * card.Buys) * this.Weights[(int)Values.buyValue] + card.Cards * Lerp(this.Weights[(int)Values.cardValue], this.Weights[(int)Values.cardValue] + 0.75, 5, 10, cardCount, true) + (this.GameModel.GetCoins(card) * this.GameModel.GetCoins(card)) * Lerp(this.Weights[(int)Values.coinValue], this.Weights[(int)Values.coinValue] + 0.3, 5, 20, coinCount, true) + (card.Is(CardType.Action) ? this.Weights[(int)Values.ActionValue] : 0) + (card.Actions + card.Cards + this.GameModel.GetCoins(card)) * this.Weights[(int)Values.combinedValue] + (card.GetVictoryPoints(this.Player) * this.Weights[(int)Values.openingPointValue]); if (card.GetVictoryPoints(this.Player) >= 6) { // Essentially infinite value. openingValue += 30; } if (card is Bureaucrat) { openingValue += Lerp(0, this.Weights[(int)Values.bureaucratValue], 5, 20, coinCount, true); } if (card is Moat) { openingValue += this.Weights[(int)Values.moatValue]; } endgameValue += card.GetVictoryPoints(this.Player) * card.GetVictoryPoints(this.Player) * card.GetVictoryPoints(this.Player) * this.Weights[(int)Values.endgamePointValue]; endgameValue += this.GameModel.GetCoins(card) * this.GameModel.GetCoins(card) * this.Weights[(int)Values.endgameCoinValue]; return (1.0 - gamePhase) * openingValue + gamePhase * endgameValue; }