I've probably got the logic wrong somewhere, but if I haven't, it appears as though it might worthwhile (but not by much:^) taking up craps using a simple strategy and sticking to it.

#! perl -sw use strict; use vars qw($runs $games $pot $bet); $runs ||= 100; $games ||= 100; $pot ||= 100; $bet ||= 1; #srand(1); #! for consistant results whilst testing. sub rolldice() { return int(1+rand(6)) + int(1+rand(6)); } #! 0 1 2 3 4 5 6 7 8 9 10 11 +12 my @passline = ( 0, 0, -1, -1, 0, 0, 0, +1, 0, 0, 0, +1, - +1 ); my @odds = ( 0, 0, 0, 0, 2, 1.5, 1.2, -1, 1.2, 1.5, 2, 0, 0 + ); my %results; for(1 .. $runs) { my $pot = $pot; #! Start with som money in the kitty for (1 .. $games) { my $bet = $bet; my $point = rolldice(); # print "pot:$pot bet:$bet point:$point"; <>; if (my $pays = $passline[$point]) { $pot += $bet * $pays; next; #! Game over } my $roll; do { $bet++ if ($pot-$bet); $roll = rolldice(); # print "pot:$pot bet:$bet roll:$roll"; <>; } until ($roll == $point or $roll == 7); $pot += int($bet * $odds[$roll]); #! Round $pot = 0,last if $pot <= 0; #! Can't continue if we've lost it + all } $results{$pot-$::pot}++; } print "Over $runs runs of up to $games games produced ", scalar keys % +results, " different outcomes\n"; my @outcomes = sort{$a<=>$b} keys %results; my ($start, $end) = ( 10*int($outcomes[0]/10), 10*(int($outcomes[-1]/1 +0)+1) ); my ($lost,$even,$won)= (0,0,0); print ' : 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 + | 9 |'; for (my $i=$start; $i <=$end; $i+=10 ) { printf "$/% 7.2f :", $i; for(my $result=$i; $result<=($i+9); $result++){ print ' -- |' and next unless exists $res +ults{$result}; printf '*%4d*|', $results{$result} and next if $result == -$po +t;; $lost += $results{$result} if $result < 0; $won += $results{$result} if $result > 0; printf '%4d |', $results{$result}; } } printf "\n\nBusted:%6.2f%% lost:%6.2f%% even:%6.2f%% won:%6.2f%%\n", $results{-$pot}*100/$runs, $lost*100/$runs, $results{0}*100/$runs, $won*100/$runs; __END__ c:\test>craps -runs=1000 -games=100 -pot=100 -bet=1 Over 1000 runs of up to 100 games produced 216 different outcomes : 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 + | 9 | -100.00 :* 43*| -- | 1 | 3 | 1 | 1 | 2 | 2 | 2 + | 1 | -90.00 : 2 | 1 | 5 | 2 | 2 | -- | 1 | 1 | 2 + | -- | -80.00 : 3 | -- | 2 | 1 | 1 | 1 | 5 | 3 | 3 + | 3 | -70.00 : 1 | 3 | -- | 3 | 5 | 2 | 5 | 7 | 1 + | 7 | -60.00 : 3 | 1 | 3 | 4 | 2 | 3 | 1 | 9 | 5 + | 1 | -50.00 : 4 | 3 | 10 | 7 | 6 | 7 | 6 | 8 | 12 + | 7 | -40.00 : 3 | 6 | 6 | 11 | 10 | 10 | -- | 7 | 8 + | 1 | -30.00 : 1 | 8 | 4 | 6 | 9 | 4 | 6 | 8 | 4 + | 8 | -20.00 : 7 | 7 | 7 | 4 | 6 | 3 | 6 | 7 | 7 + | 13 | -10.00 : 7 | 9 | 10 | 10 | 7 | 5 | 10 | 1 | 13 + | 9 | 0.00 : 9 | 4 | 7 | 11 | 8 | 6 | 4 | 8 | 10 + | 11 | 10.00 : 10 | 9 | 3 | 9 | 7 | 8 | 6 | 5 | 10 + | 6 | 20.00 : 9 | 9 | 9 | 7 | 10 | 3 | 4 | 4 | 10 + | 5 | 30.00 : 4 | 8 | 6 | 4 | 7 | 5 | 4 | 4 | 12 + | 2 | 40.00 : 3 | 2 | 5 | 4 | 11 | 3 | 3 | 2 | 4 + | 4 | 50.00 : 4 | 5 | 6 | 1 | 5 | 8 | 7 | 2 | -- + | 3 | 60.00 : 3 | 3 | 3 | 5 | 5 | 2 | 5 | 4 | -- + | 2 | 70.00 : 3 | 1 | 2 | 4 | 3 | 5 | 3 | 3 | 1 + | 3 | 80.00 : 2 | 2 | 1 | 5 | 1 | 4 | 1 | 3 | 3 + | 1 | 90.00 : 3 | 1 | 1 | 2 | 4 | 3 | 3 | 4 | -- + | 1 | 100.00 : 2 | 1 | 1 | 3 | 1 | -- | 2 | 2 | 2 + | -- | 110.00 : -- | 3 | -- | 1 | -- | -- | -- | -- | 1 + | 3 | 120.00 : -- | 1 | -- | 2 | 1 | 2 | 1 | 1 | 1 + | 1 | 130.00 : -- | -- | -- | -- | -- | 1 | -- | 1 | -- + | 1 | 140.00 : -- | -- | -- | -- | -- | 1 | -- | -- | -- + | 2 | 150.00 : -- | -- | -- | -- | -- | -- | -- | -- | -- + | -- | Busted: 4.30% lost: 45.50% even: 0.90% won: 49.30% c:\test>

Cor! Like yer ring! ... HALO dammit! ... 'Ave it yer way! Hal-lo, Mister la-de-da. ... Like yer ring!

In reply to Re: check my logic & a random number issue by BrowserUk
in thread check my logic & a random number issue by rmckillen

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.