Example #1
0
    ReadOnlyCollection <ChoiceKind> GetPossibleOptions()
    {
        AI_PlayerHand playerHand = player.GetCurrentHand;

        List <ChoiceKind> choices = new List <ChoiceKind>();

        if (playerHand.CanHit)
        {
            choices.Add(ChoiceKind.Hit);
        }
        if (playerHand.CanStand)
        {
            choices.Add(ChoiceKind.Stand);
        }
        if (playerHand.CanDoubleDown)
        {
            choices.Add(ChoiceKind.DoubleDown);
        }
        if (playerHand.CanSplit)
        {
            choices.Add(ChoiceKind.Split);
        }

        return(choices.AsReadOnly());
    }
Example #2
0
    void Choice()
    {
        do
        {
            bool isLoop = true;
            do
            {
                switch (GetBestChoice(resultInfo.dealerIdx))
                {
                case ChoiceKind.Hit:

                    GetCardPlayer();

                    isLoop = (!player.GetCurrentHand.IsStopChoice && PreferHit(resultInfo.dealerIdx));

                    break;

                case ChoiceKind.Stand:
                    isLoop = false;
                    break;

                case ChoiceKind.DoubleDown:

                    player.DoubleDown();

                    GetCardPlayer();

                    isLoop = false;

                    break;

                case ChoiceKind.Split:

                    AI_PlayerHand secondHand = player.Split(player.GetCurrentHand.IsDoubleAce);
                    GetCardPlayer();

                    AI_Card secondCard = deck.Pop();
                    player.AddCCNumber(secondCard.cardCountingScore);
                    secondHand.Push(secondCard, false);

                    break;

                case ChoiceKind.Surrender:

                    player.GetCurrentHand.AmountOfBetting = 0;
                    player.GetCurrentHand.IsSurrender     = true;
                    isLoop = false;

                    break;

                case ChoiceKind.NotDetermined:

                    isLoop = false;

                    break;
                }
            } while (isLoop && !player.GetCurrentHand.IsStopChoice);
        } while(player.UpdateAndCheckAllPossibleHand());
    }
Example #3
0
    public AI_PlayerHand AddHand()
    {
        GameObject    newObj  = (GameObject)Instantiate(handPrefab, Vector3.zero, Quaternion.identity);
        AI_PlayerHand newHand = newObj.GetComponent <AI_PlayerHand>();

        newHand.Init(transform.tag);
        hands.Add(newHand);

        return(newHand);
    }
Example #4
0
    public void GetCard(AI_Card card)
    {
        AI_PlayerHand hand = GetCurrentHand;

        bool isFirstHand = false;

        // 카드 추가전에 계산되기 때문에
        // 조건 수치를 2->1로 줄인다(origin=IsFirstHand)
        if (hands.Count == 1 && hands[0].GetCardCount <= 1)
        {
            isFirstHand = true;
        }

        hand.Push(card, isFirstHand); // (in)카드 하이라이트 +
    }
Example #5
0
    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);
    }
Example #6
0
    public AI_PlayerHand Split(bool isAce)
    {
        AI_Card card = GetCurrentHand.Pop();
        float   bet  = GetCurrentHand.AmountOfBetting;

        AI_PlayerHand splitHand = AddHand();

        if (isAce)
        {
            GetCurrentHand.SetSplitAce();
            splitHand.SetSplitAce();
        }

        // 그 핸드에 정보 전달
        splitHand.Push(card, false);
        splitHand.Betting();

        return(splitHand);
    }
Example #7
0
    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());
    }