#!/usr/bin/perl # MyPerlCrap is meant to simulate playing the field at a craps table, # using my own method of betting (a variation of "double and add"). # My motivation for writing this script is to work on improving my # Perl skills. The script runs until one million dollars is won, or # the player goes broke. # **** work-in-progress, script not complete yet ***** # **** work-in-progress, script not complete yet ***** # **** work-in-progress, script not complete yet ***** # MyPerlCrap, version 0.1, Copyright (C) 2008 Joey Kelly, http://joeykelly.net # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # version 2, as published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. use strict; # ok, here's the core algoritm: # # 1. bet # 2. roll the dice # 3. if $roll in @valid, $win++ # 4. else bet and roll again # 5. if I exceed my bet limit, start over # 6. continue until I make a million dollars, or go broke my $range = 6; my $minimum = 1; my %validrolls = ( 2 => 'two', 3 => 'three', 4 => 'four', 9 => 'nine', 10 => 'ten', 11 => 'eleven', 12 => 'twelve', ); my %paysdouble = ( 2 => 'two', 12 => 'twelve', ); my $bank = 100; my $wager = 1; my ($roll, $win, $lose, $wincount, $losscount, $winsinarow, $lossesinarow, $maxwins, $maxlosses); my @iterations = (1..5000000); #my @iterations = (1..20); for (@iterations) { # change this later, I'm just trying to run a bunch of rolls for now $roll = get_roll(); if ($validrolls{$roll}) { # print "$roll... WIN!\n"; $win++; # $winsinarow++; $wincount++; $lossesinarow = $losscount if ($losscount > $lossesinarow); $losscount = 0; } else { # print "$roll... LOSE!\n"; $lose++; # $lossesinarow++; $losscount++; $winsinarow = $wincount if ($wincount > $winsinarow); $wincount = 0; # roll again } } # end iterations print "wins = $win, losses = $lose\n"; print "wins in a row = $winsinarow, losses in a row = $lossesinarow\n"; sub get_roll { my $die1 = int(rand($range)) + $minimum; my $die2 = int(rand($range)) + $minimum; my $roll = $die1 + $die2; return $roll; }