Memory Game

Hello forum,

I’m creating a memory game with an opponent that perfectly remembers certain cards opened by either the AI or the player. Will release full code if I manage to make it work.
Thing is, it has one major flaw:

    private IEnumerator AITurnCard(int Idx, float Delay)
    {
        yield return new WaitForSeconds(Delay);
        if (Choice.Count > 0)
        {
            Debug.Break();
            while (Deck[Idx]==Choice[0])
            {
                Debug.Log("Detected a faulty selection");
                Idx = Random.Range(0, Deck.Count);
                yield return null;
            }
        }
        Deck[Idx].GetComponent<Card>().Choose();
    }

The opponent draws a random card from available from the deck but sometimes, it wants to flip the same card as the first one/choice. I have multiple variables and while loops checking so it doesn’t happen, and yet, the debug.log doesn’t appear. Does anyone know what’s going on?
Thanks in advance.

I think I found the issue so after I run a few tests I’ll upload the project as an imported asset as promised.
The issue was that I created two different types of lists. Deck holds gameobjects and choice held the component with the ‘card’ script. So while (Deck[Idx]==Choice[0]) had to be changed to while (Deck[Idx]==Choice[0].gameObject)

Here’s the unity package. Have fun getting owned by the AI. As it’s mostly flawless as I had set it’s memory capacity to 8 in the inspector. :smile:

5244641–523727–MemoryGame.unitypackage (372 KB)