public static JsonObject ToJson(Dominion.GameDescription gameDescription)
        {
            JsonObject root = new Windows.Data.Json.JsonObject();

            root.Add(jsonNameUseShelters, JsonValue.CreateBooleanValue(gameDescription.useShelters));
            root.Add(jsonNameUseColonyAndPlatinum, JsonValue.CreateBooleanValue(gameDescription.useColonyAndPlatinum));
            string banePileName = gameDescription.BanePileProgrammaticName();
            if (banePileName != null)
            {
                root.Add(jsonNameBane, JsonValue.CreateStringValue(banePileName));
            }

            JsonArray kingdomArray = new JsonArray();
            foreach (var cardName in gameDescription.KingdomPileProgramaticNames())
            {
                kingdomArray.Add(JsonValue.CreateStringValue(cardName));
            }
            root.Add(jsonNameKingdomPiles, kingdomArray);

            JsonArray eventArray = new JsonArray();
            foreach (var cardName in gameDescription.EventProgramaticNames())
            {
                eventArray.Add(JsonValue.CreateStringValue(cardName));
            }
            root.Add(jsonNameEvents, eventArray);

            return root;
        }        
        public static JsonObject ToJson(Dominion.GameDescription gameDescription, int starRating)
        {
            JsonObject root = new Windows.Data.Json.JsonObject();

            root.Add(jsonNameDeck, ToJson(gameDescription));

            JsonArray expansionArray = new JsonArray();
            Dominion.Expansion[] presentExpansions;
            Dominion.Expansion[] missingExpansions;
            gameDescription.GetRequiredExpansions(out presentExpansions, out missingExpansions);

            foreach (var expansion in presentExpansions)
            {
                JsonObject expansionObject = new JsonObject();
                expansionObject.Add("name", JsonValue.CreateStringValue(expansion.ToProgramaticName()));
                expansionObject.Add("present", JsonValue.CreateBooleanValue(true));
                expansionArray.Add(expansionObject);
            }

            foreach (var expansion in missingExpansions)
            {
                JsonObject expansionObject = new JsonObject();
                expansionObject.Add("name", JsonValue.CreateStringValue(expansion.ToProgramaticName()));
                expansionObject.Add("present", JsonValue.CreateBooleanValue(false));
                expansionArray.Add(expansionObject);
            }

            root.Add(jsonNameRequiredExpansions, expansionArray);

            root.Add(jsonNameRating, JsonValue.CreateNumberValue(starRating));

            return root;
        }
Example #3
0
 void IActionCard.Play(Dominion.Engine.Game game, Player player, Turn turn, object sidedata)
 {
     turn.AddBuys(1);
     turn.AddTreasure(1);
     turn.AddActions(1);
     turn.AddCards(1);
 }
        public bool IsExcluded(Dominion.Card card)
        {
            bool unused;
            if (this.excludes.TryGetValue(card, out unused))
                return true;

            return false;
        }
Example #5
0
        void IActionCard.Play(Dominion.Engine.Game game, Player player, Turn turn, object sidedata)
        {
            Copper copper = sidedata as Copper;
            if (copper == null)
                throw new Exception("Moneylender needs a copper");

            player.TrashCard(copper);
            turn.AddTreasure(3);
        }
Example #6
0
 void IActionCard.Play(Dominion.Engine.Game game, Player player, Turn turn, object sidedata)
 {
     IEnumerable<ICard> cards = (IEnumerable<ICard>)sidedata;
     int count = 0;
     foreach (ICard card in cards)
     {
         if (Object.ReferenceEquals(card, this))
             throw new Exception("Attempted to discard the Cellar card that was being played");
         player.DiscardFromHand(card);
         ++count;
     }
     player.Draw(count);
 }
Example #7
0
        void IActionCard.Play(Dominion.Engine.Game game, Player player, Turn turn, object sidedata)
        {
            Enum newCardType = (Enum)sidedata;

            ICard newCard = game.DrawCard(newCardType);
            if (newCard == null)
                throw new Exception("Selected target type is not available");

            if (newCard.Cost > 4)
                throw new Exception("Target card is too expensive for Workshop");

            player.AddDiscard(newCard);
        }
