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

Re: [FWP] Perl Card Games



>>>>> "GY" == Gaal Yahas <gaal@forum2.org> writes:

  GY> On Fri, Aug 06, 1999 at 10:53:58AM +0100, Peter Haworth wrote:
  >> > Why waste characters<tm>[1]?
  >> > 
  >> > %cards = ( sort(1..10,1..10),  J => 11, Q => 12, K => 13, A => 14, );
  >> > #                                                and note A != K :-)
  >> 
  >> Oh dear. Now your deck has 56 or 58 cards. You don't need both '1' and 'A' in
  >> there, even if A != K

  GY> You're right, of course. The following should fix it:

  GY> %cards = ( sort(1..10,1..10), J => 11, Q => 12,
  GY> 	K => 13, A => $cards{1}, ) for (1,2);

why is 1 and A in there? that sill makes 14 cards even if A and 1 are
both => 1.

again, i don't know the major goal here but what about hash slices?

@cards = 2 .. 10, qw( J Q K A ) ;
@cards{ @cards } = 2 .. (@cards + 1 ) ;

but i would do it the other way around. i would keep all internal card
info as integers 0 .. 12 and only convert them on I/O.

uri

-- 
Uri Guttman  -----------------  SYStems ARCHitecture and Software Engineering
uri@sysarch.com  ---------------------------  Perl, Internet, UNIX Consulting
Have Perl, Will Travel  -----------------------------  http://www.sysarch.com
The Best Search Engine on the Net -------------  http://www.northernlight.com
"F**king Windows 98", said the general in South Park before shooting Bill.

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