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)); }
public bool IsSatisfiedBy(Strategy strategy) { if(MiddleChoice != null && !MiddleChoice.Equals(strategy.middleChoice)) return false; if (HigherChoice != null && !HigherChoice.Equals(strategy.higherChoice)) return false; if (LowerChoice != null && !LowerChoice.Equals(strategy.lowerChoice)) return false; return true; }
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; }
public double GetStrategyFitness(Strategy strategy, double aggressiveness) { if (aggressiveness < 0 || aggressiveness > 1) { throw new ArgumentException("The aggressiveness has to be between 0 and 1."); } // // The maximum number of user drinks is 11, and the maximum number of dealer drinks is 10. // We normalize user and dealer drinks w.r.t. these values. // // normalizedUserDrinks == 1 => 0 drinks. // normalizedDealerDrinks == 1 => 10 drinks. // double normalizedUserDrinks = drinksMap[strategy].NormalizedUserDrinks; double normalizedDealerDrinks = drinksMap[strategy].NormalizedDealerDrinks; return normalizedUserDrinks * (1 - aggressiveness) + normalizedDealerDrinks * aggressiveness; }
public void ComputeConditionalDrinks(Strategy strategy, Dictionary<CardValue, double> likelihoods) { ExpectedDrinks drinksIfLower = ComputeDrinksIfLower(strategy, strategy.middleChoice, likelihoods); ExpectedDrinks drinksIfHigher = ComputeDrinksIfHigher(strategy, strategy.middleChoice, likelihoods); UserDrinksIfHigher = drinksIfHigher.UserDrinks; DealerDrinksIfHigher = drinksIfHigher.DealerDrinks; UserDrinksIfLower = drinksIfLower.UserDrinks; DealerDrinksIfLower = drinksIfLower.DealerDrinks; }
private void paintStrategy(Strategy strategy, bool isAlwaysOptimal) { Color defaultBackgroundColor = (Color)Resources["PhoneBackgroundColor"]; Color defaultBorderColor = (Color)Resources["PhoneBorderColor"]; Color defaultForegroundColor = (Color)Resources["PhoneForegroundColor"]; for (int card = CardDeck.kLowestCardValue; card <= CardDeck.kHighestCardValue; card++) { Button cardButton = findCardButton(new CardValue(card)); if (cardButton.IsEnabled) { cardButton.BorderBrush = new SolidColorBrush(defaultBorderColor); cardButton.Background = new SolidColorBrush(defaultBackgroundColor); cardButton.Foreground = new SolidColorBrush(defaultForegroundColor); cardButton.Opacity = 1.0; } } Color accentColor = (Color)Resources["PhoneAccentColor"]; Color goldColor = Color.FromArgb(255, 212, 175, 55); Color strategyColor = accentColor; if (isAlwaysOptimal) { strategyColor = goldColor ; // gold } paintMiddleChoice(strategy.middleChoice, strategyColor); paintSecondChoices(strategy.lowerChoice, strategy.middleChoice, strategyColor); paintSecondChoices(strategy.higherChoice, strategy.middleChoice, strategyColor); if (currentConstraint.MiddleChoice != null && !currentConstraint.MiddleChoice.Equals(currentUnconstrainedStrategy.middleChoice) && !currentUnconstrainedStrategy.middleChoice.Equals(strategy.lowerChoice) && !currentUnconstrainedStrategy.middleChoice.Equals(strategy.higherChoice)) { Color fadedColor = isUnconstrainedAlwaysOptimal ? goldColor : accentColor; paintFadedButton(currentUnconstrainedStrategy.middleChoice, fadedColor); } //UserDrinksLabel.Text = String.Format("{0:.##}", strategy.GetExpectedUserDrinks(deck.CardsLikelihoods())); //DealerDrinksLabel.Text = String.Format("{0:.##}", strategy.GetExpectedDealerDrinks(deck.CardsLikelihoods())); }
private void computeOptimalStrategy(double aggressiveness) { if (strategyEvaluator == null) return; currentOptimalStrategy = strategyEvaluator.GetBestStrategyWithConstraints(currentConstraint, aggressiveness); currentExpectedDrinks = strategyEvaluator.GetExpectedDrinks(currentOptimalStrategy); if (currentConstraint.AreAllNull()) { currentUnconstrainedStrategy = currentOptimalStrategy; currentUnconstrainedDrinks = currentExpectedDrinks; } bool isAlwaysOptimal = IsCurrentOptimalStable() && (currentConstraint.IsSatisfiedBy(currentUnconstrainedStrategy)); if (currentConstraint.AreAllNull()) { isUnconstrainedAlwaysOptimal = isAlwaysOptimal; } paintStrategy(currentOptimalStrategy, isAlwaysOptimal); }
private ExpectedDrinks GetStrategyDrinks(Strategy strategy) { ExpectedDrinks drinks = new ExpectedDrinks(strategy.GetExpectedUserDrinks(likelihoods), strategy.GetExpectedDealerDrinks(likelihoods)); drinks.ComputeConditionalDrinks(strategy, likelihoods); return drinks; }
public ExpectedDrinks GetExpectedDrinks(Strategy strategy) { return drinksMap[strategy]; }