Note: I've emailed my professor but haven't received a reply yet. I hate being so behind in this class! >:O
So... after the cut!
This is the assignment:
In the game of Craps, a "Pass Line" bet proceeds as follows. Using two six-sided dice, the first roll of the 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 roll 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, then the player loses.
Write a program that plays the game of Craps using the rules stated above so that it simulates a game without human input. Instead of asking for a wager, the program should just calculate if the player would win or lose. The program should simulate rolling the two dice and calculate the sum. Add a loop so that the program plays 10,000 games. Add counters that count how many times the player wins, and how many times the player loses. At the end of the 10,000 games, compute the probability of winning, i.e. Wins / (Wins + Losses) and output this value. Over the long run, who is going to win the most games of Craps, you or the house?
Note: To generate a random number x, where 0 <= x < 1, use x = Math.random(); . For example, multiplying by six and converting to an integer results in an integer that is from 0 to 5.
They started the code out in their MyCodeMate program like this:
/**
* This program simulates 10,000 games of craps.
* It counts the number of wins and losses and outputs the probability
* of winning.
*/
public class Craps {
public static int NUM_GAMES = 10000;
public static void main(String[] args) {
int numWins = 0;
int numLosses = 0;
// --------------------------------
// ----- ENTER YOUR CODE HERE -----
// --------------------------------
// Output probability of winning
System.out.println("In the simulation, we won " + numWins +
" times and lost " + numLosses + " times, ");
System.out.println("for a probability of " +
(double)(numWins)/(double)(numWins + numLosses));
}
}
I have written out a bit of preliminary coding myself (I can email it to someone if they'd like) but when I compile it, it's not working :(
So, suffice to say, I'm really frustrated and I wish I had dropped the class : /
No comments:
Post a Comment