Been playing with this last question, so far I got the following which keeps drawing cards until it gets a flush:
Code:
static void Main(string[] args)
{
Deck myDeck=new Deck(); //the full deck of cards
Card[] hand=new Card[5]; //the hand of 5 cards
bool flush=false; //flush or not?
int i=0,j=0,k=1;
myDeck.Shuffle(); //shuffle the deck
while (flush==false)
{
for(i=0;i<50;i+=5)
{
for (j=0;j<5;j++)
{
hand[j]=myDeck.GetCard(i+j);
Console.WriteLine("Card {0}: {1}-{2}",i+j+1,hand[j].suit,hand[j].rank);
}
flush=sameSuit(hand);
Console.WriteLine("==============");
}
myDeck.Shuffle();
k++;
}
Console.WriteLine("FLUSH! After {0} packs.",k);
Console.ReadLine();
}
static bool sameSuit(Card[] hand)
{
//loop through all cards starting at the 2nd
for (int i=1;i<hand.Length;i++)
{
//if the current suit is different from the previous then return false
if (hand[i].suit != hand[i-1].suit)
return false;
}
//we got here so all cards must be the same suit
return true;
}
But I've got a few q's about it
a) is there any really stupid bits of code?
b) although the number of packs needed to get a flush varies, it is always the last cards drawn that produce the flush...this seems highly unlikely. so i) is it my code that's telling porkies ii) or just that the shuffle method is pretty crap?