Example #8
0
 void IActionCard.Play(Dominion.Engine.Game game, Player player, Turn turn, object sidedata)
 {
     IEnumerable<ICard> cards = (IEnumerable<ICard>)sidedata;
     int count = 0;
     foreach (ICard card in cards)
     {
         if (Object.ReferenceEquals(card, this))
             throw new Exception("Attempted to trash the Chapel card that was being played");
         if (count == 4)
             throw new Exception("Attempted to trash more than 4 cards permitted by Chapel");
         player.TrashCard(card);
         ++count;
     }
 }
 public override void InitializeBank(Dominion.Rules.CardBank bank)
 {            
     bank.AddCardPile(new LimitedSupplyCardPile().WithNewCards<SecretChamber>(10));
     bank.AddCardPile(new LimitedSupplyCardPile().WithNewCards<Moat>(10));
     bank.AddCardPile(new LimitedSupplyCardPile().WithNewCards<Mine>(10));
     bank.AddCardPile(new LimitedSupplyCardPile().WithNewCards<Market>(10));
     bank.AddCardPile(new LimitedSupplyCardPile().WithNewCards<Chancellor>(10));
     bank.AddCardPile(new LimitedSupplyCardPile().WithNewCards<Nobles>(10));
     bank.AddCardPile(new LimitedSupplyCardPile().WithNewCards<Militia>(10));
     bank.AddCardPile(new LimitedSupplyCardPile().WithNewCards<Village>(10));
     bank.AddCardPile(new LimitedSupplyCardPile().WithNewCards<ThroneRoom>(10));
     bank.AddCardPile(new LimitedSupplyCardPile().WithNewCards<Remodel>(10));
     base.InitializeBank(bank);
 }
Example #10
0
 private DominionCard(Dominion.Card card)
 {
     this.Id = card.ProgrammaticName;
     this.Name = card.name;
     this.Coin = card.DefaultCoinCost;
     this.Potion = card.potionCost;
     this.Expansion = GetExpansionIndex(card.expansion);
     this.IsAttack = card.isAttack;
     this.IsAction = card.isAction;
     this.IsReaction = card.isReaction;
     this.IsDuration = card.isDuration;
     this.isWebCard = false;
     this.dominionCard = card;
 }
Example #11
0
        void IActionCard.Play(Dominion.Engine.Game game, Player player, Turn turn, object sidedata)
        {
            RemodelData upgradeData = (RemodelData)sidedata;
            ICard origCard = (ICard)upgradeData.Card;

            ICard newCard = game.DrawCard(upgradeData.TargetType);
            if (newCard == null)
                throw new Exception("Selected target type is not available");

            if ((origCard.Cost + 2) < newCard.Cost)
                throw new Exception("Target card is too expensive to remodel");

            game.TrashCard(origCard);
            player.AddDiscard(newCard);
        }
Example #12
0
        void IActionCard.Play(Dominion.Engine.Game game, Player player, Turn turn, object sidedata)
        {
            MineData upgradeData = (MineData)sidedata;
            ICard origCard = (ICard)upgradeData.Card;

            if ((origCard.Type & CardType.Treasure) != CardType.Treasure)
                throw new Exception("Mine attempted on a non-treasure card");

            ICard newCard = game.DrawCard(upgradeData.TargetType);
            if (newCard == null)
                throw new Exception("Selected target type is not available for Mine");

            if ((origCard.Cost + 3) < newCard.Cost)
                throw new Exception("Target card is too expensive to mine into");

            player.TrashCard(origCard);
            player.AddToHand(newCard);
        }
        public CardConstraintMatcher(
            bool requirePlusBuy,
            bool requireVillage,
            bool requirePlusCard,
            bool requireTrashing,
            bool requireAttack,
            bool requireReactionWhenAttack,
            bool requireAtLeast3FromAnExpansion,
            Dominion.Card[] requiredCards,
            Dominion.Card[] restrictedCards,
            Dominion.Card[] startingCards,
            IEnumerable<Dominion.Card> allCards
            )
        {
            this.requirePlusBuy = requirePlusBuy;
            this.requireVillage = requireVillage;
            this.requirePlusCard = requirePlusCard;
            this.requireTrashing = requireTrashing;
            this.requireAttack = requireAttack;
            this.requireReactionWhenAttack = requireReactionWhenAttack;
            this.requireAtLeast3FromAnExpansion = requireAtLeast3FromAnExpansion;
            this.RequiredCards = requiredCards;
            this.RestrictedCards = restrictedCards;

            this.enabledExpansions = new List<Dominion.Expansion>();
            this.currentCards = new List<Dominion.Card>();
            this.missingRequiredCards = new List<Dominion.Card>();
            this.uniqueCardPicker = new Dominion.UniqueCardPicker(allCards, MainPage.random);

            this.uniqueCardPicker.ExcludeCards(requiredCards);
            this.uniqueCardPicker.ExcludeCards(restrictedCards);
            this.uniqueCardPicker.ExcludeCards(startingCards);

            foreach (var card in startingCards)
                this.currentCards.Add(card);

            foreach(var card in requiredCards)
            {
                if (!this.currentCards.Contains(card))
                {
                    this.missingRequiredCards.Add(card);
                }
            }
        }
