コード例 #1
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));
        }
コード例 #2
0
 public CardProximityRanker(List <Deck> decks)
 {
     _decks        = decks;
     _proximityLog = new CustomLog(LogName);
     _proximityLog.Write(this);
 }