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

Re: [FWP] Perl Card Games



"Mike Upmalis" <mupmalis@i-com.com> writes:

> As a small note about the difference between a "good" shuffle and a "real"
> shuffle. When the American Contract Bridge League started using computer
> generated hands in the seventies, they had a bad reaction to those "crazy
> computer hands". The problem it turned out was that the computer generated
> deals were too good. They had perfect distribution, but people shuffling
> decks had real shuffles. People were used to poor distribution.
> 
> You can also purposely generate bad shuffles. If a hand is passed out, you
> stack the four hands after people sort them into suits, cut, and then deal
> 4-4-4-4, 5-5-5-5, 4-4-4-4. It is a goulash, or hungarian goulash deal.
> 
> Call it a human factor.  By the way, you only need 7 good shuffles to
> maximize randomness. I can supply the source, but it sticks in my memory.

One problem:  a perfect rifle shuffle will always eventually come back
to the starting card order.  The number of shuffles it takes varies,
but for powers of two (ie decks of 32, 64, etc) it takes log_2 (num
cards) to get back to the original order.

Of course, rifling perfectly is a very difficult thing to do once,
much less 13 or so times (which I believe is what it takes for a 52
card deck).

Algorithm:

@cards = (1 .. 52);
$shuffles = 8;
while ($shuffles--) {
  @a = @cards[0 .. @cards/2 - 1];
  @b = @cards[@cards/2 .. @cards - 1];
  @cards = map { ($a[$_], $b[$_]) } (0 .. $#a);
}

print "@cards\n";

Okay, 8 times for a deck of 52, just checked.  Rifle shuffling isn't
very random at all.  But it is more realistic.

Chip

-- 
Chip Turner                   chip@ZFx.com
                              Programmer, ZFx, Inc.  www.zfx.com
                              PGP key available at wwwkeys.us.pgp.net

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