Is there a better, more elegant solution to the following method?
Boolean[] spades = new Boolean[10]; // 40 cards deck
foreach (Card card in m_Cards.Where(card => (card.Suit == Suit.Spades)))
spades[(Int32)card.Rank] = true; // Rank goes from Ace (0) to King (10)
if (spades[0] && spades[1] && spades[2])
{
points += 3;
for (Int32 i = 3; i < spades.Length; ++i)
{
if (spades[i])
++points;
else
break;
}
}
In fact, the function awards 3 points to the player only if he owns Ace, Two and Three... and, always if this condition is satisfied, it awards him a point for every card that extends the sequence. Examples:
Ace + Three + Five = 0 Points
Ace + Two + Three = 3 Points
Ace + Two + Three + Five = 3 Points
Ace + Two + Three + Four + Five + Six = 6 Points
Every kind of better solution is accepted, such as Linq and enumerable extensions.
m_cards
variable? What kind of game is this? \$\endgroup\$