I'm replying to the digest. Is that not allowed? > ------------------------------ > > From: Brand Hilton <bhilton@adc.com> > > 'Course, if it was me, I'd just do > > use Algorithms::Numerical::Shuffle; > @cards = (0 .. 51); # or any number of them > @cards = shuffle(@cards) > Abigail indeed uses the (non-clobbering) N-swaps method, adding in the ability to handle ref'ed arrays in place (no memory overhead) or regular arrays. I suppose that's why Abigail is a Perl Somebody. I *could* steal this, although you should never underestimate the power of the Schwartz. But it means if I ever created a really good module and put it on CPAN, then people would have to download another module to use it. Not a problem for one module, but what if I use six different existing modules? Have others found this to be a problem with writing modules? Or do you just figure if people want to use your module they should suck it up and download the necessary prerequisites? CPAN *does* make it easy, after all (especially the CPAN module!) > ------------------------------ > > From: Matthew Bafford <dragons@dragons.duesouth.net> > > Heh, that reminds me of the slot machine game I used to play on my ol' > C64. After a while I got tired of pushing the 'pull' button, so I just > changed the code slightly to make the computer do it automatically. > > That kinda took the last bit of fun out of it... Um, that's implying that there's a bit of fun in it in the first place, which may be true for seven-year-olds, but isn't really for us old people. > HtAAoF! Um, what's that? [much snippage] A couple minor points: > my %cards = ( > 2 => 2, 3 => 3, 4 => 4, 5 => 5, 6 => 6, 7 => 7, > 8 => 8, 9 => 9, J => 10, Q => 11, K => 12, A => 13, > ); Oops! What about "10"? Otherwise your deck has only 48 or 50 cards. > sub compare_cards { my ($a, $b) = map { /.(.)/ } @_; > $cards{$a} <=> $cards{$b} } Once you add 10, which is two characters, this doesn't work :( > sub score { my $c; $c += $cards{ (/.(.)/)[0] } for @_; $c } Nice idea for resolving a tie. Another option would be a fistfight. > while ( @deck ) { > push @a, splice(@deck, rand @deck, 1); > push @b, splice(@deck, rand @deck, 1); > } This neatly steps around the shuffling in place discussion. Of course, it won't work for rummy, say. [Instructions:] > First the the deck of 52 (or 54) cards is shuffled and evenly distributed > amongst the players (usually 2, but games of 3 or 4 also play quite nicely, > although slightly differently). I'm getting a vague picture from my early childhood of playing three-way war. Of course, getting the computer to play three-way war is at least as useless as having it play two-way war. I'm getting a slightly less vague memory of my friends in college who would play MacRisk with all computer characters & see which personality (e.g. one computer character type was aggressive, meaning it always attacked as long as it could, another was more conservative, taking just one country at a time, etc.) would win. Wow, college was pretty exciting. > ------------------------------ > > From: Chip Turner <chip@zfx.com> > > @a = (rand(@cards) % @cards, $_ % @cards), @cards[@a] = @cards[reverse @a] > foreach 0 .. ($passes * @cards - 1); Btw, save bytes by not taking %cards for rand(@cards), which certainly gives you a number from 0..@cards. > @cards = map { $_->[0] } > sort { $a->[1] <=> $b->[1] } > map { [ $_, rand(1 << 31) ] } > (0 .. 51); > > That has a certain aesthetic niceness to it. I think someone did a > similar one earlier. Yup. In fact, it's my original shuffle, except that you don't have to take rand(1<<31), you can just use rand(). Then perl sorts the 52 floats from between 0 and 1. -Amir ==== Want to unsubscribe from Fun With Perl? Well, if you insist... ==== Send email to <fwp-request@technofile.org> with message _body_ ==== unsubscribe