I am not sure how to find out what all is included as curated data. For example, are the individual images of each of the 52 cards in a standard deck of playing cards included?
If not, is there a way to systematically access these from web images?
Answer
You can get some nice vector playing cards from this site, licensed under GNU LGPL (read more here). Download this folder to your computer and then try the following:
(* replace with your download dir *)
files = Flatten@With[{dir = "~/Downloads/Chrome/mma/SVG_and_EPS_Vector_Playing_Cards_Version_1.3/EPS_Vector_Playing_Cards_Version_1.3/52-Individual-Vector-Playing-Cards-1.2_(EPS-Format)/"},
FileNames["*.eps", dir, 2]];
Clear@CardData
SetAttributes[CardData, Listable]
StringCases[Last@FileNameSplit@#, card__ ~~ ".eps" :>
(CardData[card] = ImageCrop@Import@#)] & /@ files;
You can then use this like any other curated data:
GraphicsRow[CardData@{"2C", "KH", "AS", "QD", "JC"}]

Random hand generator:
You can extend this further and also create a random hand generator using Mathematica as follows:
deck = Flatten@With[
{
ranks = CharacterRange["2", "9"] ~Join~ {"10", "J", "Q", "K", "A"},
suits = {"C", "S", "H", "D"}
},
Outer[StringJoin, ranks, suits]
];
dealHand[n_Integer] /; 1 ≤ n ≤ 52 := CardData@RandomSample[deck, n]
Use this to deal a hand as dealHand[5], for instance. You'll have to modify this a bit to deal randomly and exhaust the deck at the same time (as you would in a game). There was a question on this previously on this site and I gave an answer based on Internal`Bag[] that will be useful here (along with some of the other answers there).
Comments
Post a Comment