private bool HasPairTens(ProblemState stateData) { // covers tens, jacks, queens and kings return((stateData.PlayerHand.Cards.Count == 2) && (stateData.PlayerHand.Cards[0].RankValueHigh == 10) && (stateData.PlayerHand.Cards[1].RankValueHigh == 10)); }
private static ActionToTake GetActionFromCandidate(ProblemState stateData) { int votesForStand = stateData.VotesForStand; int votesForHit = stateData.VotesForHit; int votesForDouble = stateData.VotesForDoubleDown; int votesForSplit = stateData.VotesForSplit; // there are times when all votes = 0, in which case double or split could be erroneously selected. // this code handles that situation so they never get selected if (stateData.PlayerHand.IsPair() == false) { votesForSplit = int.MinValue; } if (stateData.PlayerHand.Cards.Count > 2) { votesForDouble = int.MinValue; } List <Tuple <int, ActionToTake> > votes = new List <Tuple <int, ActionToTake> >(); votes.Add(new Tuple <int, ActionToTake>(votesForDouble, ActionToTake.Double)); votes.Add(new Tuple <int, ActionToTake>(votesForStand, ActionToTake.Stand)); votes.Add(new Tuple <int, ActionToTake>(votesForHit, ActionToTake.Hit)); votes.Add(new Tuple <int, ActionToTake>(votesForSplit, ActionToTake.Split)); var result = votes.OrderByDescending(v => v.Item1).First().Item2; return(result); }
private bool HasPair(ProblemState stateData) { if (stateData.PlayerHand.Cards.Count > 2) { return(false); } return(stateData.PlayerHand.Cards[0].Rank == stateData.PlayerHand.Cards[1].Rank); }
private bool StandIf(bool value, ProblemState state) { // pass through the value, but register the vote if (value) { state.VotesForStand++; } return(value); }
private bool SplitIf(bool value, ProblemState state) { // we don't check for validity here, since it's handled when retrieving the action if (value) { state.VotesForSplit++; } return(value); }
private static void SetupStateData(ProblemState stateData, Hand hand, Card dealerUpcard) { // prepare for testing stateData.PlayerHand = hand; stateData.DealerUpcard = dealerUpcard; stateData.VotesForDoubleDown = 0; stateData.VotesForHit = 0; stateData.VotesForStand = 0; stateData.VotesForSplit = 0; }
//------------------------------------------------------------------------- // Now terminal functions to get information about the player's hand //------------------------------------------------------------------------- private bool HasAce(ProblemState stateData) { foreach (var card in stateData.PlayerHand.Cards) { if (card.Rank == "A") { return(true); } } return(false); }
private bool DoubleIf(bool value, ProblemState state) { // double down only legal when holding 2 cards if (state.PlayerHand.Cards.Count == 2) { if (value) { state.VotesForDoubleDown++; } } return(value); }
private bool SplitIf(bool value, ProblemState state) { // only legal when holding a pair if ((state.PlayerHand.Cards.Count == 2) && (state.PlayerHand.Cards[0].Rank == state.PlayerHand.Cards[1].Rank)) { if (value) { state.VotesForSplit++; } } return(value); }
public static ActionToTake GetAction(ProblemState stateData) { int votesForStand = stateData.VotesForStand; int votesForHit = stateData.VotesForHit; int votesForDouble = stateData.VotesForDoubleDown; int votesForSplit = stateData.VotesForSplit; List <ActionWithVotes> votes = new List <ActionWithVotes>(); votes.Add(new ActionWithVotes(votesForDouble, ActionToTake.Double)); votes.Add(new ActionWithVotes(votesForStand, ActionToTake.Stand)); votes.Add(new ActionWithVotes(votesForHit, ActionToTake.Hit)); votes.Add(new ActionWithVotes(votesForDouble, ActionToTake.Double)); votes.Add(new ActionWithVotes(votesForSplit, ActionToTake.Split)); return(votes.OrderByDescending(v => v.NumVotes).First().Action); }
private bool HandVal20(ProblemState stateData) { return(stateData.PlayerHand.HandValue() == 20); }
private bool HandVal19(ProblemState stateData) { return(stateData.PlayerHand.HandValue() == 19); }
private bool HasPairAces(ProblemState stateData) { return(HasPairOf(Card.Ranks.Ace, stateData.PlayerHand)); }
private bool DealerShows8(ProblemState stateData) { return(stateData.DealerUpcard.Rank == Card.Ranks.Eight); }
private bool HasPairEights(ProblemState stateData) { return(HasPairOf(Card.Ranks.Eight, stateData.PlayerHand)); }
private bool HasPairSevens(ProblemState stateData) { return(HasPairOf(Card.Ranks.Seven, stateData.PlayerHand)); }
private bool DealerShows10(ProblemState stateData) { return(stateData.DealerUpcard.RankValueHigh == 10); }
private bool AcePlus9(ProblemState stateData) { return((stateData.PlayerHand.HandValue() - 11) == 9); }
private bool AcePlus8(ProblemState stateData) { return(stateData.PlayerHand.HasSoftAce() && (stateData.PlayerHand.HandValue() - 11) == 8); }
private bool Holding4PlusCards(ProblemState stateData) { return(stateData.PlayerHand.Cards.Count >= 4); }
private bool Holding3Cards(ProblemState stateData) { return(stateData.PlayerHand.Cards.Count == 3); }
private bool DealerShows7(ProblemState stateData) { return(stateData.DealerUpcard.Rank == Card.Ranks.Seven); }
private bool HasPairFours(ProblemState stateData) { return(HasPairOf(Card.Ranks.Four, stateData.PlayerHand)); }
//------------------------------------------------------------------------- // Now terminal functions to get information about the player's hand //------------------------------------------------------------------------- private bool HasSoftAce(ProblemState stateData) { return(stateData.PlayerHand.HasSoftAce()); }
private bool DealerShowsA(ProblemState stateData) { return(stateData.DealerUpcard.Rank == Card.Ranks.Ace); }