Debugging Craps Simulating Game: Tracking Wins & Losses

Click For Summary
SUMMARY

The forum discussion focuses on debugging a craps simulation game, specifically the logic for tracking wins and losses based on the rules of the game. The user, Bertrand, is implementing a "Pass line" bet where the first roll determines the outcome based on specific conditions. The provided code snippet demonstrates how to handle the "point" case, but requires organization and clarity to ensure accurate tracking of wins and losses. Key improvements include using a flag variable to manage game state and incrementing win/loss counters appropriately.

PREREQUISITES
  • Understanding of C++ programming language
  • Familiarity with game simulation concepts
  • Knowledge of conditional statements and loops in programming
  • Basic understanding of the rules of craps
NEXT STEPS
  • Refactor the existing C++ code for improved readability and functionality
  • Implement a function to simulate dice rolls using random number generation
  • Learn about unit testing in C++ to validate game logic
  • Explore data structures for tracking multiple game sessions and statistics
USEFUL FOR

Game developers, programmers interested in simulation projects, and anyone looking to enhance their understanding of game logic implementation in C++.

brad sue
Messages
270
Reaction score
0
Hi ,
I have a problem coding a part of a simulating game:

In the game of craps, a "Pass line" bet proceeds as follows. The first roll of the two, six-sided dice in a craps round is called the "come out roll". The bet immediately wins when the come out roll is 7 or 11, and loses when the come out is 2,3 or 12.
If 4,5,6,8,9 or 10 is rolled on the come out roll, that number becomes " the point". The player keeps rolling the dice until either 7 or the point is rolled. If the point is rolled first, then the player wins the bet. If the player rolls a 7 first, the the player loses.
you need to indicate the total number of wins and losses.


The part that bothers me is the underline part.
This is the code I've done for this underlined part:

Code:
.
.
.
if(roll==4||roll==5||roll==6||roll==8||roll==9||roll==10)//point case
        { 
          cout<<roll<<" points"<<endl;
        do
         {
          roll=dice();//dice- function that simulates the 2 dice throwings
          cout<<endl;
          cout<<"roll "<<roll<<endl;
          if(roll==7)
          cout<<roll<<" the point got to 7. player loses"<<endl;
          if(roll==4||roll==5||roll==6||roll==8||roll==9||roll==10)
          cout<< roll<<" the roll got to 'point'. player wins"<<endl;
         }
          while(roll==7||roll==4||roll==5||roll==6||roll==8||roll==9||roll==10);
       }// end if
.
.
.

Please can you help to organize my code ?
Thank you
Bertrand
 
Technology news on Phys.org
int timesToPlay = 100;
int gamesPlayed = 0;
int wins = 0;
int losses = 0;
.

.

.

if(roll==4||roll==5||roll==6||roll==8||roll==9||roll==10)//point case
{
int flag = 0;
count<<"The point is "<<roll<<endl;
point = roll;
do
{
roll=dice();//dice- function that simulates the 2 dice throwings
count<<endl;
count<<"roll = "<<roll<<endl;
if(roll==7) {
count<<roll<<" was rolled. Player loses."<<endl; losses++; flag = 1; }
if(roll==point) {count<< roll<<" was rolled. Player got the 'point'. player wins"<<endl; wins++; flag = 1;}
} while (flag == 0)
}// end if

.
.
.

This seems to be what you were trying to say.
 
Last edited:

Similar threads

  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 11 ·
Replies
11
Views
4K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 2 ·
Replies
2
Views
8K
  • · Replies 33 ·
2
Replies
33
Views
7K
  • · Replies 53 ·
2
Replies
53
Views
10K
  • · Replies 3 ·
Replies
3
Views
2K
Replies
1
Views
2K