So I'm writing a small war card game program for practice and one thing I'm having some trouble understanding is why my function is returning the same deck for both human and cpu.
public static void TheirDecks(Player hum , Player cpu)
{
hum.myDeck.GenerateDeck();
cpu.myDeck.GenerateDeck();
hum.myDeck.Shuffle();
cpu.myDeck.Shuffle();
}
so the TheirDecks() method is found in my Create class.
public void GenerateDeck() // Must use this to populate deck
{
CurrentlyInDeck = new List<Card>(52);
int place = 0; // tracks which card number
for (int i = 0; i < 4; i++)
{
for (int f = 0; f < 13; f++)
{
Card card = new Card();
CurrentlyInDeck.Add(card);
CurrentlyInDeck[place].suit = (Suit)i;
CurrentlyInDeck[place].face = (Face)f;
place++;
}
}
}
public void Shuffle()
{
Random rand = new Random();
Card holder = new Card();
int random;
for (int i = 0; i < 52; i++)
{
random = rand.Next(0, 51);
holder = CurrentlyInDeck[i];
CurrentlyInDeck[i] = CurrentlyInDeck[random];
CurrentlyInDeck[random] = holder;
}
}
Those 2 are found in another class called Deck. When I run the following:
static void Main(string[] args)
{
Create.TheirDecks(human , cpu);
human.myDeck.PrintDeck();
Console.WriteLine();
cpu.myDeck.PrintDeck();
}
The print deck function prints out the same exact deck. Why is that? Thank you for your time.