To help you understand what I am trying to explain I will tell you the rules for Yahtzee scoring. You have two scoring categories 'lows' and 'highs'. The user rolls 5 dice up to 3 times or until they are satisfied with the results, in other words they can stop rolling at anytime but may re-roll a picked amount of dice. They can only roll a total of three times overall. Lets say you rolled 6-6-3-4-6 and you wanted to re-roll the 3 and 4 to try to make it 5 6's to get a higher score then you could re-roll 2 more times to get that score. The scoring system works like this:
Lows
ones:
twos:
threes:
fours:
fives:
sixes:
total:
bonus:
Highs:
three of a kind:3 die faces are the same (2,2,2,3,4)
four of a kind: 4 die faces are the same (1,1,1,1,5)
small straight: 4 sequential dice (1,2,3,4)
large straight: 5 sequential dice(1,2,3,4,5)
full house: 3 of a kind and a pair (6,6,5,5,5)
Yahtzee: 5 dice all of same value for 50 points. (5,5,5,5,5)
total = lowstotal + highstotal + bonus;
What I am trying to do is write a function that controls where the player can apply the points. I could do this using endless amounts of else if statements but that doesn't seem efficient to me and is most likely what the rest of the class will do as they like to follow in the book and never think outside of the box. I have this program working up to the storing all the values of each die after max number of re-rolls or they decide to keep it. I want to take those 5 values and compare them to a scoring category to output to the user only the available categories to use. This will eliminate tons of error handling and potential bugs. I also have to make sure that it does not display a category with a score value already stored in it. I've got kind of a pseudocode for it, but would appreciate any thoughts on how you might do something similar to this or if you could point me in the right direction.
Thanks,
1 2 3 4 5 6 7 8 9 10 11 12 13
|
for(int i = 0; i < 4; i++){
//check for keptdie[5] values against a bool?
if (keptdie[i] == category[i])
category[i] = options[i];
}
/*I think this would work for scoring the lows but it wouldn't work for any of
the Highs as it would need to compare every value in the keptdie[] to see if it
contains 3 of a kind or 3 of kind and a pair. I am not sure on what step to
take next and if maybe there is a better way of doing this or a built function
i could use that already does something similar to this.*/
|