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?

Printable View

- 03-18-2009infuser21Help with Yahtzee Program
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?

- 03-19-2009vart
I have no idea what small straigt is. You should learn first ask questions...

- 03-19-2009Nightowl
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. ;) ) - 03-19-2009VirtualAce
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. - 03-19-2009Nightowl
But of course. My apologies.

An example could be something like this . . .

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 */

}

**x**loop could be < 5, but this is easier to follow. ;)