ChoiceKind GetBestChoice() { Dictionary <ChoiceKind, float> choiceWinningRates = new Dictionary <ChoiceKind, float>(); Situation_Info info = DB_Manager.Instance.GetSingle(ccn, dealer.GetIndexOfOpen, aiOpponent.GetCurrentHand.GetSituationIndex); if (aiOpponent.GetCurrentHand.CanHit) { choiceWinningRates.Add(ChoiceKind.Hit, info.rate_Hit); } if (aiOpponent.GetCurrentHand.CanStand) { choiceWinningRates.Add(ChoiceKind.Stand, info.rate_Stand); } if (aiOpponent.GetCurrentHand.CanDoubleDown && aiOpponent.EnoughBetToDouble) { choiceWinningRates.Add(ChoiceKind.DoubleDown, info.rate_DoubleDown); } if (aiOpponent.GetCurrentHand.CanSplit && aiOpponent.EnoughBetToSplit) { choiceWinningRates.Add(ChoiceKind.Split, info.rate_Split); } if (aiOpponent.GetCurrentHand.CanSurrender) { choiceWinningRates.Add(ChoiceKind.Surrender, -0.5f); } ChoiceKind best = ChoiceKind.NotDetermined; float bestRate = float.MinValue; foreach (ChoiceKind kind in choiceWinningRates.Keys) { if (bestRate < choiceWinningRates[kind]) { best = kind; bestRate = choiceWinningRates[kind]; } } if (best == ChoiceKind.NotDetermined) { Debug.LogError("Stand is base choice, so whatever else should be determined in this stage"); } //Debug.Log("-------ccn:"+ ccn+"-------dealer:"+ dealer.GetIndexOfOpen+"--------ai:"+ aiOpponent.GetCurrentHand.GetSituationIndex + "---------------------"); //foreach(var item in choiceWinningRates) //{ // Debug.Log(item.Key + " = "+item.Value); //} //Debug.Log("** " + best + " **"); return(best); }
ChoiceKind GetBestChoice(int dealer_idx) { Dictionary <ChoiceKind, float> choiceWinningRates = new Dictionary <ChoiceKind, float>(); AI_PlayerHand playerHand = player.GetCurrentHand; Situation_Info info = DB_Manager.Instance.GetSingle(player.CCNumber, dealer_idx, player.GetCurrentHand.GetSituationIndex); if (playerHand.CanHit) { choiceWinningRates.Add(ChoiceKind.Hit, info.rate_Hit); } if (playerHand.CanStand) { choiceWinningRates.Add(ChoiceKind.Stand, info.rate_Stand); } if (playerHand.CanDoubleDown) { choiceWinningRates.Add(ChoiceKind.DoubleDown, info.rate_DoubleDown); } if (playerHand.CanSplit) { choiceWinningRates.Add(ChoiceKind.Split, info.rate_Split); } if (playerHand.CanSurrender) { choiceWinningRates.Add(ChoiceKind.Surrender, -0.5f); } ChoiceKind best = ChoiceKind.NotDetermined; float bestRate = float.MinValue; foreach (ChoiceKind kind in choiceWinningRates.Keys) { if (bestRate < choiceWinningRates[kind]) { best = kind; bestRate = choiceWinningRates[kind]; } } if (best == ChoiceKind.NotDetermined) { Debug.LogError("should be determined for best choice"); } return(best); }
void Choice() { ChoiceKind curChoice = ChoiceKind.NotDetermined; do { if (IsFirstChoiceNotDetermined()) { ReadOnlyCollection <ChoiceKind> possibleOptions = GetPossibleOptions(); curChoice = possibleOptions[Random.Range(0, possibleOptions.Count)]; resultInfo.firstChoice = curChoice; } else { curChoice = GetBestChoice(resultInfo.dealerIdx); } while (true) { bool loop = true; switch (curChoice) { case ChoiceKind.Hit: GetCardPlayer(); loop = (!player.GetCurrentHand.IsStopChoice && PreferHit(resultInfo.dealerIdx)); break; case ChoiceKind.Stand: loop = false; break; case ChoiceKind.DoubleDown: player.DoubleDown(); int preCount = player.CCNumber; int preValue = (int)player.GetCurrentHand.value; bool isPreSoft = player.GetCurrentHand.IsSoft; GetCardPlayer(); if (preValue >= 12 && isPreSoft == false) { if (player.GetCurrentHand.value == HAND_VALUE.BURST_PLAYER) { DB_Manager.Instance.AddBurstInfo(preCount, preValue); } else { DB_Manager.Instance.AddNotBurstInfo(preCount, preValue); } } loop = false; break; case ChoiceKind.Split: AI_PlayerHand secondHand = null; AI_Card secondCard = deck.Pop(); player.AddCCNumber(secondCard.cardCountingScore); secondHand = player.Split(player.GetCurrentHand.IsDoubleAce); GetCardPlayer(); secondHand.Push(secondCard, false); curChoice = GetBestChoice(resultInfo.dealerIdx); loop = (curChoice != ChoiceKind.Stand); break; case ChoiceKind.Surrender: player.GetCurrentHand.AmountOfBetting = 0; player.GetCurrentHand.IsSurrender = true; loop = false; break; case ChoiceKind.NotDetermined: Debug.LogError("Stand is base choice, so whatever else should be determined in this stage"); loop = false; break; } if (loop == false) { break; } } } while (player.UpdateAndCheckAllPossibleHand()); }