#!/usr/bin/perl --
use List::Util 'shuffle';
%params = ();
$queryString = $ENV{"QUERY_STRING"};
@keyValuePairs = split(/\&/, $queryString);
foreach my $keyValuePair (@keyValuePairs) {
($key, $value) = split(/\=/, $keyValuePair);
$key =~ s/%([a-f0-9]{2})/chr(hex($1))/eig; # URL decode the key
$value =~ s/%([a-f0-9]{2})/chr(hex($1))/eig; # URL decode the value
$params{$key} = $value;
}
@deck = ();
@player = ();
@dealer = ();
@discard = ();
if(!$params{"SESSIONID"} || !-e "/tmp/r_leguen.cgi_blackjack.".$params{"SESSIONID"}) {
# if no session ID is provided,
# we initialize a session
@cards = (
"c_2", # the 2 of clubs
"c_3", # the 3 of clubs
"c_4", # the 4 of clubs
"c_5", # the 5 of clubs
"c_6", # the 6 of clubs
"c_7", # the 7 of clubs
"c_8", # the 8 of clubs
"c_9", # the 9 of clubs
"c_10", # the 10 of clubs
"c_j", #the Jack of clubs
"c_q", #the Queen of clubs
"c_k", #the King of clubs
"d_2", # the 2 of diamonds
"d_3", # the 3 of diamonds
"d_4", # the 4 of diamonds
"d_5", # the 5 of diamonds
"d_6", # the 6 of diamonds
"d_7", # the 7 of diamonds
"d_8", # the 8 of diamonds
"d_9", # the 9 of diamonds
"d_10", # the 10 of diamonds
"d_j", #the Jack of diamonds
"d_q", #the Queen of diamonds
"d_k", #the King of diamonds
"h_2", # the 2 of hearts
"h_3", # the 3 of hearts
"h_4", # the 4 of hearts
"h_5", # the 5 of hearts
"h_6", # the 6 of hearts
"h_7", # the 7 of hearts
"h_8", # the 8 of hearts
"h_9", # the 9 of hearts
"h_10", # the 10 of hearts
"h_j", #the Jack of hearts
"h_q", #the Queen of hearts
"h_k", #the King of hearts
"s_2", # the 2 of spades
"s_3", # the 3 of spades
"s_4", # the 4 of spades
"s_5", # the 5 of spades
"s_6", # the 6 of spades
"s_7", # the 7 of spades
"s_8", # the 8 of spades
"s_9", # the 9 of spades
"s_10", # the 10 of spades
"s_j", #the Jack of spades
"s_q", #the Queen of spades
"s_k", #the King of spades
);
@deck = shuffle(@cards);
$sessionID = int(rand(999999999999999));
}
else { # if a session ID is provided, we initialize session data.
$sessionID = $params{"SESSIONID"};
open("SESSION", ";
chomp($cards);
@deck = split(/,/, $cards);
# we read the second line,
# which is the list of cards in the hand
# seperated by commas
$cards = \n";
if(@dealer) {
print "Welcome To CGI BlackJack
\n";
print "Dealer's Hand:
\n";
print $addition;
print "
";
for($i=1; $i<@dealer; $i++) {
if($params{"Action"} eq "Stand") {
print "
";
}
else {
print "
";
}
}
print "
\n"; if(@player) { print "