Пример #1
0
        public Game(Rules rules, Agent agent, double pp_multiplier, Random random)
        {
            dealer_hand = new Hand();
            player_handset = new HandSet();
            shoe = new CardSet();

            this.rules = rules;
            this.agent = agent;
            this.pp_multiplier = pp_multiplier;
            this.random = random;

            this.player_money = 0;
            this.bet = rules.MinBet;
            this.split_count = 0;

            party_points = 0;

            ResetShoe();
        }
Пример #2
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;
        }
Пример #3
0
        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;
        }
Пример #4
0
        private int ExpectedMoney(Hand dealer, Hand[] player)
        {
            int game_bet = 100 * current_bet;
            int expected_money = 0;

            if (insurance_taken)
            {
                expected_money -= game_bet / 2;

                if (dealer.IsNatural()) expected_money += 3 * game_bet / 2;
            }

            if (surrendered)
            {
                expected_money -= game_bet / 2;
            }
            else
            {
                foreach (Hand hand in player)
                {
                    int hand_bet = hand.Doubled ? (game_bet * 2) : game_bet;

                    expected_money -= hand_bet;

                    if (dealer.IsNatural())
                    {
                        if (hand.IsNatural()) expected_money += hand_bet;
                    }
                    else if (split_count == 0 && hand.IsNatural())
                    {
                        expected_money += 2 * hand_bet + hand_bet / 2;
                    }
                    else if (dealer.IsBust())
                    {
                        if (!hand.IsBust())
                        {
                            expected_money += 2 * hand_bet;
                        }
                    }
                    else if (!hand.IsBust())
                    {
                        int player_total = hand.PointCount();
                        int dealer_total = dealer.PointCount();

                        if (player_total < dealer_total)
                        {
                            // do nothing, we lose our bet
                        } // we win, 2:1 payout
                        else if (dealer_total < player_total)
                        {
                            expected_money += 2 * hand_bet;
                        } // push
                        else
                        {
                            expected_money += hand_bet;
                        }
                    }
                }
            }

            return expected_money;
        }
Пример #5
0
        public override void RoundOver(CardSet seen_cards, CardSet dealer_hand, CardSet[] player_hands, long game_id, int roll_after)
        {
            Hand dealer = new Hand(dealer_hand);

            Hand[] player = new Hand[player_hands.Length];
            for (int i = 0; i < player.Length; i++)
            {
                player[i] = new Hand(player_hands[i]);
                player[i].Doubled = hand_doubled[i];
            }

            int actual_money = roll_after - roll_before;
            int expected_money = ExpectedMoney(dealer, player);

            if (game_id > 0 && game_id == last_game_id)
            {
                throw new Exception("game_id == last_game_id");
            }

            if (action_count == 0)
            {
                bool dealer_natural = dealer.IsNatural();
                bool player_natural = player.Count() == 1 && player[0].IsNatural();

                if (!dealer_natural && !player_natural)
                {
                    throw new Exception("No actions made and no BJ");
                }
                else
                {
                    if (actual_money == 0)
                    {
                        if (dealer_natural && insurance_taken)
                        {
                            // this is correct
                        }
                        else if (!(dealer_natural && player_natural))
                        {
                            throw new Exception("BJ but no roll change (and no push)");
                        }
                    }
                }
            }

            game_logger.Showdown(dealer_hand, player_hands, game_id, expected_money, actual_money);
            Console.WriteLine("Roll: " + roll_after);

            last_game_id = game_id;

            if (expected_money != actual_money)
            {
                if (Config.Current.GetBooleanProperty("ThrowMoneyException"))
                {
                    throw new MoneyMismatchException(expected_money, actual_money);
                }
                else
                {
                    Console.WriteLine();
                    Console.WriteLine("EXPECTED MONEY MISMATCH!");
                    Console.WriteLine();
                }
            }

            shoe.Remove(seen_cards);

            if (shoe.FullCount - shoe.CardCount >= 84)
            {
                shoe.Reset();
            }

            Console.WriteLine("Seen cards: " + seen_cards);
            Console.WriteLine("Removed from shoe: {0} ({1})", shoe.FullCount - shoe.CardCount, seen_cards.Count);

            InitializeRound();
        }
Пример #6
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;
        }
Пример #7
0
 public SHand(Hand hand)
 {
     int soft_total = hand.SoftTotal();
     if (soft_total <= 21 && hand.HasAce())
     {
         this.Total = soft_total;
         this.Soft = true;
     }
     else
     {
         this.Total = hand.HardTotal();
         this.Soft = false;
     }
 }