Here's some of the methods how i find specific combinations :
public class Hand
{
public enum Combinations
{
Default = -1,
HighCard = -1,
PairTable = 0,
Pair = 1,
TwoPair = 2,
ThreeOfAKind = 3,
Straight = 4,
Flush = 5,
FullHouse = 6,
FourOfAKind = 7,
StraightFlush = 8,
RoyalFlush = 9
}
public double Power { get; set; }
public int Current { get; set; }
}
straight[]
contains the player's 2 cards and the five cards on the table
private UsersProperties RFourOfAKind(UsersProperties user, IReadOnlyList<int> straight)
{
const int localType = (int) Hand.Combinations.FourOfAKind;
for (int j = 0; j <= 3; j++)
{
if (straight[j]/4 == straight[j + 1]/4 && straight[j]/4 == straight[j + 2]/4 &&
straight[j]/4 == straight[j + 3]/4)
{
UpdateHand(user, localType, straight[j]/4*4);
}
if (straight[j]/4 == (int) Cards.Numbers.Ace && straight[j + 1]/4 == (int) Cards.Numbers.Ace &&
straight[j + 2]/4 == (int) Cards.Numbers.Ace && straight[j + 3]/4 == (int) Cards.Numbers.Ace)
{
UpdateHand(user, localType, 13*4);
}
}
return user;
}
Full House method :
private UsersProperties RFullHouse(UsersProperties user, int[] straight)
{
const int localType = (int) Hand.Combinations.FullHouse;
for (int j = (int) Cards.Numbers.Ace; j <= (int) Cards.Numbers.King*4; j++)
{
int two = -1;
int counterForThree = straight.Count(rep => rep/4 == j/4);
if (counterForThree == 3)
{
for (int k = (int) Cards.Numbers.Ace; k <= (int) Cards.Numbers.King*4; k++)
{
if (k/4 == j/4) continue;
int counterForTwo = straight.Count(rep => rep/4 == k/4);
if (counterForTwo != 2 || k/4 == two) continue;
two = k/4;
if (j == 0)
{
UpdateHand(user, localType, 13*3 + (k/4)*2);
}
else if (k == 0)
{
UpdateHand(user, localType, j/4*3 + 13*2);
}
}
}
}
return user;
}
Straight Method :
private UsersProperties RStraight(UsersProperties user, IEnumerable<int> straight)
{
const int localType = (int) Hand.Combinations.Straight;
int[] op = straight.Select(o => o/4).Distinct().ToArray();
for (int j = 0; j < op.Length - 4; j++)
{
if (op[j] + 1 == op[j + 1] && op[j] + 2 == op[j + 2] && op[j] + 3 == op[j + 3] && op[j] + 4 == op[j + 4])
{
UpdateHand(user, localType, op.Max() - 4 == op[j] ? op.Max() : op[j + 4]);
}
if (op[j] != (int) Cards.Numbers.Ace || op[j + 1] != (int) Cards.Numbers.Ten ||
op[j + 2] != (int) Cards.Numbers.Jack || op[j + 3] != (int) Cards.Numbers.Queen ||
op[j + 4] != (int) Cards.Numbers.King) continue;
UpdateHand(user, localType,13);
}
return user;
}
Also the UpdateHand method :
private void UpdateHand(UsersProperties user, int combinationType, int powerType)
{
user.Type = combinationType;
user.Power = powerType + user.Type * 100;
_win.Add(new Hand { Power = user.Power, Current = user.Type });
}