#!/usr/bin/perl use strict; use CGI; srand($$); my $cgi = new CGI; print $cgi->header; my $droll = 999999999; my $maxl = $cgi->param('maxl') || 500; my $minw = $cgi->param('minw') || 100; my $pw = $cgi->param('pw') || 0.49; my $submitted = $cgi->param('submitted') || "NA"; print STDERR "$pw and $cgi->param('pw')\n"; if ($maxl < 0 or $maxl > 10000){ print "

Max Loss should be between 0 and 10000, running with 500"; $maxl = 500; } if ($minw < 0 or $minw > 10000){ print "

Min Win should be between 0 and 10000, running with 100"; $minw = 100; } if ($pw < 0 or $pw > 0.5){ print "

Probability of Winning should be between 0 and 0.5, running with 0.49"; $pw = 0.49; } my $nPlayed = 0; my $nWon = 0; my $nLost = 0; my $totalWon = 0; my $totalLost = 0; if (open (F, "; chomp($file); close(F); ($nPlayed, $nWon, $totalWon, $totalLost) = split(" ", $file); $nLost = $nPlayed - $nWon; } display_header(); display_query(); display_result();# if ($submitted eq "Submit"); display_footer(); sub display_result{ my $start = 1; my $b = $start; my $sumb = $b; my $cums = 0; my $norm = 1.0/$droll; my $session = 0; my $trial = 1; my $new_session = 1; my $sum_all_bets = 0; my @all_lines; while ( $sumb <= $maxl and abs($cums) <= $maxl and $cums <= $minw ){ $cums = $cums - $sumb; my $r = int(100*rand ($droll)*$norm)/100.0; $sum_all_bets += $sumb; if ($r <= $pw){ # win $cums += 2*$sumb; if ($new_session){ push(@all_lines, "#Session $session. Betting $sumb\$. Random number $r < $pw Total Win = $cums; dropping bet to 1\$"); } else{ push(@all_lines, "                   Betting $sumb\$. Random number $r < $pw Total Win = $cums; dropping bet to 1\$"); } $sumb = $start; $b = $start; $trial = 1; $session++; $new_session = 1; push(@all_lines,"                   "); } else{ # loss $sumb += $b; if ($new_session){ push(@all_lines, "#Session $session. Betting $b\$. Random number $r > $pw Total Win = $cums; increasing bet to $sumb\$"); } else{ push(@all_lines,"                   Betting $b\$. Random number $r > $pw Total Win = $cums; increasing bet to $sumb\$"); } $b *= 2; $new_session = 0; $trial++; }# if-else }# while my $ngames = @all_lines; $session++; $sum_all_bets = int($sum_all_bets*100.0/$ngames)/100.0; if ($cums < 0){ $totalLost += $cums; print_line(" I am sorry, you lost $cums\$. You played $session sessions, $ngames games, betting $sum_all_bets\$ on average.
Scroll Down to see why, Press Submit to try again or Go back to advice Vegas page.
"); } else{ $nWon++; $totalWon += $cums; print_line(" Congratulations! You won $cums\$. You played $session sessions, $ngames games, betting $sum_all_bets\$ on average.
Scroll Down to see why, Press Submit to try again or Go back to advice Vegas page.
"); } $nPlayed++; if (open (F, ">/tmp/vegas.stats")){ print F "$nPlayed $nWon $totalWon $totalLost\n"; close(F); } print "
Key: :You Win;    :Casino Wins
"; for my $l (@all_lines){ print_line($l); } } sub print_line{ print < $_[0] EOF ; } ############################################################# HEADER sub display_header { if (open (F, "; chomp($file); print $file; close(F); } my $avWon = int(100*(($nWon > 0) ? $totalWon*1.0/$nWon : 0))/100.0; my $avLost = int(100*(($nLost > 0) ? $totalLost *1.0/$nLost : 0))/100.0; print < How to win in Vegas Demo                
How to Win in Vegas Demo Out of $nPlayed people who tried this demo, $nWon won with average win of $avWon\$ ...and $nLost lost an average of $avLost\$

EOF } sub display_query { print <
 
Max Loss to Stop     Min Win to Stop     Probability of Win       EOF ; print <
EOF } sub display_footer { if (open (F, "; chomp($file); print $file; close(F); } print < EOF }