dimanche 30 juin 2019

How do you switch 2 elements in the same array?

I am trying to shuffle a non shuffled deck(2D array) that i have created earlier in the same class under a function named NewDeck(). The code is designed to switch two elements in the same array thousands of times and get a unique deck with no duplicates. Instead it returns 52 deck of the same card.

Thanks

Code:

public static string[,] Shuffle()
    {
        Deck cDeck = new Deck() { shuffledDeck = Deck.NewDeck() };
        Random rnd = new Random();

        int x, y, z, k;

        string[,] ph = cDeck.shuffledDeck;

        for (int i = 0; i < 10000; i++)
        {
            x = rnd.Next(4);
            y = rnd.Next(13);
            z = rnd.Next(4);
            k = rnd.Next(13);

            cDeck.shuffledDeck.SetValue(ph[x, y], z, k);
            cDeck.shuffledDeck.SetValue(ph[z, k], x, y);
            ph = cDeck.shuffledDeck;
        }
        return cDeck.shuffledDeck;
    }




Aucun commentaire:

Enregistrer un commentaire