Ejemplo n.º 1
0
 private async System.Threading.Tasks.Task PopulateFromResources()
 {
     foreach (Dominion.Card card in Dominion.Cards.AllKingdomCardsList)
     {
         this.originalCards.Add(DominionCard.Create(card));
     }
 }
Ejemplo n.º 2
0
        public Dominion.GameConfig GetGameConfig()
        {
            Dominion.StartingCardSplit player1Split = this.player1Strategy.StartingCardSplit.Value;
            Dominion.StartingCardSplit player2Split = this.player2Strategy.StartingCardSplit.Value;
            Dominion.Card[]            kingdomCards = this.currentDeck.Cards.Where(c => c.cardShapedObject is Card).Select(c => (Card)c.cardShapedObject).ToArray();
            Dominion.Event[]           events       = this.eventCards.Cards.Where(c => c.cardShapedObject is Event).Select(c => (Event)c.cardShapedObject).ToArray();
            Dominion.Landmark[]        landmarks    = this.eventCards.Cards.Where(c => c.cardShapedObject is Landmark).Select(c => (Landmark)c.cardShapedObject).ToArray();
            Dominion.Project[]         projects     = this.eventCards.Cards.Where(c => c.cardShapedObject is Project).Select(c => (Project)c.cardShapedObject).ToArray();
            DominionCard baneCard = this.BaneCard.CurrentCards.FirstOrDefault();

            var builder = new Dominion.GameConfigBuilder();

            builder.SetKingdomPiles(kingdomCards);
            builder.SetEvents(events);
            builder.SetLandmarks(landmarks);
            builder.SetProjects(projects);
            if (baneCard != null)
            {
                builder.SetBaneCard((Card)baneCard.dominionCard);
            }

            builder.useColonyAndPlatinum = this.UseColonyPlatinum.Value;
            builder.useShelters          = this.UseShelters.Value;
            builder.SetCardSplitPerPlayer(new Dominion.StartingCardSplit[] { player1Split, player2Split });

            return(builder.ToGameConfig());
        }
Ejemplo n.º 3
0
 private async System.Threading.Tasks.Task PopulateSheltersFromResources()
 {
     foreach (Dominion.Card card in Dominion.Cards.Shelters)
     {
         this.originalCards.Add(DominionCard.Create(card));
     }
 }
Ejemplo n.º 4
0
 public void PopulateFromGameDescription(GameDescription gameDescription)
 {
     this.currentDeck.PopulateCards(gameDescription.kingdomPiles.Select(c => DominionCard.Create(c)));
     if (gameDescription.baneCard != null)
     {
         this.baneCard.PopulateBaneCard(DominionCard.Create(gameDescription.baneCard));
     }
     this.eventCards.PopulateCards(gameDescription.events.Select(c => DominionCard.Create(c)));
     this.UseShelters.Value       = gameDescription.useShelters;
     this.UseColonyPlatinum.Value = gameDescription.useColonyAndPlatinum;
 }
 public CardAcceptanceDescription(DominionCard card)
     : this()
 {
     this.Card.Value  = card;
     this.Count.Value = CountAsManyAsPossible;
     this.SecondaryMatchVisible.Value = false;
     this.TestCard.Value    = card;
     this.Comparison.Value  = Dominion.Strategy.Description.Comparison.LessThan;
     this.Threshhold.Value  = 1;
     this.CountSource.Value = Dominion.Strategy.Description.CountSource.Always;
 }
Ejemplo n.º 6
0
        private async void CurrentCardsListView_Drop(object sender, DragEventArgs e)
        {
            if (!e.Data.GetView().AvailableFormats.Contains("text"))
            {
                return;
            }

            string cardNames = (string)await e.Data.GetView().GetTextAsync("text");

            Dominion.Card[] cards = cardNames.Split(',').Select(cardName => DominionCard.Create(cardName).dominionCard).ToArray();
            Dominion.Strategy.Description.StrategyDescription strategy = this.StrategyDescription.ConvertToDominionStrategy();
            strategy = strategy.AddCardsToPurchaseOrder(cards);
            this.StrategyDescription.PopulateFrom(strategy);
        }
