Game in MATLAB?
8 views (last 30 days)
Show older comments
Nick Haufler
on 25 Jan 2016
Commented: Walter Roberson
on 27 Jan 2016
I'm making Yahtzee in Matlab, and I'm focusing on getting the scoring set up. I get scores to come back in an array, but they don't seem to be correct. I've looked over my code several times, but just cant seem to figure out what went wrong. I'm desperate at this point, and need help. I attached my code along with this post. Any help is appreciated. Thanks! You guys are awesome.
2 Comments
Accepted Answer
Walter Roberson
on 25 Jan 2016
Hint: instead of using size(something==value) you can use sum(something==value)
Your code is counting some things multiple times. For example, a full house is counted but so is its value as 3 of a kind. Likewise, Chance should only apply if nothing else matched.
For 3 of a kind or 4 of a kind, you are using a score of sum(diceValues), which is not correct: you should be counting only the dice that match.
Your points array could be numeric instead of a cell array.
8 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!