# Recommended textual representation for playing cards?

I am working on creating a that involves using playing cards, but I am not sure what the best way to represent them textually is.

Here are some alternatives I have considered:

Note, the samples show a hand consisting of the Ace of Clubs, Ten of Clubs, Five of Hearts, Five of Spades, and Queen of Spades.

• Represent rank with digits 1-9 and 10, and then J, Q, and K, and suit with S (spades), C (clubs), D (diamonds), and H (hearts):

1C 10C 5H 5S QS

• Use 0 to represent a ten:

1C 0C 5H 5S QS

• Each card is represented by the same number of characters.
• Use numbers to represent all ranks:

1C 10C 5H 5S 12S

• Might be easier to parse, somehow.
• Use ♠. ♣, ♦, and ♥ to represent suit:

1♣ 10♣ 5♥ 5♠ Q♠

• Might be more difficult for languages that have problems with extended charsets.
• Use A instead of 1, for an ace:

A♣ 10♣ 5♥ 5♠ Q♠

• Makes it a little bit prettier.
• Some combination of these alternatives.

• Use a custom character set to encode the cards.

• Much more efficient.
• Can't view it very easily.

I am rather partial to formatting them like A♣ 10♣ 5♥ 5♠ Q♠, but I would like to see what others think about this issue.

• I like bullet #2 Jun 7, 2014 at 2:53
• I'd go for the standard representation Jun 7, 2014 at 4:01
• "T" for ten is not uncommon and it preserves a one-character rank indication which "10" does not. But for some classes of challenges maybe you don't want to make the input that much easier... Jun 7, 2014 at 4:22
• That said, I don't think we need or even should have a standard representation for absolutely everything. The author of each challenge may have a reason for choosing a particular system and who are we to gainsay that? Jun 7, 2014 at 4:25

KISS. Sticking to ASCII makes it simpler: the byte representations will be the same in ISO-8859-1, UTF-8, and MacRoman, so people don't have to worry about ensuring that they're using the correct character encoding. (Of course, they should as a matter of principle, but this site isn't really about best practices).

Of the various ASCII options, the one I'm more familiar with from my bridge-playing days is A23456789TJQK CDHS, but the simplest for inter-program communication is probably to number the cards from 0 to 51.

However, there's nothing which requires you to use the same format for inter-program communication and for presentation to the user. Although I recommend using ASCII for the communication, the scoring program could be made more polished by using A23456789TJQK ♠♡♢♣ in its logs.

Might I suggest Unicode (6+)?

http://en.wikipedia.org/wiki/Playing_cards_in_Unicode

🂡 🂱 🃁 🃑
🂢 🂲 🃂 🃒
🂣 🂳 🃃 🃓
🂤 🂴 🃄 🃔
🂥 🂵 🃅 🃕
🂦 🂶 🃆 🃖
🂧 🂷 🃇 🃗
🂨 🂸 🃈 🃘
🂩 🂹 🃉 🃙
🂪 🂺 🃊 🃚
🂫 🂻 🃋 🃛
🂬 🂼 🃌 🃜
🂭 🂽 🃍 🃝
🂮 🂾 🃎 🃞
🂠 🃏 🃟

edit This is a screenshot from Chromium on Ubuntu 14.04 of what it should look like.

• In a lot of fonts these are either unsupported or really hard to distinguish unless you use a large font size. Jun 7, 2014 at 10:34
• I see boxes because I don't have the appropriate font package Jun 7, 2014 at 11:19
• On what platform are you? Jun 7, 2014 at 15:30
• The text and the image look identical to me (FF on Ubuntu), and I haven't done any fancy font stuff, so these must be supported by default on at least some systems. That said, I don't think these would be the best idea because of lack of support, at least on some platforms. Jun 7, 2014 at 18:30
• Renders OK for me on Ubuntu 14.04, but not on OSX 10.9.3. I'm downvoting this because I don't think its worth going to all this trouble, only to have hearts and diamonds be coloured black. Jun 7, 2014 at 20:14
• I'm using Scientific Linux 6.4. I don't have many Unicode fonts installed because I really don't need them & the extra fonts are really just bloat-ware, IMO. Jun 8, 2014 at 14:45
• Aside: I'm really impressed that Unicode has glyphs for the "Cavalier" cards in bizarre tarot decks. Jun 19, 2014 at 10:01
• Chrome, Windows 7: squares. Seems only Linux supports these glyphs as of now. Jul 1, 2014 at 19:27