GR.Gambling.Blackjack.GameLogger.Showdown C# (CSharp) Method

Showdown() public method

public Showdown ( CardSet dealer_hand, CardSet player_hands, long game_id, int expected_money, int actual_money ) : void
dealer_hand CardSet
player_hands CardSet
game_id long
expected_money int
actual_money int
return void
        public void Showdown(CardSet dealer_hand, CardSet[] player_hands, long game_id, int expected_money, int actual_money)
        {
            if (game_id <= 0)
            {
                long ticks = DateTime.Now.ToUniversalTime().Ticks;
                TimeSpan time = new TimeSpan(ticks);
                game_id = ((long)(time.TotalSeconds * 10)) % (int.MaxValue);
            }

            TextWriter file = new StreamWriter("gamelog.txt", true);

            file.WriteLine("GameStart {0}", game_id);
            file.WriteLine("Time {0}", DateTime.Now.ToUniversalTime().ToString(new CultureInfo("en-US", true)));
            file.WriteLine("Bet {0}", bet_size);
            file.WriteLine("Shoe {0}", shoe);
            file.WriteLine("ShoeEv {0}", shoe_ev);
            file.WriteLine("Insurance {0}", take_insurance);

            foreach (ActionInfo action in action_history)
            {
                file.Write("Action {0} | {1}", action.hand_index, action.player_cards);

                foreach (ActionEv ev in action.action_evs)
                {
                    file.Write(" | {0} {1}", ev.Action, ev.Ev);
                }

                file.WriteLine();
            }

            for (int i=0; i<player_hands.Length; i++)
            {
                file.WriteLine("Showdown {0} | {1}", i, player_hands[i]);
            }

            file.WriteLine("Dealer {0}", dealer_hand);
            file.WriteLine("ExpectedMoney {0}", expected_money);
            file.WriteLine("ActualMoney {0}", actual_money);
            file.WriteLine("GameEnd {0}", game_id);
            file.WriteLine();

            file.Close();

            Console.WriteLine("Game ID: " + game_id);
            Console.WriteLine("Expected: " + expected_money);
            Console.WriteLine("Actual:   " + actual_money);
        }

Usage Example

        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();
        }