Beispiel #1
0
 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));
 }
Beispiel #2
0
        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);
        }
Beispiel #3
0
 private bool HasPair(ProblemState stateData)
 {
     if (stateData.PlayerHand.Cards.Count > 2)
     {
         return(false);
     }
     return(stateData.PlayerHand.Cards[0].Rank == stateData.PlayerHand.Cards[1].Rank);
 }
Beispiel #4
0
 private bool StandIf(bool value, ProblemState state)
 {
     // pass through the value, but register the vote
     if (value)
     {
         state.VotesForStand++;
     }
     return(value);
 }
Beispiel #5
0
 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);
 }
Beispiel #6
0
        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;
        }
Beispiel #7
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);
        }
Beispiel #8
0
 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);
 }
Beispiel #9
0
 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);
 }
Beispiel #10
0
        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);
        }
Beispiel #11
0
 private bool HandVal20(ProblemState stateData)
 {
     return(stateData.PlayerHand.HandValue() == 20);
 }
Beispiel #12
0
 private bool HandVal19(ProblemState stateData)
 {
     return(stateData.PlayerHand.HandValue() == 19);
 }
Beispiel #13
0
 private bool HasPairAces(ProblemState stateData)
 {
     return(HasPairOf(Card.Ranks.Ace, stateData.PlayerHand));
 }
 private bool DealerShows8(ProblemState stateData)
 {
     return(stateData.DealerUpcard.Rank == Card.Ranks.Eight);
 }
Beispiel #15
0
 private bool HasPairEights(ProblemState stateData)
 {
     return(HasPairOf(Card.Ranks.Eight, stateData.PlayerHand));
 }
Beispiel #16
0
 private bool HasPairSevens(ProblemState stateData)
 {
     return(HasPairOf(Card.Ranks.Seven, stateData.PlayerHand));
 }
 private bool DealerShows10(ProblemState stateData)
 {
     return(stateData.DealerUpcard.RankValueHigh == 10);
 }
Beispiel #18
0
 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);
 }
Beispiel #20
0
 private bool Holding4PlusCards(ProblemState stateData)
 {
     return(stateData.PlayerHand.Cards.Count >= 4);
 }
Beispiel #21
0
 private bool Holding3Cards(ProblemState stateData)
 {
     return(stateData.PlayerHand.Cards.Count == 3);
 }
 private bool DealerShows7(ProblemState stateData)
 {
     return(stateData.DealerUpcard.Rank == Card.Ranks.Seven);
 }
Beispiel #23
0
 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);
 }