I am writing a c++ yahtzee program for my programming class, and i am having trouble with the small straights. I have no idea how to tell if the player has rolled a small straight, can anyone give me a clue as to where to start?
This is a discussion on Help with Yahtzee Program within the C++ Programming forums, part of the General Programming Boards category; I am writing a c++ yahtzee program for my programming class, and i am having trouble with the small straights. ...
I am writing a c++ yahtzee program for my programming class, and i am having trouble with the small straights. I have no idea how to tell if the player has rolled a small straight, can anyone give me a clue as to where to start?
I have no idea what small straigt is. You should learn first ask questions...
If I have eight hours for cutting wood, I spend six sharpening my axe.
As much as I have to agree, I'd say that the Wikipedia page has some good info on that kind of thing.
Simply put, it's not difficult. Just check if the maximum difference between the lowest and highest dies is 4, and that no dice are equal to each other.
(There's probably a simpler solution, but that's the first thing that springs to mind, besides sorting the die values.)
Do as I say, not as I do . . .
Experimentation is the essence of programming. Just remember to make a backup first.
"I'm a firm believer that <SomeGod> gave us two ears and one mouth for a reason - we are supposed to listen, twice as much as we talk." - LEAF
Questions posted by these guidelines are more likely to be answered.
Debian GNU/Linux user, with the awesome window manager, the git version control system, and the cmake buildsystem generator.
A small straight can be:
1234
2345
3456
A large straight can be:
12345
23456
What nightowl said is a good way to check for both a small and a large straight with the exception of a large straight having a max difference of 4 and a small straight a max difference of 3 between the dies.
Arrogance breeds bad code
But of course. My apologies.
An example could be something like this . . .
And so on. Yes, I know that the x loop could be < 5, but this is easier to follow.Code:/* assuming here that rolled[] is an array of size 6 (int[6]) */ int max = 0, min = 7; int x = 0; for(x = 0; x < 6; x ++) { if(rolled[x] > max) max = rolled[x]; if(rolled[x] < min) min = rolled[x]; } if(max-min == 3 || max-min == 4) { bool same = false; for(x = 0; x < 6 && !same; x ++) { for(int y = x; y < 6 && !same; y ++) { if(x == y) continue; if(rolled[x] == rolled[y]) same = true; } if(same) /* then it's not a straight */ }![]()
Do as I say, not as I do . . .
Experimentation is the essence of programming. Just remember to make a backup first.
"I'm a firm believer that <SomeGod> gave us two ears and one mouth for a reason - we are supposed to listen, twice as much as we talk." - LEAF
Questions posted by these guidelines are more likely to be answered.
Debian GNU/Linux user, with the awesome window manager, the git version control system, and the cmake buildsystem generator.