PDA

View Full Version : Multiple Combinations



Vicato
- 11th April 2011, 02:29
I'm making a yahtzee game and trying to determine when someone has a three-of-a-kind, four-of-a-kind, full house, small straight, large straight, and yahtzee. The yahtzee part is easy since all five of the numbers are the same, but the others aren't so easy. Is there a better way to determine when I have three-of-a-kind than using a ton of IF THENS to check all possible ways of getting three of the same numbers?

HenrikOlsson
- 11th April 2011, 06:23
Dice VAR BYTE[5] 'Array of 5 bytes, one for each dice.
Results VAR BYTE[6] 'Array of six bytes containing the number of ones, twos, threes etc
i VAR BYTE

For i = 0 to 5
Results[i] = 0 'Clear counters
Next

For i = 0 to 4 'Itterate thru the five dices
Select Case Dice[i]
Case 1
Results[0] = Results[0] + 1 'Ones
Case 2
Results[1] = Results[1] + 1 'Twos
Case 3
Results[2] = Results[2] + 1 'Threes
Case 4
Results[3] = Results[3] + 1 'Fours
Case 5
Results[4] = Results[4] + 1 'Fives
Case 6
Results[5] = Results[5] + 1 'Sixes
End Select
NEXT
Now you know how MANY of each you've got, perhaps that's a start?

Vicato
- 11th April 2011, 20:47
Dice VAR BYTE[5] 'Array of 5 bytes, one for each dice.
Results VAR BYTE[6] 'Array of six bytes containing the number of ones, twos, threes etc
i VAR BYTE

For i = 0 to 5
Results[i] = 0 'Clear counters
Next

For i = 0 to 4 'Itterate thru the five dices
Select Case Dice[i]
Case 1
Results[0] = Results[0] + 1 'Ones
Case 2
Results[1] = Results[1] + 1 'Twos
Case 3
Results[2] = Results[2] + 1 'Threes
Case 4
Results[3] = Results[3] + 1 'Fours
Case 5
Results[4] = Results[4] + 1 'Fives
Case 6
Results[5] = Results[5] + 1 'Sixes
End Select
NEXT
Now you know how MANY of each you've got, perhaps that's a start?

This actually worked out really well, I got it checking for each one. Thanks for your help! :)