Пример #1
0
 public void OnPredictionUpdate(PredictionInfo prediction)
 {
     _layout.Dispatcher.Invoke(() =>
     {
         _layout.Update(prediction);
     });
     _firstUpdateReceived = true;
     UpdateShowing();
 }
Пример #2
0
        public void Update(PredictionInfo prediction)
        {
            // Show each card at its unplayed count.
            // HACK - Because AnimatedCardList seems to reverse the order of cards with the same ID,
            // we have to reverse their order here but preserve the original order for the percentages.
            // This may need to be readdressed if AnimatedCardList's behavior changes.
            var cards = prediction.PredictedCards
                        .GroupBy(cardInfo => cardInfo.Card.Id, cardInfo => cardInfo.GetCardWithUnplayedCount())
                        .Select(group => group.Reverse())
                        .SelectMany(x => x)
                        .ToList();

            CardList.Update(cards, true);

            PercentageList.ItemsSource = prediction.PredictedCards.Select(cardInfo =>
            {
                // Lookup probabilities for any cards not already played.
                var nextProbabilities = cardInfo.Probabilities.Skip(cardInfo.NumPlayed).ToList();
                bool alreadyPlayed    = (cardInfo.Card.Count - cardInfo.NumPlayed <= 0);
                return(new PercentageItem(
                           nextProbabilities, cardInfo.Playability, alreadyPlayed, cardInfo.OffMeta));
            }).ToList();

            // Additional stats
            PossibleCards.Text = "Predicting " +
                                 prediction.NumPredictedCards + " / " + prediction.NumPossibleCards + " Possible Cards";
            PossibleDecks.Text = prediction.NumPossibleDecks.ToString() + " Matching Decks";

            // Force a measure pass so we can know the actual height of the InfoBox
            Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
            Arrange(new Rect(0, 0, DesiredSize.Width, DesiredSize.Height));

            // Enforce a maximum height on the Viewbox that contains the list of cards.
            // Note that we only scale the cardlist, but factor the InfoBox into the max height calculation.
            // The FitDeckListToDisplay setting reduces the max further to prevent overlap of other
            // UI elements.
            double maxHeightRatio =
                _config.FitDeckListToDisplay ? FittedMaxHeightRatio : AbsoluteMaxHeightRatio;
            double displayHeight =
                Core.OverlayWindow.Height - System.Windows.SystemParameters.WindowCaptionHeight;
            double maxHeight = maxHeightRatio * displayHeight;

            if (cards.Count * CardHeight > maxHeight - InfoBox.ActualHeight)
            {
                CardView.Height = maxHeight - InfoBox.ActualHeight;
            }
            else
            {
                CardView.Height = Double.NaN;
            }

            // Reposition on canvas, in case window has been resized.
            Canvas.SetBottom(this, Core.OverlayWindow.Height * BottomFromScreenRatio);
            Canvas.SetLeft(this, Core.OverlayWindow.Width * LeftFromScreenRatio);
        }
