Пример #1
0
    void dumbAILogic()
    {
        List <string> CPUhand = UNOsystem.CPU1;
        bool          valid   = true;

        foreach (string card in CPUhand)
        {
            print(CPUhand.Count);
            valid = input.valid(card);
            if (valid)
            {
                //print("Made it in if statement");
                AIplay         = true;
                AIselectedCard = card;
                AIPlay(card);

                UnityEngine.Random random = new UnityEngine.Random();
                int number = UnityEngine.Random.Range(1, 255);
                if ((number % 2) == 1)
                {
                    input.CPU_UNO_Check();
                    if (CPUhand.Count == 1)
                    {
                        //Trigger UNO to pop up on screen
                        StartCoroutine(AIUno());
                        //print("CPU has uno");
                    }
                }


                if (card[0] == ' ')
                {
                    UNOsystem.curColor = 'Y';
                    StartCoroutine(colorYellow());
                }
                break;
            }
        }

        if (valid == false)
        {
            UNOsystem.turnDraw(1, UNOsystem.CPU1);

            string possibleCard = CPUhand[CPUhand.Count - 1];

            if (input.valid(possibleCard))
            {
                print("Playing drawn card");
                AIPlay(possibleCard);

                /*
                 * input.CPU_UNO_Check();
                 * if (CPUhand.Count == 1)
                 * {
                 *  //Trigger UNO to pop up on screen
                 *  StartCoroutine(AIUno());
                 * }
                 */
                if (possibleCard[0] == ' ')
                {
                    UNOsystem.curColor = 'Y';
                    StartCoroutine(colorYellow());
                }
            }
        }

        AI_winCheck();

        /*
         * if (CPUhand.Count == 0)
         * {
         *  winText.GetComponent<TextMeshProUGUI>().text = "Game Over! You Lose!";
         *  GameOverSystem.ExitMenuIsActive = true;
         * }
         */
    }
Пример #2
0
    public void Smart_AI_Logic()
    {
        print("TESTING - Smart_AI_Logic()");
        bool playWild = false;

        List <List <double> > comm_scores = new List <List <double> >()
        {
            new List <double>()
            {
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
            },
            new List <double>()
            {
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
            },
            new List <double>()
            {
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
            },
            new List <double>()
            {
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
            }
        };

        //Proportion of cards that the opponent may play still possible
        //double hand_color_quantity,
        //double hand_symbol_quantity,
        //double played_color_quantity,
        //double played_symbol_quantitiy

        List <double> hand_color_quantity_proportions = new List <double>()
        {
            0, 0, 0, 0
        };

        for (byte i = 0; i < hand_color_quantity_proportions.Count; i++)
        {
            hand_color_quantity_proportions[i] += colorQuants(maxQuants)[i];
            hand_color_quantity_proportions[i] -= colorQuants(handMem)[i];
            hand_color_quantity_proportions[i]  = hand_color_quantity_proportions[i] / (colorQuants(maxQuants)[i]);
        }

        List <double> hand_symbol_quantity_proportions = new List <double>()
        {
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
        };

        for (byte i = 0; i < hand_symbol_quantity_proportions.Count; i++)
        {
            hand_symbol_quantity_proportions[i] += symbolQuants(maxQuants)[i];
            hand_symbol_quantity_proportions[i] -= symbolQuants(handMem)[i];
            hand_symbol_quantity_proportions[i]  = hand_symbol_quantity_proportions[i] / (symbolQuants(maxQuants)[i]);
        }

        List <double> discard_color_quantity_proportions = new List <double>()
        {
            0, 0, 0, 0
        };

        for (byte i = 0; i < discard_color_quantity_proportions.Count; i++)
        {
            discard_color_quantity_proportions[i] += colorQuants(maxQuants)[i];
            discard_color_quantity_proportions[i] -= colorQuants(discardMem)[i];
            discard_color_quantity_proportions[i]  = discard_color_quantity_proportions[i] / (colorQuants(maxQuants)[i]);
        }

        List <double> discard_symbol_quantity_proportions = new List <double>()
        {
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
        };

        for (byte i = 0; i < discard_symbol_quantity_proportions.Count; i++)
        {
            discard_symbol_quantity_proportions[i] += symbolQuants(maxQuants)[i];
            discard_symbol_quantity_proportions[i] -= symbolQuants(discardMem)[i];
            discard_symbol_quantity_proportions[i]  = discard_symbol_quantity_proportions[i] / (symbolQuants(maxQuants)[i]);
        }

        for (byte i = 0; i < 4; i++)
        {
            for (byte k = 0; k < 13; k++)
            {
                comm_scores[i][k] = commonness_score(hand_color_quantity_proportions[i], hand_symbol_quantity_proportions[k], discard_color_quantity_proportions[i], discard_symbol_quantity_proportions[k]);
            }
        }

        //Select card in hand with lowest commonness score
        List <sbyte> temp = get_min_in_hand(comm_scores);

        if (temp[0] == -1 && temp[1] == -1)
        {
            //No non-wild cards can be played
            playWild = true;
        }
        //return card_name(temp[0], temp[1]);

        //Special handling for wild cards
        //  +Save them
        //  +Play as last resort
        //  +Select most common non-black color in (discard pile + hand)
        if (playWild)
        {
            if (handMem[4][14] > 0)
            {
                HardAIplay(" Wild Draw Four");
            }
            else if (handMem[4][13] > 0)
            {
                HardAIplay(" Wild");
            }
            else//No cards (including wild) can be payed
            {
                print("  No card found; drawing");
                UNOsystem.turnDraw(1, UNOsystem.CPU1);
                if (input.valid(UNOsystem.CPU1[UNOsystem.CPU1.Count - 1]))
                {
                    print("Playing drawn card");
                    HardAIplay(UNOsystem.CPU1[UNOsystem.CPU1.Count - 1]);
                }
            }
        }
        else
        {
            HardAIplay(card_name(temp[0], temp[1]));
        }

        input.CPU_UNO_Check();
        if (UNOsystem.CPU1.Count == 1)
        {
            //Trigger UNO to pop up on screen
            StartCoroutine(actionManager.AIUno());
        }

        actionManager.AI_winCheck();
        return;
    }