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

Re: [FWP] Perl Card Games



That is serious fun; thanks for sharing!

It's most interesting seeing other ways of doing things. Shaking up your
assumptions and so forth.

For instance, your base representation is that a deck, or a hand, is an array
of references to card objects, each with suit and value. It never would have
occurred to me to structure things that way; I've always assumed that when
programming a deck of cards would be modelled by an array of integers, and
things like suits and values just show up in display.

But your approach is very pretty; I may try it next time. Vaguely related, I
recently had to tackle a fairly nightmarish task, reading a half-dozen tables
and writing a few thousand files containing various slices and dices of the
data from those tables; I ended up going with an extremely wasteful internal
representation of the tables, and the resulting cumbersome, not-very-terse
code carried so much internal documentation that a friend was able to pick up
maintenance on it with no handoff at all. The table representations that
worked for me were along the lines of

	$table = {
		key1 => {
			colname1 => value1,
			colname2 => value2,
			...
		},
		key2 => {
			...
	}

for tables that had distinct keys, and

	$table = [
		{
			colname1 => value1,
			colname2 => value2,
			...
		},
		{
			...
	];

for those that don't. Use ends up looking like

	$tablename->{$keyvalue}{columname}

which is rich in documentation value.

Back to cards....

I've never seen a shuffle like yours before; yours is way sexier than many
I've seen, but I still like mine better; one way of writing mine is

	@shuffled = ();
	push @shuffled, splice @src, rand(@src), 1 while @src;

People who care more about performance can restructure it as an in-place
shuffle in N-1 random swaps, which I think is just about optimal.

But your Schwartian sort-by-random-keys is awfully sexy.

-Bennett

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