[Chris Angelico]

> I use decks of cards primarily for non-game
> usage (for instance, teaching data structures and algorithms - cards
> laid out on a table can represent a tree, heap, array, etc)


I do too. They're a great tool for visualizing and physically trying out
different techniques.

[Chris Angelico]

> A deck containing four suits of thirteen
> cards plus one joker would have 53 cards, which is a prime number;
> printing 54 cards lets you lay them out as 9 by 6 on a sheet, so it's
> easy to add a second joker. Some decks (I have an Alice in Wonderland
> themed deck) have *four* jokers.
> As such, the most logical way to do this would be as an attribute of
> the card.


In most cases I've seen wild cards used, it's a declaration about a certain
card (e.g. "Eights are wild."
or "The 2 of clubs is wild."). I've found that if you're trying to model a
game like poker or Monopoly, it's tempting to add complexity to simple
objects, but it can lead to problems later on. A card doesn't know if it's
wild. That's a function of the game being played. An ace may be high or low.

On Tue, Aug 21, 2018 at 2:06 PM, Chris Angelico <ros...@gmail.com> wrote:

> On Wed, Aug 22, 2018 at 4:56 AM, Abe Dillon <abedil...@gmail.com> wrote:
> > [Chris Angelico]
> >>
> >> In English, "card is not wild" can
> >> be interpreted as a membership check, but in Python, it is only an
> >> identity check; you're capitalizing on false readability by using this
> >> notation.
> >
> >
> > I promise that wasn't my intent. Since both my proposed form and the
> lambda
> > form use the same expression,
> > it doesn't really tip the balance in favor of my argument. Also, most toy
> > card problems I work with use a finite,
> > immutable set of cards, so identity checking isn't *that* weird.
>
> Fair enough. To be fair, I use decks of cards primarily for non-game
> usage (for instance, teaching data structures and algorithms - cards
> laid out on a table can represent a tree, heap, array, etc), and my
> decks of cards are artistic. A deck containing four suits of thirteen
> cards plus one joker would have 53 cards, which is a prime number;
> printing 54 cards lets you lay them out as 9 by 6 on a sheet, so it's
> easy to add a second joker. Some decks (I have an Alice in Wonderland
> themed deck) have *four* jokers.
>
> As such, the most logical way to do this would be as an attribute of
> the card. Its jokerness is as much a feature as the clubness of
> another card. You can pick up a physical card, look at it, and say
> "This is a joker"; you don't have to see if it's in a list of specific
> known jokers.
>
> hand = sorted(cards, by=value[card.suit] if not card.wild else
> max_value with card)
>
> Honestly, though, it'd usually be more interesting to sort by rank
> within suit. What you're doing here would group the cards by suit,
> ignoring their ranks; more useful would be:
>
> hand = sorted(cards, key=lambda card: (card.is_wild, card.suit, card.rank))
>
> Much cleaner. No conditionals needed.
>
> ChrisA
> _______________________________________________
> Python-ideas mailing list
> Python-ideas@python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to