There is a logical error somewhere in the game that has to do with my win and lose boolean values making the game print out both a win or loss on the first roll, as well as the end value always being true, but I'm not sure where it is.
My best guess is around where it checks for the win or loss conditions.
package bergman.java.ass2;
import java.util.Random;
/**
*
* @author Jason
*/
public class GameSimulation {
public static void main(String[] args) {
//create dice
int die1, die2;
//create the counters for the wins and the times the program runs
int runsCounter, winsCounter = 0, loseCounter = 0;
//Create the variable to check whether it is the initial roll or not
boolean firstRoll;
//create a variable to store the initial point of the roll
int rollPoint = 0;
//Create the variable to store the random number
Random rand = new Random();
//Create a variable to check whether a win/loss is true or not
boolean win = false, lose = false;
for(;runsCounter < 10000;){
//roll the dice for initial roll
firstRoll = true;
die1 = rand.nextInt(6) + 1;
die2 = rand.nextInt(6) + 1;
//check if it's the first roll
if (firstRoll = true) {
//if it's a 7 or 11 on first roll add a win
if (die1 + die2 == 7 || die1 + die2 == 11) {
System.out.print("you win! with rolls " + die1 + " and "
+ die2 + "\n");
firstRoll = false;
win = true;
}
//if it's a loss on the first roll add a loss
if (die1 + die2 == 2 || die1 + die2 == 3 || die1 + die2 == 12) {
System.out.print("You lose! with rolls " + die1 + " and "
+ die2 + "\n");
firstRoll = false;
lose = true;
}
//if it's neither, store the roll and end the loop
else {
rollPoint = die1 + die2;
firstRoll = false;
}
}
//check if first roll was a win or loss, if not continue rolling
for (; win == false && lose == false;) {
die1 = rand.nextInt(6) + 1;
die2 = rand.nextInt(6) + 1;
//check if the new roll matches point or 7
if (die1 + die2 == rollPoint) {
win = true;
} else if (die1 + die2 == 7) {
lose = true;
}
}
//utilize win/loss statements within loop
if (win = true) {
winsCounter = winsCounter++;
System.out.print("You win with rolls " + die1
+ " and " + die2 + " with a point roll for " + rollPoint);
win = false;
} else if (lose = true) {
System.out.print(" you lose by rolling a 7 before point score");
loseCounter = loseCounter++;
lose = false;
}
}
}
}