The idea here is I want the initial hash to be run into the child function, have changes made, send the changes back to the parent. Then send the changed hash into the child for more changes to take place. I've been making a poker program to help me learn, and here are the functions in question:
It might not be the best way to make poker, but I did it like this in python and it worked.
#hand is fed 5 cards(an array) to be analyzed for what they're worth. The function #is all called with a number to indicate which player it is.
sub hand {
my($cards) = shift;
my %ply1score = (2 => "0", 3 => "0", 4 => "0", 5 => "0", 6 => "0", 7 => "0",
8 => "0", 9 => "0", 10 => "0", 11 => "0", 12 => "0", 13 => "0",
14 => "0", s => "0", c => "0", d => "0", h => "0");
my %ply2score = (2 => "0", 3 => "0", 4 => "0", 5 => "0", 6 => "0", 7 => "0",
8 => "0", 9 => "0", 10 => "0", 11 => "0", 12 => "0", 13 => "0",
14 => "0", s => "0", c => "0", d => "0", h => "0");
for (@$cards){
print "card: $_\n";
my @whatisit = split;
if ($_[0] eq 1){
calc($whatisit[0],$whatisit[2], %ply1score);
}
if ($_[0] eq 2){
calc($whatisit[0],$whatisit[2], %ply2score);
}
}
}
sub calc {
my $face = $_[0];
my $suit = $_[1];
my %score = @_;
if ($face eq "Ace") {
$score{14}++;
}
if ($face eq "Two") {
$score{2}++;
}
if ($face eq "Three") {
$score{3}++;
}
if ($face eq "Four") {
$score{4}++;
}
if ($face eq "Five") {
$score{5}++;
}
if ($face eq "Six") {
$score{6}++;
}
if ($face eq "Seven") {
$score{7}++;
}
if ($face eq "Eight") {
$score{8}++;
}
if ($face eq "Nine") {
$score{9}++;
}
if ($face eq "Ten") {
$score{10}++;
}
if ($face eq "Jack") {
$score{11}++;
}
if ($face eq "Queen") {
$score{12}++;
}
if ($face eq "King") {
$score{13}++;
}
if ($suit eq "Diamonds") {
$score{d}++;
}
if ($suit eq "Clubs") {
$score{c}++;
}
if ($suit eq "Hearts") {
$score{h}++;
}
if ($suit eq "Spades") {
$score{s}++;
}
return %score;
}
So after checking for the face and suit, there should be a change of values from 0 to 1. Which there is for %score. But once returned I would like ply1score to see that as well, but it stays at 0 throughout.