Example #14
0
        void IActionCard.Play(Dominion.Engine.Game game, Player player, Turn turn, object sidedata)
        {
            turn.AddTreasure(2);

            foreach (KeyValuePair<IAI, Player> opponent in game.Players)
            {
                if (object.ReferenceEquals(opponent.Value, player))
                    continue;

                // FIXME: should have a better way of handling reaction cards that puts
                // the reaction in the reaction card, not the attack card
                bool safe = false;
                foreach (ICard card in opponent.Value.Hand)
                {
                    if (card is Moat)
                    {
                        safe = true;
                        break;
                    }
                }
                if (safe)
                    continue;

                int expectedDiscards = opponent.Value.Hand.Count() - 3;
                if (expectedDiscards != 0)
                {
                    IEnumerable<ICard> discards = opponent.Key.ChooseExternalDiscard(opponent.Value, opponent.Value.Hand.Count() - 3);
                    int count = 0;
                    foreach (ICard card in discards)
                    {
                        opponent.Value.DiscardFromHand(card);
                        ++count;
                    }
                    if (count != expectedDiscards)
                        throw new Exception("ChooseExternalDiscard did not choose correct card count");
                }
            }
        }
Example #15
0
 public int Score(Dominion.Rules.CardZone allCards)
 {
     return (allCards.CardCount / 10);
 }
 public System.Threading.Tasks.Task PopulateCommon(Dominion.GameConfig gameConfig)
 {
     return PopulateCommonFromResources(gameConfig).ContinueWith(async (continuation) =>
     {
         await this.UpdateUI();
     });
 }
        private async System.Threading.Tasks.Task PopulateCommonFromResources(Dominion.GameConfig gameConfig)
        {
            this.originalCards.Clear();

            Dominion.CardGainAvailablility[] availabilities = gameConfig.GetCardAvailability(1, Dominion.CardAvailabilityType.AdditionalCardsAfterKingdom);

            foreach (var availability in availabilities)
            {
                this.originalCards.Add(DominionCard.Create(availability.card));
            }
        }
        string[] GetSearchWordsForCard(Dominion.Card card)
        {
            var result = new List<string>();
            result.Add(card.name);
            result.Add(card.expansion.ExpansionToString());
            result.Add(card.DefaultCoinCost.ToString());
            if (card.isAction)
                result.Add("action");
            if (card.isAttack)
                result.Add("attack");
            if (card.isReaction)
                result.Add("reaction");
            if (card.isVictory)
                result.Add("victory");
            if (card.isTreasure)
                result.Add("treasure");
            if (card.isShelter)
                result.Add("shelter");
            if (card.isReserve)
                result.Add("reserve");
            if (card.isTraveller)
                result.Add("traveller");
            if (card.isEvent)
                result.Add("event");
            if (card.isDuration)
                result.Add("duration");
            if (card.requiresRuins)
                result.Add("ruins");
            if (card.requiresSpoils)
                result.Add("spoils");
            if (card.isPrize)
                result.Add("prize");
            if (card.isRuins)
                result.Add("ruins");
            if (card.isRuins)
                result.Add("ruins");
            if (card.potionCost != 0)
                result.Add("potion");

            if (this.appDataContext.CurrentDeck.CurrentCards.Where(c => c.dominionCard == card).Any())
            {
                result.Add("current");
                result.Add("deck");
                result.Add("selected");
            }

            return result.ToArray();
        }
 private bool ShouldIncludeExpansion(Dominion.Expansion expansion, Random random)
 {
     int cExpansion = this.kingdomPiles.Where(c => c.expansion == expansion).Count();
     int roll = random.Next(1, 10);
     return cExpansion >= roll ? true : false;
 }
 bool MatchesAttack(Dominion.Card card)
 {
     return card.isAttack;
 }
        public void PopulateFrom(Dominion.Strategy.Description.StrategyDescription descr)
        {
            this.Clear();

            foreach (Dominion.Strategy.Description.CardAcceptanceDescription cardAcceptanceDescription in descr.purchaseOrderDescription.descriptions)
            {
                this.PurchaseOrderDescriptions.Add(CardAcceptanceDescription.PopulateFrom(cardAcceptanceDescription));
            }

            foreach (Dominion.Strategy.Description.CardAcceptanceDescription cardAcceptanceDescription in descr.trashOrderDescription.descriptions)
            {
                this.TrashOrderDescriptions.Add(CardAcceptanceDescription.PopulateFrom(cardAcceptanceDescription));
            }
        }
 bool MatchesPlusBuy(Dominion.Card card)
 {
     return card.plusBuy > 0;
 }
        bool MatchesOtherConstraints(Dominion.Card card)
        {
            if (!this.allowAttack && card.isAttack)
                return false;
            if (!this.enabledExpansions.Contains(card.expansion))
                return false;

            return true;
        }
 bool MatchesPlusCard(Dominion.Card card)
 {
     return card.plusCard > 1;
 }
