Post

#### Prime b

• NA
• 810
• 340.4k

Mar 14 2012 5:28 PM
Vulpes! Remember the project we worked on, the card one? Well i received a 90! So i am happy, thank you.
But teacher asked me about ( the code below ), and I couldn't really explain how it works, and I completely forgot to ask you to explain it to me how it does work, so could you explain to me how it works?
So that's about it, we have two project left to do and the semester is over, I honestly cant wait for it to be over, I am all stressed out about my final grades.

public HandType DetermineHandByType(out string description)
{
HandType result = HandType.NOTHING;
if (!IsComplete())
{
description = "Hand is incomplete";
return result;
}
int[] cardCounts = new int[13]; // all zero initially

foreach (GraphicalCard card in hand) cardCounts[card.GetNumericValue() - 2]++;

int value = -1;
int pair = -1;

for (int index = 0; index < 13; index++)
{
if (cardCounts[index] == 1)
{
if ((result == HandType.NOTHING) && (index > value)) value = index;
}
else if (cardCounts[index] == 2)
{
if (result == HandType.NOTHING)
{
result = HandType.TENS_OR_BETTER;
value = -1;
pair = index;
}
else if (result == HandType.TENS_OR_BETTER)
{
description = String.Format("Two Pairs\r\n{0}s and {1}s\r\nPlayer wins", cn[index], cn[pair]);
return HandType.TWO_PAIRS;
}
else if (result == HandType.THREE_OF_A_KIND)
{
description = String.Format("Full House\r\n{0}s and {1}s\r\nPlayer wins", cn[value], cn[index]);
return HandType.FULL_HOUSE;
}
}
else if (cardCounts[index] == 3)
{
if (result == HandType.NOTHING)
{
result = HandType.THREE_OF_A_KIND;
value = index;
}
else if (result == HandType.TENS_OR_BETTER)
{
description = String.Format("Full House\r\n{0}s and {1}s\r\nPlayer wins", cn[index], cn[pair]);
return HandType.FULL_HOUSE;
}
}
else if (cardCounts[index] == 4)
{
description = String.Format("Four {0}s\r\nPlayer wins", cn[index]);
return HandType.FOUR_OF_A_KIND;
}
}

if (result == HandType.THREE_OF_A_KIND)
{
description = String.Format("Three {0}s\r\nPlayer wins", cn[value]);
return result;
}
else if (result == HandType.TENS_OR_BETTER)
{
if (pair >= 8)
{
description = String.Format("Pair of {0}s\r\nPlayer wins", cn[pair]);
return result;
}
else
{
description = String.Format("Pair of {0}s\r\nHouse wins", cn[pair]);
return HandType.NOTHING;
}
}

if (IsRoyalFlush(out first, out suit))
{
description = String.Format("Royal Flush in {0}\r\n10 to Ace\r\nPlayer wins", suit);
return HandType.ROYAL_FLUSH;
}
else if (IsStraightFlush(out first, out suit))
{
description = String.Format("Straight Flush in {0}\r\n{1} to {2}\r\nPlayer wins", suit, cn[first], cn[first + 4]);
return HandType.STRAIGHT_FLUSH;
}
else if (IsFlush(out suit))
{
description = String.Format("Flush in {0}\r\nPlayer wins", suit);
return HandType.FLUSH;
}
else if (IsStraight(out first))
{
description = String.Format("Straight {0} to {1}\r\nPlayer wins", cn[first], cn[first + 4]);
return HandType.STRAIGHT;
}

description = String.Format("{0} High\r\nHouse Wins", cn[value]);
return result;
}