Sign in to follow this  

scoring for farkle dice game

This topic is 2635 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

what is the best way to check six dice for scoring for the dice game farkle in C++? Would the best way be to use a ton of if statements such as

if dieOne == 1 and dieTwo == 1 and dieThree == 1 and dieFour == 1 and dieFive == 1 and dieSix == 1
player gets 8,000pts

I know this is not properly coded it is just psuedo code for my design purposes. My only concern is it would take hundreds of if statemnets to check all dice possibilities. I was just wondering if there is a better way.

Share this post


Link to post
Share on other sites
Well the first thing I would do is get rid of all your dieN's and just make a proper array of die. Then you can iterate over them properly in a for loop with much less typing :)

Just looking up the rules real quick (http://en.wikipedia.org/wiki/Farkle#Standard_scoring) they don't look that complicated.

Something like this:


Die die[6];
int score = 0;
int counters[6]; //sides 1-6 indexed as 0-5 here for simplicity

for(uint i=0;i<6;i++){
if(die[i]==0) score+=100;
if(die[i]==4) score+=50;
counters[die[i]]++;
}
if(counters[0]>3) score+=1000; //more than 3 1's is 1000 points
...etc...


Share this post


Link to post
Share on other sites
From glancing at the rules, you only have three different scoring possibilities. Karwost's answer is on the right track, but won't handle some cases like duplicate flushes. There's a better way:

1) roll an array of 6 dice (e.g. result = 4,3,1,1,6,1)
2) sort the results by value (e.g. = 1,1,1,3,4,6)
3) iterate array, for each value "n" doing:
-- 3a) add 50 pts for every 5, and 100 pts for every 1.
-- 3b) Increment a "flush" ctr if value of n = value of n-1. Clear ctr if not.
-- 3c) Increment a "straight" ctr if value of n = 1+ value of n-1. Clear if not.
-- 3d) If flush ctr=3, add 100 * val of die (+100 if val=1, -150 if val=5), and clear ctr.

At end of loop, if straight ctr=6, clear score and set = 1000.

The +100 for val=1, -150 for val-5 may look a bit odd, but that's to adjust the double-scoring the individual dice within a flush as individual 1's and 5's.

Share this post


Link to post
Share on other sites

This topic is 2635 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this