Ejemplo n.º 7
0
        private async System.Threading.Tasks.Task PopulateCommonFromResources(Dominion.GameConfig gameConfig)
        {
            this.originalCards.Clear();

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

            foreach (var availability in availabilities)
            {
                if (!gameConfig.kingdomPiles.Contains(availability.card) && gameConfig.baneCard != availability.card)
                {
                    this.originalCards.Add(DominionCard.Create(availability.card));
                }
            }
        }
        private void SelectedCards_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            this.appDataContext.selectedCards.Clear();
            foreach (var item in this.GetSelectedCardsAndClear(fShouldClear: false))
            {
                this.appDataContext.selectedCards.Add(DominionCard.Create(item));
            }
            this.appDataContext.IsSelectionPresentOnCurrentDeck.Value = this.appDataContext.selectedCards.Any();
            this.appDataContext.UpdateSimulationStep();
            this.appDataContext.UpdatePlayerButtonVisibilities();

            this.appDataContext.HintSelectedCardNotSimulatedButtonVisible.Value =
                this.appDataContext.IsSelectionPresentOnCurrentDeck.Value &&
                !this.appDataContext.CanSimulateCardsInSelection();
        }
Ejemplo n.º 9
0
 public void PopulateBaneCard(DominionCard card)
 {
     if (this.originalCards.Contains(card))
     {
         return;
     }
     if (this.originalCards.Any())
     {
         this.originalCards.Clear();
     }
     if (card != null)
     {
         this.originalCards.Add(card);
     }
     this.UpdateUIFromUIThread();
 }
Ejemplo n.º 10
0
        void AvailableCards_PropetyChanged(object sender, PropertyChangedEventArgs e)
        {
            var setCards = new HashSet <Dominion.Card>();

            foreach (var card in this.currentDeck.Cards)
            {
                setCards.Add((Dominion.Card)card.dominionCard);
            }

            foreach (var card in this.commonCards.Cards)
            {
                setCards.Add((Dominion.Card)card.dominionCard);
            }

            this.player1Strategy.ConvertToDominionStrategy().GetAllCardsInStrategy(setCards);
            this.player2Strategy.ConvertToDominionStrategy().GetAllCardsInStrategy(setCards);

            var extraCards = new List <DominionCard>();

            foreach (var card in this.availableCards)
            {
                if (!setCards.Contains(card.dominionCard))
                {
                    extraCards.Add(card);
                }
            }

            foreach (var card in setCards)
            {
                var dominionCard = DominionCard.Create(card);
                if (!this.availableCards.Contains(dominionCard))
                {
                    this.availableCards.Add(dominionCard);
                }
            }

            foreach (var card in extraCards)
            {
                this.availableCards.Remove(card);
            }

            // this sort method will order but cause items in strategy to be data bound empty
            //Sort(this.availableCards, c => c.dominionCard.name);
        }
        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);
        }
Ejemplo n.º 12
0
        public bool GenerateRandom(
            int targetCount,
            ref DominionCard baneCard,
            IEnumerable <DominionCard> allCards,
            IEnumerable <DominionCard> itemsToReplace)
        {
            bool isCleanRoll = MainPage.GenerateRandom(
                targetCount,
                ref baneCard,
                this.originalCards, this.Cards, allCards, itemsToReplace);

            if (!isCleanRoll)
            {
                this.ClearSort();
            }
            else
            {
                ReapplySortOrder();
            }

            this.UpdateUIFromUIThread();

            return(isCleanRoll);
        }
