Inheritance: IComparable
Example #1
0
        public void Action(Card dealer_upcard, CardSet[] player_hands, int active_hand_index, List<ActionEv> actions)
        {
            ActionInfo info = new ActionInfo() {
                hand_index = active_hand_index,
                player_cards = player_hands[active_hand_index],
                action_evs = actions.ToArray()
            };

            action_history.Add(info);
        }
        // seen_cards include active_hand's cards
        public override ActionType GetAction(CardSet seen_cards, Card dealer_upcard, CardSet[] player_hands, int active_hand, List<ActionType> available_actions)
        {
            List<ActionEv> actions = GetActions(seen_cards, dealer_upcard, player_hands, active_hand, available_actions);

            ActionType best = actions[0].Action;

            if (best == ActionType.Split)
            {
                split_count++;
            }
            else if (best == ActionType.Double)
            {
                hand_doubled[active_hand] = true;
            }
            else if (best == ActionType.Surrender)
            {
                surrendered = true;
            }

            action_count++;

            return best;
        }
Example #3
0
        // splits the active hand to two new hands
        public void Split(Card card1, Card card2)
        {
            Hand[] split_hands = ActiveHand.Split(card1, card2);

            hands.Add(split_hands[0]);
            hands.Add(split_hands[1]);
        }
Example #4
0
 private void RemoveCount(Card card)
 {
     card_counts[card.PointValue - 1]--;
 }
Example #5
0
 public void Add(Card card)
 {
     card_set.Add(card);
     AddCount(card);
 }
Example #6
0
 public CardSet(Card[] cards)
     : this(cards.Length)
 {
     this.Add(cards);
     UpdateCount();
 }
Example #7
0
 private void AddCount(Card card)
 {
     card_counts[card.PointValue - 1]++;
 }
Example #8
0
 public void AddCard(Card card)
 {
     cards.Add(card);
 }
Example #9
0
 public void Remove(Card card)
 {
     if (card_set.Remove(card))
         RemoveCount(card);
 }
Example #10
0
        private List<ActionEv> Evaluate(Card upcard, Hand hand)
        {
            shell.StandardInput.WriteLine(upcard.PointValue);
            shell.StandardInput.WriteLine(hand.Count);

            foreach (Card card in hand)
                shell.StandardInput.WriteLine(card.PointValue);

            string line = "";
            List<ActionEv> actions = new List<ActionEv>();
            while (true)
            {
                line = shell.StandardOutput.ReadLine();

                if (line.StartsWith("done"))
                    break;

                ActionEv action_ev = new ActionEv();

                string[] param = line.Split(new char[] { ' ' });

                action_ev.Ev = double.Parse(param[1]);
                if (param[0] == "Surrender")
                    action_ev.Action = ActionType.Surrender;
                else if (param[0] == "Hit")
                    action_ev.Action = ActionType.Hit;
                else if (param[0] == "Stand")
                    action_ev.Action = ActionType.Stand;
                else if (param[0] == "Double")
                    action_ev.Action = ActionType.Double;
                else if (param[0] == "Split")
                    action_ev.Action = ActionType.Split;
                else
                    Console.WriteLine("BIG F*****G UPS!!!!!");

                actions.Add(action_ev);
            }

            actions.Sort(delegate(ActionEv ae1, ActionEv ae2) { return ae2.Ev.CompareTo(ae1.Ev); });

            /*Console.WriteLine("Upcard: " + upcard + " Hand: " + hand);
            foreach (ActionEv ae in actions)
                Console.WriteLine(ae.Action + " " + ae.Ev);
            Console.ReadKey();*/

            return actions;
        }
Example #11
0
 public override void DealCard(Card card)
 {
     primary.DealCard(card);
     secondary.DealCard(card);
 }
        public List<ActionEv> GetActions(CardSet seen_cards, Card dealer_upcard, CardSet[] player_hands, int active_hand, List<ActionType> available_actions)
        {
            ValidateActions(player_hands[active_hand], available_actions);

            Shoe tmp_shoe = shoe.Copy();
            tmp_shoe.Remove(seen_cards);

            Eval.CacheDealerProbs(dealer_upcard.PointValue, tmp_shoe.ToArray());

            List<ActionEv> actions = new List<ActionEv>();

            foreach (ActionType a in available_actions)
            {
                double ev = GetActionEV(tmp_shoe, player_hands[active_hand], a, dealer_upcard);

                actions.Add(new ActionEv() { Action = a, Ev = ev });
            }

            actions.Sort(delegate(ActionEv ae1, ActionEv ae2) { return ae2.Ev.CompareTo(ae1.Ev); });

            game_logger.Action(dealer_upcard, player_hands, active_hand, actions);

            return actions;
        }
        private double GetActionEV(Shoe tmp_shoe, CardSet active_hand, ActionType action, Card dealer_upcard)
        {
            Hand hand = new Hand(active_hand);

            SHand shand;
            int soft_total = hand.SoftTotal();
            if (soft_total <= 21 && hand.HasAce())
            {
                shand.Total = soft_total;
                shand.Soft = true;
            }
            else
            {
                shand.Total = hand.HardTotal();
                shand.Soft = false;
            }

            int[] shoe_counts = tmp_shoe.ToArray();
            int upcard = dealer_upcard.PointValue;

            switch (action)
            {
                case ActionType.Stand:

                    return Eval.StandEv(shand, upcard, shoe_counts);

                case ActionType.Hit:

                    return Eval.HitEv(shand, upcard, shoe_counts);

                case ActionType.Double:

                    return Eval.DoubleEv(shand, upcard, current_bet, shoe_counts);

                case ActionType.Split:

                    return Eval.SplitEv(active_hand[0].PointValue, upcard, current_bet, max_splits - split_count, shoe_counts);

                case ActionType.Surrender:

                    return Eval.SurrenderEv();
            }

            return -1;
        }
Example #14
0
 // seen_cards include active_hand's cards
 public abstract ActionType GetAction(CardSet seen_cards, Card dealer_upcard, CardSet[] player_hands, int active_hand, List<ActionType> available_actions);
Example #15
0
 public void Remove(Card card)
 {
     total--;
     counts[card.PointValue - 1]--;
 }
Example #16
0
        // splits this hand to two new hands
        public Hand[] Split(Card card1, Card card2)
        {
            Hand[] hands = new Hand[] { new Hand(), new Hand() };

            hands[0].AddCard(cards[0]);
            hands[1].AddCard(cards[1]);

            hands[0].AddCard(card1);
            hands[1].AddCard(card2);

            //hands[0].Bet = this.bet;
            //hands[1].Bet = this.bet;

            if (cards[0].IsAce() && cards[1].IsAce())
            {
                hands[0].from_aces = true;
                hands[1].from_aces = true;
            }

            this.split = true;

            return hands;
        }
Example #17
0
 public void Hit(Card card)
 {
     cards.Add(card);
     hit_count++;
 }
Example #18
0
 public void Double(Card card)
 {
     cards.Add(card);
     doubled = true;
 }
Example #19
0
 public override void DealCard(Card card)
 {
     card_counter.RemoveCard(card.PointValue);
 }
Example #20
0
 public void Add(Card[] cards)
 {
     card_set.AddRange(cards);
     foreach (Card card in cards)
         AddCount(card);
 }
Example #21
0
        public void Add(string cards)
        {
            string[] split = cards.Split(new char[] { ' ' });

            for (int i = 0; i < split.Length; i++)
            {
                Card c = new Card(split[i]);
                Add(c);
            }
        }
Example #22
0
 public virtual void DealCard(Card card)
 {
 }