CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com

1. Junior Member
Join Date
Nov 2019
Posts
1

## Stuck with this Pigs game! Need some tips please!!

Hey there, I've been working on this program for my class and I don't know what I'm doing wrong... I have been stuck on this particular area for a few days now. It's the long weekend and it's due tomorrow evening so I can't ask my teacher. Everything else with my code is working great but the math isn't adding up properly. I have to create a gambling program that has two separate simulators in it.
1: Game of Craps
2: Game of Pigs

The Craps is working perfectly fine but there's one small area with my coding for my Pigs game that is driving me nuts. I'll post some of the code here and if you guys could offer me some guidance just to get the total points to add up properly, that would be swell. I've literally tried changing the loops around probably a dozen times and have decided to go with a couple separate methods for when the humans playing and the robot is playing. It's looping properly but the the total points are too much and the differences are a really weird amount. Any help would be greatly appreciated. Thanks! Just to make sure nobody gets the wrong idea, I'm not looking for anyone to just give me the correct answer for this math or the equations but if you could point me in the right direction, I would be very happy! I've called upon these two methods within the PigsSim() method.

Code:
```static void humanPigs()
{
int humanDiceNumber = 0;//dice roll for the human user
int maxPoints;//max amount of points to play for
int humanPoints = 0;//point value for each human dice roll
int humanRoundPoints = 0;//total amount of points for the humans round
int totalHumanPoints = 0;//total amount of points for the human for all rounds

bool isPlaying = true;

Random rand = new Random();

Console.WriteLine("---------------------");
Console.WriteLine("--Pigs (Human Turn)--");
Console.WriteLine("---------------------");

maxPoints = 100;

while (isPlaying)
{

for (int i = 0; i < 1; i++)//random num generator x1
{
humanDiceNumber = rand.Next(1, 7);//generator for numbers between 1-6

}
Console.WriteLine(\$"You rolled a {humanDiceNumber}");

if (humanDiceNumber == 1)
{
humanPoints = 0;
humanRoundPoints = 0;

isPlaying = false;
computerPigs();

}
else
{
humanPoints = humanDiceNumber;
humanRoundPoints += humanPoints;
totalHumanPoints += humanRoundPoints;

Console.WriteLine("Enter r to roll or h to hold (r/h): ");

{
case "r":
Console.WriteLine(\$"Your turn point total is {humanRoundPoints}");
break;
case "h":
isPlaying = false;
Console.WriteLine("You HOLD");
Console.WriteLine(\$"Your turn point total is {humanRoundPoints}");
Console.WriteLine("");
computerPigs();
break;
default:
isPlaying = false;
Console.WriteLine("Sorry that isn't a valid entry! You must be tired so I'll hold this for you and you can get some rest ;)");
Console.WriteLine("You HOLD");
Console.WriteLine(\$"Your turn point total is {humanRoundPoints}");
Console.WriteLine("");
computerPigs();
break;
}
if (totalHumanPoints >= maxPoints)
{

Console.WriteLine(\$"Your turn point total is {humanRoundPoints}");
Console.WriteLine("");
Console.WriteLine("YOU WIN!!");

isPlaying = false;
}
}
}
}
static void computerPigs()
{
int computerDiceNumber = 0;
int maxPoints;//max amount of points to play for
int computerPoints = 0;//point value for each computer dice roll
int computerRoundPoints = 0;//total amount of points for the computers round
int totalComputerPoints = 0;//total amount of points for the computer for all rounds

maxPoints = 100;

Random rand = new Random();

bool isPlaying = true;

Console.WriteLine("------------------------");
Console.WriteLine("--Pigs (Computer Turn)--");
Console.WriteLine("------------------------");

Console.WriteLine("It's the computer's turn!!");

while (isPlaying)
{

for (int i = 0; i < 1; i++)//random num generator x1
{
computerDiceNumber = rand.Next(1, 7);//generator for numbers between 1-6

}
Console.WriteLine(\$"Computer rolled a {computerDiceNumber}");

if (computerDiceNumber == 1)
{
computerPoints = 0;
computerRoundPoints = 0;

Console.WriteLine(\$"Computer's turn score is {computerRoundPoints}");

isPlaying = false;
humanPigs();

}
if (computerDiceNumber != 1)
{
computerPoints = computerDiceNumber;
computerRoundPoints += computerPoints;
totalComputerPoints += computerRoundPoints;

if (computerRoundPoints >= 10)
{

Console.WriteLine("Computer HOLDS");
Console.WriteLine(\$"Computer's turn point total is {computerRoundPoints}");
Console.WriteLine("");
Console.WriteLine(\$"Computer's total points: {totalComputerPoints}");
isPlaying = false;
humanPigs();
}
if (totalComputerPoints >= maxPoints)
{
Console.WriteLine(\$"Computer's turn point total is {computerRoundPoints}");
Console.WriteLine("");
Console.WriteLine("YOU WIN!!");
Console.WriteLine(\$"Computer's total points: {totalComputerPoints}");
isPlaying = false;
}
}
}
}```
Last edited by Arjay; November 10th, 2019 at 11:02 PM. Reason: Added code taga

2. ## Re: Stuck with this Pigs game! Need some tips please!!

Were you taught how to use the debugger so you can debug your code?

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•