[EMAIL PROTECTED] wrote:
Hi Members,
Hello,
2) How do I shorten/improve this script.
You could try it like this:
##### start of script #################
use strict;
use warnings;
use List::Util qw/ shuffle /;
my %config = (
number_of_games => 5_000,
capital => 1_000,
originalcapital => 1_000,
betting_system => 18,
bet_amount_per_number => 2,
wincounter => 0,
losscounter => 0,
roulette_dealer_number => 0,
);
# dealers number rolled
for ( 1 .. $config{ number_of_games } ) {
different_playing_styles( ( 0 .. 36 )[ rand 37 ], shuffle 0 .. 36 );
}
my $win_loss = $config{ capital } > $config{ originalcapital } ? 'win' :
'lost';
my $amount = ( $config{ capital } - $config{ originalcapital } ) * (
$config{ capital } > $config{ originalcapital } ? 1 : -1 );
print "Summary\n",
"Betting system = Bet $config{betting_system} numbers at ",
"\$$config{bet_amount_per_number} per number.\n",
"Total games dealt = $config{number_of_games} games.\n",
"Total : Win = $config{wincounter} times = \$",
( 36 - $config{ betting_system } ) * $config{ bet_amount_per_number
} * $config{ wincounter },
"\nLose = $config{losscounter} times = \$",
$config{ betting_system } * $config{ bet_amount_per_number } *
$config{ losscounter },
"\nYou $win_loss \$$amount\n",
'*' x 50,
"\n";
#####################################################
# sub routines
######################################################
sub different_playing_styles {
my ( $roulette_dealer_number, @numbers ) = @_;
if ( grep $_ == $roulette_dealer_number, @numbers[ 0 .. $config{
betting_system } ] ) {
$config{ wincounter }++;
$config{ capital } = ( $config{ capital } + 36 - $config{
betting_system } ) * $config{ bet_amount_per_number };
}
else {
$config{ losscounter }++;
$config{ capital } = ( $config{ capital } - $config{
betting_system } ) * $config{ bet_amount_per_number };
}
}
__END__
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/