Ejemplo n.º 1
0
 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;
 }
Ejemplo n.º 2
0
        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));
        }
Ejemplo n.º 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;
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 5
0
 public void Reset()
 {
     this.MiddleChoice = this.LowerChoice = this.HigherChoice = null;
 }
Ejemplo n.º 6
0
 private void paintMiddleChoice(CardValue value, Color color)
 {
     Button middleButton = findCardButton(value);
     if (middleButton.IsEnabled)
     {
         middleButton.Background = new SolidColorBrush(color);
     }
 }
Ejemplo n.º 7
0
 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);
     }
 }
Ejemplo n.º 8
0
 private void ForceMiddleChoice(CardValue middleChoice)
 {
     //Strategy optimalStrategy = stra
     currentConstraint.Reset();
     if (middleChoice.Value != currentUnconstrainedStrategy.middleChoice.Value)
     {
         currentConstraint.MiddleChoice = middleChoice;
     }
     ConstraintsChanged();
 }
Ejemplo n.º 9
0
 private void paintFadedButton(CardValue cardValue, Color color)
 {
     Button middleButton = findCardButton(cardValue);
     if (middleButton.IsEnabled)
     {
         middleButton.Background = new SolidColorBrush(color);
         middleButton.Opacity = 0.4;
     }
 }
Ejemplo n.º 10
0
 private Button findCardButton(CardValue value)
 {
     return (Button)this.FindName("Card_" + value.Value);
 }
Ejemplo n.º 11
0
 private void ForceLowerChoice(CardValue lowerChoice)
 {
     if (lowerChoice.Value < currentOptimalStrategy.middleChoice.Value)
     {
         currentConstraint.MiddleChoice = currentOptimalStrategy.middleChoice;
         currentConstraint.LowerChoice = lowerChoice;
         currentConstraint.HigherChoice = currentOptimalStrategy.higherChoice;
     }
     ConstraintsChanged();
 }
Ejemplo n.º 12
0
 public Card(CardValue value, CardDeck deck)
 {
     this.Value = value;
     this.NumberDealt = 0;
     this.deck = deck;
 }
Ejemplo n.º 13
0
 public Card(CardValue value)
 {
     this.Value = value;
     this.NumberDealt = 0;
 }
Ejemplo n.º 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);
        }
Ejemplo n.º 15
0
 public double CardLikelihood(CardValue cardValue)
 {
     if (totalNumberCardsLeft == 0) return 0;
     return Cards.Where(c => c.Value.Equals(cardValue)).First().NumberLeft / (double)totalNumberCardsLeft;
 }
Ejemplo n.º 16
0
 public Strategy(CardValue middleChoice, CardValue lowerChoice, CardValue higherChoice)
 {
     this.middleChoice = middleChoice;
     this.lowerChoice = lowerChoice;
     this.higherChoice = higherChoice;
 }