private static CardValue CardValueFromButton(Button cardButton)
 {
     string name = cardButton.Name;
     int numericValue = int.Parse(name.Split(new string[] { "_" }, StringSplitOptions.RemoveEmptyEntries)[1]);
     CardValue cardValue = new CardValue(numericValue);
     return cardValue;
 }
        public static ExpectedDrinks ComputeDrinksIfLower(Strategy strategy, CardValue lowerThan, Dictionary<CardValue, double> likelihoods)
        {
            Dictionary<CardValue, double> normalizedLowerLikelihoods = GetNormalizedLikelihoods(
                likelihoods.Where(x => x.Key.Value < lowerThan.Value));

            return new ExpectedDrinks(strategy.GetExpectedUserDrinks(normalizedLowerLikelihoods),
                                strategy.GetExpectedDealerDrinks(normalizedLowerLikelihoods));
        }
Beispiel #3
0
 private Strategy FindOptimalStrategy(CardValue middleChoice, CardDeck deck)
 {
     IEnumerable<Card> cardsLower = deck.Cards.Where(card => card.Value.Value < middleChoice.Value);
     IEnumerable<Card> cardsHigher = deck.Cards.Where(card => card.Value.Value > middleChoice.Value);
     Strategy optimalStrategy = new Strategy(
         middleChoice,
         FindClosestExistingCard(ExpectedCardValue(cardsLower), cardsLower),
         FindClosestExistingCard(ExpectedCardValue(cardsHigher), cardsHigher));
     return optimalStrategy;
 }
Beispiel #4
0
 private CardValue FindClosestExistingCard(double d, IEnumerable<Card> cards)
 {
     double minimumDistance = Double.PositiveInfinity;
     CardValue closestCard = new CardValue(-1);
     foreach (Card card in cards.Where(c => c.NumberLeft > 0))
     {
         double distance = Math.Abs(d - card.Value.Value);
         if (distance < minimumDistance)
         {
             closestCard = card.Value;
             minimumDistance = distance;
         }
     }
     return closestCard;
 }
 public void Reset()
 {
     this.MiddleChoice = this.LowerChoice = this.HigherChoice = null;
 }
 private void paintMiddleChoice(CardValue value, Color color)
 {
     Button middleButton = findCardButton(value);
     if (middleButton.IsEnabled)
     {
         middleButton.Background = new SolidColorBrush(color);
     }
 }
 private void paintSecondChoices(CardValue value, CardValue middleChoice, Color color)
 {
     Button button = findCardButton(value);
     if (button.IsEnabled && value.Value != middleChoice.Value)
     {
         button.BorderBrush = new SolidColorBrush(color);
         button.Foreground = new SolidColorBrush(color);
     }
 }
 private void ForceMiddleChoice(CardValue middleChoice)
 {
     //Strategy optimalStrategy = stra
     currentConstraint.Reset();
     if (middleChoice.Value != currentUnconstrainedStrategy.middleChoice.Value)
     {
         currentConstraint.MiddleChoice = middleChoice;
     }
     ConstraintsChanged();
 }
 private void paintFadedButton(CardValue cardValue, Color color)
 {
     Button middleButton = findCardButton(cardValue);
     if (middleButton.IsEnabled)
     {
         middleButton.Background = new SolidColorBrush(color);
         middleButton.Opacity = 0.4;
     }
 }
 private Button findCardButton(CardValue value)
 {
     return (Button)this.FindName("Card_" + value.Value);
 }
 private void ForceLowerChoice(CardValue lowerChoice)
 {
     if (lowerChoice.Value < currentOptimalStrategy.middleChoice.Value)
     {
         currentConstraint.MiddleChoice = currentOptimalStrategy.middleChoice;
         currentConstraint.LowerChoice = lowerChoice;
         currentConstraint.HigherChoice = currentOptimalStrategy.higherChoice;
     }
     ConstraintsChanged();
 }
Beispiel #12
0
 public Card(CardValue value, CardDeck deck)
 {
     this.Value = value;
     this.NumberDealt = 0;
     this.deck = deck;
 }
Beispiel #13
0
 public Card(CardValue value)
 {
     this.Value = value;
     this.NumberDealt = 0;
 }
Beispiel #14
0
        protected Card findCardByValue(CardValue value)
        {
            foreach (Card card in Cards)
            {
                if (card.Value.Equals(value))
                {
                    return card;
                }
            }

            // there was no such card in the deck
            throw new InvalidOperationException("No such card: " + value.Value);
        }
Beispiel #15
0
 public double CardLikelihood(CardValue cardValue)
 {
     if (totalNumberCardsLeft == 0) return 0;
     return Cards.Where(c => c.Value.Equals(cardValue)).First().NumberLeft / (double)totalNumberCardsLeft;
 }
Beispiel #16
0
 public Strategy(CardValue middleChoice, CardValue lowerChoice, CardValue higherChoice)
 {
     this.middleChoice = middleChoice;
     this.lowerChoice = lowerChoice;
     this.higherChoice = higherChoice;
 }