[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [FWP] Perl Card Games



Uri wrote:
> 
> but what do you mean by deal? shuffling 1 .. 52 is a deal in my
> book. the numbers are unique and in random order.

I meant deal as distinct from shuffle.  You know, first card to the
first hand, next card to the next hand, etc.  As I said, not  necessary
if the randomization is good.


>   JP> 	$hands[$_] = splice @shuffled, 0, 13 for 0..3;
> 
> that doesn't work as you are assigning a list to a scalar.
> you need an anon array there.

Obviously.


> and why do a splice when a slice will do?

If you do a slice, then you have to keep track of your slice beginning.
Splice can always start at 0  -- ergo simpler code.


> $card = rand @deck, ( $deck[$card], $deck[$_] ) = ( $deck[$_], $deck[$card] )
> 		for 0 .. $#deck ;

Oh, yeah, that's beautiful code.     :-P


> push( @hands, [ splice( @deck, 0, 13 ) ] ) for 0 .. 3;


$handsize = 5; # straight poker.
@hands = 5;    # O.k., who's in?
@$_ = splice @deck, 0, $handsize  for @hands;  # too much fun.


John Porter


==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe