in reply to check my logic & a random number issue
The reason I think something is wrong, is because when I simulated just 100 trials, there were a number of identical net win/loss results that occured twice. Is my logic, or random number generation the problem?Other than just eyeballing the results, what statistical analyses have you performed? Have you checked that your average dice roll is 7? When I added code in to print the average dice roll, I noticed that there's a condition that you haven't covered.
Because you put $gameover = 1 at the start of that conditional block you don't need to continue to do so for each specific condition. Unless, of course, you had intended to remove that first $gameover = 1.if ($roll == $point) { $gameover = 1; if ($roll == 6 || $roll == 8) { $gameover = 1; #not necessary $winnings += 1.2 + 1; print "WIN $winnings\n"; } elsif ($roll == 5 || $roll == 9) { $gameover = 1; # not necessary $winnings += 1.5 + 1; print "WIN $winnings\n"; } elsif ($roll == 4 || $roll == 10) { $gameover = 1; # not necessary $winnings += 2 + 1; print "WIN $winnings\n"; } else { print "what happens here?"; # loss? draw? } }
Is it these kind of pairs that are bothering you?
because chances are high that these are just statistical fluctuations. If you look at the dice rolls that generate these losses you'll find that they're all different. The game of craps may just be weighted to encourage losses. ;)LOSE -1 average dice roll: 7 LOSE -1 average dice roll: 8 LOSE -2 average dice roll: 7 LOSE -2 average dice roll: 7 LOSE -1 average dice roll: 7 LOSE -1 average dice roll: 7
You'll notice that 8 in my average dice roll. This is a running average and those 5 losses just happened to be results 5 - 10 of a simulation. The average ought to stay around 7 but will fluctuate around it through about 3 standard errors. ;)
So, in conclusion, yes there is a logic error in your code, your game occasionally ends without setting wins or losses. Had you kept a total of games played you might have spotted this. Whether or not your random number generator is non-random or your use of it is flawed can only really be determined by analysing it in the same using something similar to what dws suggested.
Your logic may contain other errors but as I've never studied the game of craps I have no idea what the frequency of certain results should be. Should you lose more often than you win, but win bigger? Should you lose 1 unit twice as often as you lose 2 units? I'm 100% certain that there are statistic tables out there for this game just as there are for other casino games. Once you have that data, you'll be able to analyse your results better and check whether they're in line with what they should be.
Hope it helps
jarich
PS: for the interests of simplifying your code, you can easily drop the database stuff.
PPS: FWIW in the interests of not installing more stuff, my roll function came out to be:
sub rolldice() { # was: my $roll = int(rand(12)) + 1; my $d1 = int(rand(6)) + 1; my $d2 = int(rand(6)) + 1; my $roll = $d1 + $d2; return $roll; }
Update: Didn't think hard enough about my rolldice function. Fixed now.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: check my logic & a random number issue
by blahblahblah (Priest) on Oct 11, 2002 at 04:15 UTC | |
by jarich (Curate) on Oct 11, 2002 at 05:24 UTC | |
|
Re: Re: check my logic & a random number issue
by Daruma (Curate) on Oct 11, 2002 at 05:19 UTC | |
by jarich (Curate) on Oct 11, 2002 at 05:42 UTC | |
by rmckillen (Novice) on Oct 11, 2002 at 17:21 UTC |