Ejemplo n.º 13
0
        internal static bool GenerateRandom(
            int targetCount,
            ref DominionCard baneCard,
            IList <DominionCard> resultList,
            IList <DominionCard> sourceList,
            IEnumerable <DominionCard> allCards,
            IEnumerable <DominionCard> itemsToReplace)
        {
            bool isReplacingItems = itemsToReplace != null && itemsToReplace.Any() && sourceList.Count <= targetCount;
            bool isReducingItems  = itemsToReplace != null && itemsToReplace.Any() && sourceList.Count > targetCount;
            var  cardPicker       = new Dominion.UniqueCardPicker <Dominion.Card>(allCards.Select(c => c.dominionCard), MainPage.random);

            bool isCleanRoll = false;

            if (isReplacingItems)
            {
                cardPicker.ExcludeCards(itemsToReplace.Select(c => c.dominionCard));
            }

            baneCard = DominionCard.Create(cardPicker.GetCard(c => c.DefaultCoinCost == 2 || c.DefaultCoinCost == 3));

            if (isReplacingItems)
            {
                foreach (DominionCard cardToReplace in itemsToReplace)
                {
                    for (int i = 0; i < resultList.Count; ++i)
                    {
                        if (resultList[i] == cardToReplace)
                        {
                            var nextCard = cardPicker.GetCard(c => true);
                            if (nextCard == null)
                            {
                                resultList.Remove(cardToReplace);
                                i--;  // do this index again
                            }
                            else
                            {
                                resultList[i] = DominionCard.Create(nextCard);
                            }
                        }
                    }
                }
            }
            else if (sourceList.Count < targetCount && sourceList.Count > 0)
            {
                var listRemoved = new List <DominionCard>();
                foreach (var card in resultList)
                {
                    if (!sourceList.Contains(card))
                    {
                        listRemoved.Add(card);
                    }
                }

                foreach (var card in listRemoved)
                {
                    resultList.Remove(card);
                }
            }
            else if (isReducingItems)
            {
                foreach (var card in itemsToReplace)
                {
                    resultList.Remove(card);
                }
            }
            else
            {
                resultList.Clear();
                isCleanRoll = true;
            }

            while (resultList.Count < targetCount)
            {
                Dominion.Card currentCard = cardPicker.GetCard(c => true);
                if (currentCard == null)
                {
                    break;
                }
                resultList.Add(DominionCard.Create(currentCard));
            }

            return(isCleanRoll);
        }
        public void Randomize10Cards()
        {
            var currentDeckSelectedItems = this.CurrentCardsListView.SelectedItems.Select(item => (DominionCard)item).ToArray <DominionCard>();
            var baneSelectedItems        = this.BaneCardsListView.SelectedItems.Select(item => (DominionCard)item).ToArray <DominionCard>();
            var eventsSelectedItems      = this.EventCardsListView.SelectedItems.Select(item => (DominionCard)item).ToArray <DominionCard>();

            bool isReplacing = currentDeckSelectedItems.Any() || baneSelectedItems.Any() || eventsSelectedItems.Any();
            bool isReducing  = this.appDataContext.CurrentDeck.CurrentCards.Count() > 10 && currentDeckSelectedItems.Any();
            bool isGrowing   = this.appDataContext.CurrentDeck.CurrentCards.Count() < 10 && this.appDataContext.CurrentDeck.CurrentCards.Any();

            if (!isReplacing && !isGrowing && !isReducing)
            {
                // clean roll
                this.appDataContext.player1Strategy.Clear();
                this.appDataContext.player2Strategy.Clear();
                this.appDataContext.UpdateSimulationStep();
                this.appDataContext.CurrentDeck.ReapplySortOrder();

                if (this.appDataContext.GetDecksFromWeb.Value)
                {
                    var uiScheduler = System.Threading.Tasks.TaskScheduler.FromCurrentSynchronizationContext();
                    WebService.GetGameConfigFomServer(this.appDataContext).ContinueWith(descrTask =>
                    {
                        GameDescriptionAndRating gameDescriptionAndRating = descrTask.Result;
                        if (gameDescriptionAndRating != null)
                        {
                            this.appDataContext.PopulateFromGameDescription(gameDescriptionAndRating.gameDescription);
                            this.appDataContext.WebRating.Value  = (int)(gameDescriptionAndRating.rating + 0.5);
                            this.appDataContext.DeckRating.Value = 0;
                        }
                        else
                        {
                            GenerateRandomDeck();
                        }
                    }, uiScheduler);
                }
                else
                {
                    GenerateRandomDeck();
                }
            }
            else
            {
                this.appDataContext.CurrentDeck.CopyOrder();
                DominionCard baneCard    = this.appDataContext.BaneCard.CurrentCards.FirstOrDefault();
                bool         isCleanRoll = this.appDataContext.CurrentDeck.GenerateRandom(10, ref baneCard, this.appDataContext.AllCards.CurrentCards, itemsToReplace: currentDeckSelectedItems);
                this.appDataContext.BaneCard.PopulateBaneCard(baneCard);
                this.appDataContext.DeckRating.Value = 0;
                this.appDataContext.WebRating.Value  = 0;
            }

            string jsonDescription = WebService.ToJson(this.appDataContext.GetGameConfig().gameDescription, 5).Stringify();

            System.Diagnostics.Debug.WriteLine("New Kingdom");
            System.Diagnostics.Debug.WriteLine("===========");
            System.Diagnostics.Debug.WriteLine(jsonDescription);

            if (this.CurrentCardsChanged != null)
            {
                this.CurrentCardsChanged();
            }
        }
Ejemplo n.º 15
0
 private async System.Threading.Tasks.Task PopulatColonyPlatinumFromResources()
 {
     this.originalCards.Add(DominionCard.Create(Dominion.Cards.Platinum));
     this.originalCards.Add(DominionCard.Create(Dominion.Cards.Colony));
 }