Dice Question (Full House and Straight recognition)

Lloyd Powell picture Lloyd Powell · Jun 26, 2011 · Viewed 7k times · Source

I'm making a dice game. There are 5 dice in which I have all the values for and I need to determine if they make up a full house (3 of one and 2 of another), small straight (1-4, 2-6 or 3-6) or a large straight (1-5, 2-6).

Perhaps the best way to approach this seems to be to use regular expressions.

Does anyone know how I would go about representing these rules in regex?

Or if you can provide a better solution, I'd appreciate that.

Examples:

  • Full house = 44422 or 11166 or 12212 etc.
  • Small Straight = 12342 or 54532 etc.
  • Large Straight = 12345 or 52643 etc.

Edit
Changed wording to highlight that this is my inexperienced opinion.

I know how to achieve this using code, but it seems like such a long winded solution, I'm wondering if there's a more simplistic approach.

Answer

Craig White picture Craig White · Jun 26, 2011

I would order all the numbers decreasing and then do some linear criteria matching on each value as you go along it whether it be in an int[] or a string.