Ok, here's a correct solution for 5 dice. I ended up needing to create a straight_check() function for the short straight after all. Can't do this with N-of-a-kind data very easily for 5 dice; however, the value_count data comes in very handy.
Essentially the short straight test works like this:
are there 1 or more 1's? 2's? 3's? 4's? if all yes, return true
are there 1 or more 2's? 3's? 4's? 5's? if all yes, return true
are there 1 or more 3's? 4's? 5's? 6's? if all yes, return true
And the long straight test is:
are there 1 or more 1's? 2's? 3's? 4's? 5's? if all yes, return true
are there 1 or more 2's? 3's? 4's? 5's? 6's? if all yes, return true
Works for 6 dice too if you change the const.
Essentially the short straight test works like this:
are there 1 or more 1's? 2's? 3's? 4's? if all yes, return true
are there 1 or more 2's? 3's? 4's? 5's? if all yes, return true
are there 1 or more 3's? 4's? 5's? 6's? if all yes, return true
And the long straight test is:
are there 1 or more 1's? 2's? 3's? 4's? 5's? if all yes, return true
are there 1 or more 2's? 3's? 4's? 5's? 6's? if all yes, return true
Const DICE = 5 Global die_value[DICE-1] Global value_count[6] Global of_a_kinds[DICE] Function roll_all_dice() For i = 0 To DICE-1 die_value[i] = Rand(1, 6) Next update_aggregates() End Function Function update_aggregates() For i = 1 To 6 value_count[i] = 0 Next For i = 0 To DICE-1 value_count[die_value[i]] = value_count[die_value[i]] + 1 Next For i = 0 To DICE-1 of_a_kinds[i] = 0 Next For i = 1 To 6 of_a_kinds[value_count[i]] = of_a_kinds[value_count[i]] + 1 Next End Function Function straight_check(length = DICE) For i = 1 To 6-length+1 match = True For n = i To i+length-1 If value_count[n] = 0 Then match = False : Exit ; Exit is an unnecessary optimization - sorry, force of habit Next If match = True Then Return True Next Return False End Function Function score_dice$() If straight_check(DICE) Then Return "long straight" If straight_check(DICE-1) Then Return "short straight" If of_a_kinds[5] = 1 Then Return "5 of a kind" If of_a_kinds[4] = 1 Then Return "4 of a kind" If of_a_kinds[3] = 1 And of_a_kinds[2] = 1 Then Return "full house" If of_a_kinds[3] = 1 Then Return "3 of a kind" If of_a_kinds[2] = 2 Then Return "2 pair" If of_a_kinds[2] = 1 Then Return "pair" Return "nada" End Function SeedRnd MilliSecs() roll_all_dice() Print "roll:" For i = 0 To DICE-1 : Print " " + i + ": " + die_value[i] : Next Print "value_count:" For i = 1 To 6 : Print " " + i + "'s: " + value_count[i] : Next Print "of_a_kinds:" For i = 1 To DICE : Print " " + i + "-of-a-kinds: " + of_a_kinds[i] : Next Print score_dice$()
Works for 6 dice too if you change the const.