Пример #3
0
        private void TestView()
        {
            var cardList = new List <PredictionInfo.CardInfo>();

            for (int n = 0; n < 2; n++)
            {
                var card0 = Database.GetCardFromName("Ice Block");
                card0.Count = 3;
                var cardInfo0 = new PredictionInfo.CardInfo(card0, 0);                 // OffMeta, Unplayed
                var card1     = Database.GetCardFromName("Ice Block");
                var cardInfo1 = new PredictionInfo.CardInfo(card1, 1);                 // OffMeta, Played
                var card2     = Database.GetCardFromName("Ice Block");
                card2.Count = 2;
                var cardInfo2 = new PredictionInfo.CardInfo(card2, new List <decimal> {
                    1, 1
                }, 0);                                                                                           // Unplayed
                var card3 = Database.GetCardFromName("Ice Block");
                card3.IsCreated = true;
                var cardInfo3 = new PredictionInfo.CardInfo(card3, 1);                 // Created and Played
                var card4     = Database.GetCardFromName("Cryomancer");
                var cardInfo4 = new PredictionInfo.CardInfo(card4, new List <decimal> {
                    1, 1
                }, 0);
                var card5     = Database.GetCardFromName("Polymorph");
                var cardInfo5 = new PredictionInfo.CardInfo(card5, new List <decimal> {
                    .5m, 1
                }, 0);
                cardList.Add(cardInfo0);
                cardList.Add(cardInfo1);
                cardList.Add(cardInfo2);
                cardList.Add(cardInfo3);
                cardList.Add(cardInfo4);
                cardList.Add(cardInfo5);
            }
            cardList = cardList
                       .OrderBy(cardInfo => cardInfo.Card.Cost)
                       .ThenBy(cardInfo => cardInfo.Card.Name)
                       .ToList();
            var prediction = new PredictionInfo(1, 30, 4, 5, cardList, new List <PredictionInfo.CardInfo> {
            });

            SetEnabled(true);
            OnPredictionUpdate(prediction);
        }
Пример #4
0
        public void UpdatePrediction()
        {
            // Make CardInfos for all cards that have already been played
            var cardInfos = _opponent.KnownCards
                            .Select(card =>
            {
                var playedCard       = Database.GetCardFromId(card.Id);
                playedCard.Count     = card.Count;
                playedCard.IsCreated = card.IsCreated;
                var numPlayed        = card.Jousted ? 0 : playedCard.Count;
                return(new PredictionInfo.CardInfo(playedCard, numPlayed));
            }).ToList();

            // Get the predicted cards from the original deck list and group them together by id.
            // Then find the ones that have already been played and update their probabilities.
            // Otherwise, make a new CardInfo with the predicted cards.
            _predictor.PredictedCards
            .GroupBy(predictedCard => predictedCard.Card.Id, predictedCard => predictedCard)
            .ToList()
            .ForEach(group =>
            {
                // Find a played card that started in the original deck
                var playedCardInfo = cardInfos.FirstOrDefault(cardInfo => cardInfo.Card.Id == group.Key &&
                                                              cardInfo.Card.Collectible && !cardInfo.Card.IsCreated);
                var probabilities     = group.Select(predictedCard => predictedCard.Probability).ToList();
                int numPredictedCards = probabilities.Count;
                if (playedCardInfo != null)
                {
                    playedCardInfo.Card.Count = Math.Max(numPredictedCards, playedCardInfo.Card.Count);
                    playedCardInfo.Probabilities.AddRange(probabilities);
                }
                else
                {
                    // This predicted card hasn't been played yet.
                    var card   = Database.GetCardFromId(group.Key);
                    card.Count = numPredictedCards;
                    cardInfos.Add(new PredictionInfo.CardInfo(card, probabilities, 0));
                }
            });

            var predictedCards = cardInfos
                                 .OrderBy(cardInfo => cardInfo.Card.Cost)
                                 .ThenBy(cardInfo => cardInfo.Card.Name)
                                 .ThenBy(cardInfo => cardInfo.Card.IsCreated)
                                 .ToList();
            var runnerUps = _predictor.GetNextPredictedCards(30).Select(cardInfo =>
            {
                // Don't group runnerUps, they all should have a count of 1 and are unplayed.
                var card          = Database.GetCardFromId(cardInfo.Card.Id);
                var probabilities = new List <decimal> {
                    cardInfo.Probability
                };
                return(new PredictionInfo.CardInfo(card, probabilities, 0));
            }).ToList();

            var predictionInfo = new PredictionInfo(
                _predictor.PossibleDecks.Count, _predictor.PossibleCards.Count,
                _predictor.AvailableMana, _predictor.AvailableManaWithCoin, predictedCards, runnerUps);

            _predictionLog.Write(predictionInfo);
            OnPredictionUpdate.ForEach(callback => callback.Invoke(predictionInfo));
        }