# Yahtzee game

• 12-06-2010, 02:28 PM
Vinny2110
Yahtzee game
Hello

i'm making a simple yahtzee game for school but I don't have any idea how i should program a small and big straight.

Code:

```//big straight         if (waarde1 != waarde2 && waarde1 != waarde3 && waarde1 != waarde4 && waarde1 != waarde5 && waarde2 != waarde3 && waarde2 != waarde4 && waarde2 != waarde5 && waarde3 != waarde4 && waarde3 != waarde5 && waarde4 != waarde5){             resultaat = mogelijkheden.get(9);             checkScore();         } //smal straight if(waarde1==1&&waarde2==2&&waarde3==3&&waarde4==4&&waarde5==4 //unfinished){         resultaat = mogelijkheden.get(8);             checkScore();         }```
That is what I tried first but their are so many posibilities for a small straight, isnt their an easier way?

(sorry for my grammar, and for my names of the variables but im from belgium)
• 12-06-2010, 02:43 PM
Iron Lion
This is what I came up with, assuming that you've implemented your dice as an array of objects named Die[] with a method getValue() that returns its value as an int:
Code:

```public boolean isSmallStraight() {         boolean isRolled[] = new boolean[6];         for(int i = 1; i <= 6; i++) { // for the numbers 1-6                 for(int j = 0; j < 5; j++) { //for each of the five dice                         if(Die[j].getValue() == i) {                                 isRolled[i-1] = true;                         }                 }         }         return ((isRolled[0] && isRolled[1] && isRolled[2] && isRolled[3])             || (isRolled[1] && isRolled[2] && isRolled[3] && isRolled[4])             || (isRolled[2] && isRolled[3] && isRolled[4] && isRolled[5]));        }```
• 12-06-2010, 08:22 PM
Zack
Iron Lion, while I understand you're just trying to help, just giving source code to prospective programmers is generally a very bad idea. If they're working on an assignment, and we just give them the answer, they learn nothing and will go into their exam without the knowledge they need.

Instead, a push in the right direction is a good idea.
• 12-07-2010, 10:49 AM
Vinny2110
Thx, and now i probably have to change my big straight also like that?