Example #25
0
 void IActionCard.Play(Dominion.Engine.Game game, Player player, Turn turn, object sidedata)
 {
     player.Draw(3);
 }
 bool MatchesVillage(Dominion.Card card)
 {
     return card.plusAction > 0;
 }
        bool CurrentConstraint(Dominion.Card card)
        {
            foreach(var current in RequiredCards)
            {
                if (!currentCards.Contains(current))
                {
                    return card == current;
                }
            }

            return true;
        }
Example #28
0
 void IActionCard.Play(Dominion.Engine.Game game, Player player, Turn turn, object sidedata)
 {
     turn.AddTreasure(2);
     if ((bool)sidedata)
         player.PlaceDeckInDiscard();
 }
        public static CardAcceptanceDescription PopulateFrom(Dominion.Strategy.Description.CardAcceptanceDescription descr)
        {
            var result = new CardAcceptanceDescription();
            result.Card.Value = DominionCard.Create(descr.card);

            if (descr.matchDescriptions.Length != 1 && descr.matchDescriptions.Length != 2)
                throw new Exception("Support only one match description in addition to count all owned");

            if (descr.matchDescriptions[0].countSource == Dominion.Strategy.Description.CountSource.Always)
            {
                result.Count.Value = CountAsManyAsPossible;
            }
            else if (descr.matchDescriptions[0].countSource == Dominion.Strategy.Description.CountSource.CountAllOwned &&
                     descr.matchDescriptions[0].cardType == descr.card &&
                     descr.matchDescriptions[0].comparison == Dominion.Strategy.Description.Comparison.LessThan)
            {
                result.Count.Value = descr.matchDescriptions[0].countThreshHold;
            }
            else
            {
                throw new Exception("First match description needs to describe how many of the card to own");
            }

            if (descr.matchDescriptions.Length == 2)
            {
                result.TestCard.Value = descr.matchDescriptions[1].cardType != null ? DominionCard.Create(descr.matchDescriptions[1].cardType) : null;
                result.Threshhold.Value = descr.matchDescriptions[1].countThreshHold;
                result.Comparison.Value = descr.matchDescriptions[1].comparison;
                result.CountSource.Value = descr.matchDescriptions[1].countSource;
            }
            else
            {
                result.CountSource.Value = Dominion.Strategy.Description.CountSource.Always;
            }

            return result;
        }
Example #30
0
 private static ExpansionIndex GetExpansionIndex(Dominion.Expansion expansion)
 {
     switch (expansion)
     {
         case Dominion.Expansion.Alchemy: return ExpansionIndex.Alchemy;
         case Dominion.Expansion.Base: return ExpansionIndex.Base;
         case Dominion.Expansion.Cornucopia: return ExpansionIndex.Cornucopia;
         case Dominion.Expansion.DarkAges: return ExpansionIndex.DarkAges;
         case Dominion.Expansion.Guilds: return ExpansionIndex.Guilds;
         case Dominion.Expansion.Hinterlands: return ExpansionIndex.Hinterlands;
         case Dominion.Expansion.Intrigue: return ExpansionIndex.Intrigue;
         case Dominion.Expansion.Promo: return ExpansionIndex.Promo;
         case Dominion.Expansion.Prosperity: return ExpansionIndex.Prosperity;
         case Dominion.Expansion.Seaside: return ExpansionIndex.Seaside;
         case Dominion.Expansion.Adventures: return ExpansionIndex.Adventures;
         case Dominion.Expansion.Unknown: return ExpansionIndex._Unknown;
     }
     throw new Exception("Expansion not found");
 }