private void EvaluateEV() { shoe_ev = Eval.ShoeEv(shoe.ToArray(), max_bet); ev_evaluated = true; Console.WriteLine("Shoe EV: " + shoe_ev); }
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); }
public override bool TakeInsurance(CardSet seen_cards) { Shoe tmp_shoe = shoe.Copy(); tmp_shoe.Remove(seen_cards); double insurance_ev = Eval.InsuranceEv(current_bet, tmp_shoe.ToArray()); if (insurance_ev >= 0.0) { game_logger.Insurance(true); insurance_taken = true; return(true); } return(false); }
static void MakeTestRun(int run_number, Random random, int targetRuns, double ev_cutoff, BettingSystem betting_system, ResetSystem reset) { Console.WriteLine(run_number + " - EV cutoff " + ev_cutoff + " " + betting_system); TextWriter deal_file = new StreamWriter(string.Format("expected{0}.txt", run_number)); TextWriter roll_file = new StreamWriter(string.Format("roll{0}.txt", run_number)); double pp_multiplier = 0; Rules rules = new Rules { Decks = 8, MinBet = 100, MaxBet = 20000, Splits = 3 }; //OptStrategy b = new OptStrategy(10000, ev_cutoff, pp_multiplier); BasicStrategy b = new BasicStrategy(20000, ev_cutoff, pp_multiplier, betting_system); Game game = new Game(rules, b, pp_multiplier, random); int start_roll = 20000 * 100; //game.PlayerMoney = 10000000; // 100000$ game.PlayerMoney = start_roll; double expected_money = (double)game.PlayerMoney; game.Bet = 100; // 1$ double lowest = TotalMoney(game), highest = TotalMoney(game); int runs = 0; double total_big_bet_ev = 0; double total_big_bet = 0; int num_big_bets = 0; int resets = 0; int reset_counter = 0; bool written_200k = false; while (true) { double total_money = TotalMoney(game); if (total_money < lowest) { lowest = total_money; } if (total_money > highest) { highest = total_money; } if (runs % 5000 == 0) { Console.WriteLine(runs + " " + (double)game.PlayerMoney / 100.0 + "$" + " pp: " + game.PartyPoints + " expected: " + expected_money / 100.0 + "$"); Console.WriteLine("lowest: " + (double)lowest + "$" + " highest: " + (double)highest + "$"); Console.WriteLine("Total: ${0}", game.PlayerMoney / 100.0); Console.WriteLine("Expected: ${0}", expected_money / 100.0); /*Console.WriteLine("Average big bet: {0:0.00} ({1:0.0000})", * (total_big_bet / 100.0) / num_big_bets, * (total_big_bet_ev / 100.0) / num_big_bets); * Console.WriteLine("Resets {0} ({1:0.000}%)", resets, resets / (double)runs); */ Console.WriteLine(); } if (game.PlayerMoney <= 0) { deal_file.WriteLine(expected_money / 100.0); roll_file.WriteLine(game.PlayerMoney / 100.0); Write200kResult(0); WriteFinalResult(0); break; } if (runs % 1000 == 0) { //file.WriteLine(string.Format("{0} {1} {2} {3} {4} {5}", runs, game.PlayerMoney / 100.0, game.PartyPoints, total_money, lowest, highest)); deal_file.WriteLine(expected_money / 100.0); roll_file.WriteLine(game.PlayerMoney / 100.0); if (runs >= targetRuns) { if (!written_200k) { Write200kResult(game.PlayerMoney / 100.0); written_200k = true; } if (game.PlayerMoney >= start_roll) { WriteFinalResult(game.PlayerMoney / 100.0); break; } } //if (game.party_points >= 20000) break; } if (reset_counter > 0) { reset_counter--; runs++; continue; } if (reset != null && reset.Reset(52 * game.Rules.Decks - game.Shoe.Count, b.ShoeEV())) { resets++; runs++; reset_counter = 1; game.ResetShoe(); continue; } b.CurrentRoll = game.PlayerMoney; Shoe shoe = new Shoe(8); shoe.Clear(); shoe.Add(game.Shoe); game.StartRound(); game.DealRound(); Card p1 = game.PlayerHandSet[0][0], p2 = game.PlayerHandSet[0][1], d = game.DealerHand[0]; shoe.Remove(p1); shoe.Remove(p2); shoe.Remove(d); BjEval.Eval.CacheDealerProbs(d.PointValue, shoe.ToArray()); double deal_ev = BjEval.Eval.DealEv( p1.PointValue, p2.PointValue, d.PointValue, shoe.ToArray(), game.Bet); //Console.WriteLine("EV: {0} {1} {2} {3} {4}", p1.PointValue, p2.PointValue, d.PointValue, shoe.CardCount, deal_ev); expected_money += deal_ev * game.Bet; if (game.Bet > 100) { total_big_bet += game.Bet; total_big_bet_ev += game.Bet * deal_ev; num_big_bets++; } runs++; } deal_file.Close(); roll_file.Close(); b.Stop(); }
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; }
static void MakeTestRun(int run_number, Random random, int targetRuns, double ev_cutoff, BettingSystem betting_system, ResetSystem reset) { Console.WriteLine(run_number + " - EV cutoff " + ev_cutoff + " " + betting_system); TextWriter deal_file = new StreamWriter(string.Format("expected{0}.txt", run_number)); TextWriter roll_file = new StreamWriter(string.Format("roll{0}.txt", run_number)); double pp_multiplier = 0; Rules rules = new Rules { Decks = 8, MinBet = 100, MaxBet = 20000, Splits = 3 }; //OptStrategy b = new OptStrategy(10000, ev_cutoff, pp_multiplier); BasicStrategy b = new BasicStrategy(20000, ev_cutoff, pp_multiplier, betting_system); Game game = new Game(rules, b, pp_multiplier, random); int start_roll = 20000 * 100; //game.PlayerMoney = 10000000; // 100000$ game.PlayerMoney = start_roll; double expected_money = (double)game.PlayerMoney; game.Bet = 100; // 1$ double lowest = TotalMoney(game), highest = TotalMoney(game); int runs = 0; double total_big_bet_ev = 0; double total_big_bet = 0; int num_big_bets = 0; int resets = 0; int reset_counter = 0; bool written_200k = false; while (true) { double total_money = TotalMoney(game); if (total_money < lowest) lowest = total_money; if (total_money > highest) highest = total_money; if (runs % 5000 == 0) { Console.WriteLine(runs + " " + (double)game.PlayerMoney / 100.0 + "$" + " pp: " + game.PartyPoints + " expected: " + expected_money / 100.0 + "$"); Console.WriteLine("lowest: " + (double)lowest + "$" + " highest: " + (double)highest + "$"); Console.WriteLine("Total: ${0}", game.PlayerMoney/100.0); Console.WriteLine("Expected: ${0}", expected_money/100.0); /*Console.WriteLine("Average big bet: {0:0.00} ({1:0.0000})", (total_big_bet / 100.0) / num_big_bets, (total_big_bet_ev / 100.0) / num_big_bets); Console.WriteLine("Resets {0} ({1:0.000}%)", resets, resets / (double)runs); */ Console.WriteLine(); } if (game.PlayerMoney <= 0) { deal_file.WriteLine(expected_money / 100.0); roll_file.WriteLine(game.PlayerMoney / 100.0); Write200kResult(0); WriteFinalResult(0); break; } if (runs % 1000 == 0) { //file.WriteLine(string.Format("{0} {1} {2} {3} {4} {5}", runs, game.PlayerMoney / 100.0, game.PartyPoints, total_money, lowest, highest)); deal_file.WriteLine(expected_money / 100.0); roll_file.WriteLine(game.PlayerMoney / 100.0); if (runs >= targetRuns) { if (!written_200k) { Write200kResult(game.PlayerMoney / 100.0); written_200k = true; } if (game.PlayerMoney >= start_roll) { WriteFinalResult(game.PlayerMoney / 100.0); break; } } //if (game.party_points >= 20000) break; } if (reset_counter > 0) { reset_counter--; runs++; continue; } if (reset!=null && reset.Reset(52 * game.Rules.Decks - game.Shoe.Count, b.ShoeEV())) { resets++; runs++; reset_counter = 1; game.ResetShoe(); continue; } b.CurrentRoll = game.PlayerMoney; Shoe shoe = new Shoe(8); shoe.Clear(); shoe.Add(game.Shoe); game.StartRound(); game.DealRound(); Card p1 = game.PlayerHandSet[0][0], p2 = game.PlayerHandSet[0][1], d = game.DealerHand[0]; shoe.Remove(p1); shoe.Remove(p2); shoe.Remove(d); BjEval.Eval.CacheDealerProbs(d.PointValue, shoe.ToArray()); double deal_ev = BjEval.Eval.DealEv( p1.PointValue, p2.PointValue, d.PointValue, shoe.ToArray(), game.Bet); //Console.WriteLine("EV: {0} {1} {2} {3} {4}", p1.PointValue, p2.PointValue, d.PointValue, shoe.CardCount, deal_ev); expected_money += deal_ev * game.Bet; if (game.Bet > 100) { total_big_bet += game.Bet; total_big_bet_ev += game.Bet * deal_ev; num_big_bets++; } runs++; } deal_file.Close(); roll_file.Close(); b.Stop(); }