Hello all, monks.

I was playing with Perl, trying to get a poker game, or a game of any origin with cards probably doing some coding, but I`ve encountered a bizzare problem . Here is some code and I`ll add in later the problem.

Looks like I`ve managed to get it work fine for now

View the screenshoto
#!/usr/bin/perl use strict; use utf8; use warnings; ########## S U B R O U T I N E S ######################## #deck creator using a really simpla algorithm #DECK MAKER sub deck_maker { my @deck = (); #the deck for returning my @types = ('spades', 'hearts', 'diamonds', 'clubs'); my @cards = ( [2,3,4,5,6,7,8,9,10,'J','Q','K','A'], [2,3,4,5,6,7,8,9,10,'J','Q','K','A'], [2,3,4,5,6,7,8,9,10,'J','Q','K','A'], [2,3,4,5,6,7,8,9,10,'J','Q','K','A'] ); for ( my $i=0; $i < 4; $i++) { for ( my $j=0; $j < 13; $j++) { #pops an element from array my $newcard = pop($cards[$i]) . " of " . $types[$i]; push(@deck, $newcard); } } return @deck; #return the new deck } #SWAP sub swap_two { #really simple swap ($_[0], $_[1]) = ($_[1], $_[0]); } #SHUFFLE sub shuffle { #simple shuffling algorithm #there are 52 cards always but $#shuffle+1 can be used too... it`s + useless #unless there are people that don`t know there are 52 cards in tot +al. for (my $i=0; $i < 52; $i++) { my $card1 = int rand(52); my $card2 = int rand(52/2); &swap_two($_[$card1], $_[$card2]); } my (@cut1) = @_[0..($#$_+1)/2]; my (@cut2) = @_[($#$_+1)/2..$#$_+1]; push(@_ , @cut2); push(@_, @cut1); } #PICK A CARD sub pick_a_card { my $deck = shift; return pop @$deck; } sub show_my_hand { print "~~"x40,"\n"; foreach my $cards (@_) { print "[", $cards, "]"; } print "\n", "~~"x40,"\n"; } ################################################# # THE GAME STARTS BELOW ############################ ################################################ # init the deck and shuffle it my @deck = &deck_maker; &shuffle(@deck); # end of deck manipulations my (@hand) = (); push (@hand, &pick_a_card(\@deck)); push (@hand, &pick_a_card(\@deck)); push (@hand, &pick_a_card(\@deck)); push (@hand, &pick_a_card(\@deck)); push (@hand, &pick_a_card(\@deck)); &show_my_hand(@hand); #game loop here

Since the problem is solved, are there any free time monks who wish to make a simple poker game with some Tk or SDL for minimal gui???

Here is a simple output to my code:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~ [K of diamonds][10 of clubs][4 of clubs][5 of clubs][6 of clubs] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~ **************************************** Deck No. 0 has 6 of spades Deck No. 1 has 8 of spades Deck No. 2 has J of hearts Deck No. 3 has Q of spades Deck No. 4 has 7 of spades Deck No. 5 has 9 of diamonds Deck No. 6 has 3 of clubs Deck No. 7 has 2 of clubs Deck No. 8 has A of clubs Deck No. 9 has 5 of spades Deck No. 10 has 2 of diamonds Deck No. 11 has 8 of clubs Deck No. 12 has 9 of spades Deck No. 13 has 10 of spades Deck No. 14 has 6 of hearts Deck No. 15 has 4 of spades Deck No. 16 has 2 of spades Deck No. 17 has 8 of hearts Deck No. 18 has A of hearts Deck No. 19 has 4 of diamonds Deck No. 20 has 9 of hearts Deck No. 21 has 7 of diamonds Deck No. 22 has J of clubs Deck No. 23 has 10 of hearts Deck No. 24 has A of spades Deck No. 25 has 2 of hearts Deck No. 26 has A of diamonds Deck No. 27 has K of hearts Deck No. 28 has Q of diamonds Deck No. 29 has J of diamonds Deck No. 30 has 10 of diamonds Deck No. 31 has Q of clubs Deck No. 32 has 8 of diamonds Deck No. 33 has K of spades Deck No. 34 has 6 of diamonds Deck No. 35 has 5 of diamonds Deck No. 36 has 4 of hearts Deck No. 37 has 3 of diamonds Deck No. 38 has J of spades Deck No. 39 has 7 of hearts Deck No. 40 has K of clubs Deck No. 41 has 5 of hearts Deck No. 42 has Q of hearts Deck No. 43 has 3 of hearts Deck No. 44 has 9 of clubs Deck No. 45 has 3 of spades Deck No. 46 has 7 of clubs

In reply to What I am missing here by heatblazer

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.