
Yahtzee C++ programme help
hi all,
i would like to make a yahtzee game but i would like some help to get it started i dont know where to start from??
I would like to keep it simple and use the following:
While loop
For loop
Arrays
RAND_MAX
rand()%n
srand(seed)
Re roll only once.
The programme takes 5 input the 5 dices rolls and determines the 13 different outcomes possible scores. The programme inputs 5 values in the range from 1 to 6 abd stores the 5 values in an integer array. then determine the 13 alternatives then stores in a suitable array.
[cpp]
#include<iostream>
#include<cstlib>
using namespace std;
int main()
{
[/cpp]

How do you see play proceeding? Write out those steps in outline form  or even as a flowchart. Where will each of your "I want to include"(s) fit into your flowchart? Once you can play the whole game following your flowchart, you will be ready to write the code for your game.

this is what ive done so far. but im stuck with this.
how do you store the dices numbed into count?? like say count[0] holds number of ones count[1] holds number of 2s ect....
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
int nums[5];
int i;
time_t t;
int count[6];
srand(time(&t)); /* seed the random number generator */
for(i = 0; i < 5; i++)
{
nums[i] = rand()%6 + 1;
cout << nums[i] << endl;
}
return 0;
}

Basically, this program is very straightforward. I think you can do that.
Please be patient.

You aren't going to be able to just slap this together: you need to plan out the flow of your game. Think about how you play Yahtzee. Sketch out how play goes. You are going to want to roll die and display their values after the roll. You want to decide what combination you are going to play for. You have to "hold" certain die and roll the others. After the third roll or when the player decides he's done, you need to total the roll and store it associated with one of the combinations.
As to your combinations array, you score the results of your roll under the allowable rules for each of the possible combinations. For ones, count the number of ones, if there are two or three or four or five ones, then you score appropriately. Go for each of 1 to 6. Then, do you have two of a kind, three of a kind, four of a kind, five of a kind. Do you have a full house. Have a short straight or a long straight? Score for each, place into the destination element of your combinations array.
Last edited by nspils; 09032007 at 10:48 PM.

you only have a few dice, its probably easiest to just roll them into an array of size 6 (if thats the max dice, i forget the game details) and parse the possible options for the roll (is it 6 of a kind, full house, etc? there are like 10 things to check). You only have to parse at the very end, when the user puts it into a slot you compute the points (if fullhouse points = 50 else = 0 sort of thing or total all the 6's for those type etc). You also have to track rerolls and used rolls and all that.
Last edited by jonnin; 09032007 at 11:04 PM.

i only need to use one die,
this is what ive done so far but i think its wrong:
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
int nums[5];
int i, j, input;
time_t t;
int count[6];
srand(time(&t)); /* seed the random number generator */
for(j= 0; j < 14; j++)
{
for(i = 0; i < 5; i++)
{
nums[i] = rand()%6 + 1;
cout << nums[i] << endl;
switch(nums[i])
{
case 1: ++count[0]; break;
case 2: ++count[1]; break;
case 3: ++count[2]; break;
case 4: ++count[3]; break;
case 5: ++count[4]; break;
case 6: ++count[5]; break;
default: cout << "An error has occured!"; break;
}
}
cout << "Choose which numbers you want to keep? \n";
"\n";
cin >> input;
if (input > 6) cout << "Please select number from 1 to 6 only \n";
'\n';
}
return 0;
}

You are going to need some additional logic to assess whether your game is working on any of the other possible scoring combinations. I would write this with more than one array  probably one for each scoring combination plus one to track my use of the 13 combinations.

can someone write me up the code so i can study it when i have free time?i realy want to get into this:
this is the output i would like:
Enter seed? 123
=== Round#1 ===
Total for the first six categories is 0 points.
Current total is 0 points.
The dice were 21211
What rerolls? hhhhh
These are available categories:
(1) Ones gives 3 points.
(2) Twos gives 4 points.
(3) Threes gives 0 points.
(4) Fours gives 0 points.
(5) Fives gives 0 points.
(6) Sixs gives 0 points.
(7) Threes of a kind gives 7 points.
(8) Fours of a kind gives 0 points.
(9) Full house gives 25 points.
(10) Small straight gives 0 points.
(11) Large straight gives 0 points.
(12) Yahtzee gives 0 points.
(13) Chances gives 7 points.
Please enter a category#? 9
=== Round#2 ===
Total for the first six categories is 0 points.
Current total is 25 points.
The dice were 25144
What rerolls? hhhhr
The dice were 25143
These are available categories:
(1) Ones gives 1 points.
(2) Twos gives 2 points.
(3) Threes gives 3 points.
(4) Fours gives 4 points.
(5) Fives gives 5 points.
(6) Sixs gives 0 points.
(7) Threes of a kind gives 0 points.
(8) Fours of a kind gives 0 points.
(10) Small straight gives 30 points.
(11) Large straight gives 40 points.
(12) Yahtzee gives 0 points.
(13) Chances gives 15 points.
Please enter a category#? 11
=== Round#3 ===
Total for the first six categories is 0 points.
Current total is 65 points.
The dice were 51552
What rerolls?
Similar Threads

By WXY595 in forum VB Classic
Replies: 3
Last Post: 02272006, 07:12 AM

By dibakar in forum Open Source
Replies: 0
Last Post: 06212005, 11:26 AM

By Preet Kanwaljit Singh in forum Careers
Replies: 0
Last Post: 06032003, 03:10 PM

By Avijit in forum VB Classic
Replies: 0
Last Post: 10232001, 05:26 AM

By george in forum Careers
Replies: 0
Last Post: 08272001, 11:33 AM
Posting Permissions
 You may not post new threads
 You may not post replies
 You may not post attachments
 You may not edit your posts

Forum Rules

Development Centers
 Android Development Center
 Cloud Development Project Center
 HTML5 Development Center
 Windows Mobile Development Center
