I'm learning perl, been reading some pdfs and such which doesnt really help sink the info. So i decided to do what I did to help me with python, build something of a poker game. The cards are successfully dealt, now im working on splitting up the card terms to analyze what they're worth and alot scores.
#!/usr/bin/perl -w
use strict;
our @cards = ("Ace of Spades","Two of Spades","Three of Spades,"Four of Spades,"
Five of Spades","Six of Spades","Seven of Spades","Eight of Spades",
"Nine of Spades","Ten of Spades");
#I have the rest of the cards in this array, but 10 is enough for testing
sub fisher_yates_shuffle {
my $deck = shift;
my $i;
for ($i = @@$deck; --$i ){
my $j = int rand ($i+1);
next if $i == $j;
@$deck[$i,$j] = @$deck[$j,$i];
}
deal();
}
sub deal {
my @ply1hand = 0;
my @ply2hand = 0;
print "Player 1s hand:\n";
for (my $dealcount = 0; $dealcount <= 4; $dealcount++) {
$ply1hand[$dealcount] = pop(@cards);
print $ply1hand[$dealcount], "\n";
}
print "\nPlayer 2s hand:\n";
for (my $dealcount = 0; $dealcount <= 4; $dealcount++) {
$ply2hand[$dealcount] = pop(@cards);
print $ply2hand[$dealcount], "\n";
}
print @ply1hand;
calc(\@ply1hand);
calc(\@ply2hand);
}
sub calc {
my $card1 = $_[0];
my $card2 = $_[1];
my $card3 = $_[2];
my $card4 = $_[3];
my $card5 = $_[4];
print "card1: $card1";
#This prints the memory address and not the single card I want. I've played around with this function quite a bit and cant get it to print a card. The idea is to split the card at white space so i can reference the face value and the suit.