public override ActionType GetBestAction(Game game) { ActionType a1 = primary.GetBestAction(game); ActionType a2 = secondary.GetBestAction(game); if (a1 != a2 && !IsDiff) { List <ActionEv> l1 = primary.GetActions(game); Diff = 0.0; if (l1 != null) { for (int i = 0; i < l1.Count; i++) { if (l1[i].Action == a2) { Diff = l1[0].Ev - l1[i].Ev; break; } } } IsDiff = true; } return(a1); }
public override ActionType GetBestAction(Game game) { ActionType a1 = primary.GetBestAction(game); ActionType a2 = secondary.GetBestAction(game); if (a1 != a2 && !IsDiff) { List <ActionEv> l1 = primary.GetActions(game); List <ActionEv> l2 = secondary.GetActions(game); int m = 0; if (l1 != null) { m = l1.Count; } if (l2 != null && l2.Count > m) { m = l2.Count; } Console.WriteLine("STRATEGY MISMATCH"); Console.WriteLine(); Console.WriteLine(game.ToString()); Console.WriteLine(string.Format("{0,-25} {1,-25}", primary.GetType(), secondary.GetType())); Console.WriteLine(); Console.WriteLine(string.Format("{0,-25} {1,-25}", a1, a2)); Console.WriteLine(); for (int i = 0; i < m; i++) { ActionEv e1 = new ActionEv(), e2 = new ActionEv(); if (l1 != null && i < l1.Count) { e1 = l1[i]; } if (l2 != null && i < l2.Count) { e2 = l2[i]; } Console.WriteLine(string.Format("{0,-25} {1,-25}", e1, e2)); } Console.WriteLine(); Console.WriteLine(); Console.WriteLine(); } return(a1); }
public void DealRound() { player_handset.ActiveHand.AddCard(shoe.ExtractTop()); dealer_hand.AddCard(shoe.ExtractTop()); player_handset.ActiveHand.AddCard(shoe.ExtractTop()); dealer_hand.AddCard(shoe.ExtractTop()); bool dealer_natural; dealer_natural = dealer_hand.IsNatural(); // check if player has blackjack if (player_handset.ActiveHand.IsNatural()) { if (dealer_natural) { // push, return initial bet player_money += bet; EndRound(); return; } else { // player wins with blackjack, pay out 1.5:1 (with 10$ at stake, return 15$) player_money += (int)(1.5 * bet) + bet; EndRound(); return; } } int insurance = 0; // offer insurance if (Upcard().IsAce()) { if (agent.TakeInsurance(this)) { insurance = (int)(0.5 * bet); player_money -= insurance; AddPartyPoints(insurance); } } // dealer has blackjack if (dealer_natural) { if (insurance > 0) { //?????? // insurance bet pays 2:1, initial bet is lost player_money += (2 * insurance) + insurance; EndRound(); return; } else { // dealer wins with blackjack EndRound(); return; } } // main loop // keeps asking player for actions for unfinished hands until // no unfinished hands remains while (!player_handset.AllFinished()) { ActionType action = agent.GetBestAction(this); if (!IsValidAction(action)) { Console.WriteLine("Player made invalid action!"); return; } // player decides to stand, hand is over, move to next one if (ActionType.Stand == action) { player_handset.ActiveHand.Stand(); } else if (ActionType.Hit == action) { player_handset.ActiveHand.Hit(shoe.ExtractTop()); } else if (ActionType.Surrender == action) { player_handset.ActiveHand.Surrender(); } else if (ActionType.Double == action) { player_handset.ActiveHand.Double(shoe.ExtractTop()); player_money -= bet; AddPartyPoints(bet); } else if (ActionType.Split == action) { player_handset.Split(shoe.ExtractTop(), shoe.ExtractTop()); player_money -= bet; AddPartyPoints(bet); split_count++; } else { Console.WriteLine("Unknown action"); } player_handset.NextActiveHand(); } // each hand should be here in either some of these states: // busted, standed, doubled, surrendered // if all hands are busted, dealer doesn't draw, only reveals his hand and the round is over if (player_handset.AllBusted()) { EndRound(); return; } // player surrendered if (player_handset.ActiveHand.Surrendered) { // return half of the initial bet player_money += (int)(0.5 * bet); EndRound(); return; } // handle the dealer logic while (true) { // must hit on soft 17's if (dealer_hand.HasAce() && dealer_hand.SoftTotal() == 17) { dealer_hand.AddCard(shoe.ExtractTop()); continue; } // finish condition if (dealer_hand.PointCount() >= 17) { break; } dealer_hand.AddCard(shoe.ExtractTop()); } // payouts foreach (Hand hand in player_handset) { // skip split hands if (hand.IsSplit()) { continue; } int hand_bet = (hand.Doubled) ? (bet * 2) : bet; if (dealer_hand.IsBust()) { /* * // both busted, it's a push * if (hand.IsBust()) * player_money += hand_bet; * else // not busted hand wins dealer's busted hand 2:1 payout * player_money += 2 * hand_bet; */ if (!hand.IsBust()) { player_money += 2 * hand_bet; } } else { // do nothing, we lose our bet if (hand.IsBust()) { } else { int player_total = hand.PointCount(); int dealer_total = dealer_hand.PointCount(); if (player_total < dealer_total) { // do nothing, we lose our bet } // we win, 2:1 payout else if (dealer_total < player_total) { player_money += 2 * hand_bet; } // push else { player_money += hand_bet; } } } } // round is over EndRound(); }