A program to play “Set”
Justin Pearson
Sep 21, 2017
We use Mathematica’s image-processing functions and a little machine learning to play the pattern-matching card game “Set”.
For more information see:
http://justinppearson.com/presentations.html#a-program-to-play-the-set-card-game
https://www.setgame.com/sites/default/files/instructions/SET%20Mini%20Round%20Instructions.pdf
Enable / disable webcam usage (in case no webcam)
Camera calibration (do this manually)
Adjust the lighting to make the CurrentImage[] match these pictures:
Basic definitions
Main algorithm
Examples
No args: find sets in an example image:
2nd arg: “debug” (show cards as you parse them):
3rd arg: “quit after finding 1st set”:
Color classifier
Simple “nearest neighbor” algorithm: blob is closest to which color?
Shape classifier
We use Multinomial Logistic Regression using 4 shape properties, then train with Maximum-Likelihood Estimation of the decision boundaries.
Gather & Prep Training Data / Test Data
“Training” frames:
“Testing” frames:
Gather feature vectors
Plot training and test sets
Train classifier
Examples
shape | x=rectangularity etc | A*x | classified shape |
{1,0.705561,0.525649,0.961538,0.88058} | {-4.74043,19.5778,0.} | oval | |
{1,0.51032,0.3631,0.904762,0.817582} | {27.8106,0.31323,0.} | diamond | |
{1,0.620569,0.455728,0.870229,0.791842} | {-22.7232,-17.347,0.} | squiggly |
Validation:
image | shape stats | true | predicted |
{0.705561,0.525649,0.961538,0.88058} | oval | oval | |
{0.714978,0.539667,0.966527,0.888673} | oval | oval | |
{0.711933,0.544339,0.96281,0.883971} | oval | oval | |
{0.601687,0.413548,0.828571,0.79291} | squiggly | squiggly | |
{0.515522,0.373147,0.961039,0.813598} | diamond | diamond | |
{0.561538,0.417737,0.960526,0.860124} | diamond | diamond | |
{0.631277,0.429324,0.781609,0.780505} | squiggly | squiggly | |
{0.702756,0.54322,0.961977,0.888574} | oval | oval | |
{0.708888,0.55952,0.958491,0.890328} | oval | oval | |
{0.51032,0.3631,0.904762,0.817582} | diamond | diamond | |
{0.508121,0.3631,0.888889,0.808189} | diamond | diamond | |
{0.70309,0.551348,0.963265,0.889643} | oval | oval | |
{0.718647,0.575406,0.967078,0.899936} | oval | oval | |
{0.724509,0.565612,0.970588,0.900984} | oval | oval | |
{0.603027,0.415597,0.8,0.771144} | squiggly | squiggly | |
{0.536667,0.345686,0.947059,0.834969} | diamond | diamond | |
{0.552083,0.369425,0.946429,0.848786} | diamond | diamond | |
{0.781065,0.567796,0.977778,0.91468} | oval | oval | |
{0.784024,0.569947,0.974265,0.916411} | oval | oval | |
{0.807692,0.57836,0.992727,0.930141} | oval | oval | |
{0.620569,0.455728,0.870229,0.791842} | squiggly | squiggly | |
{0.613078,0.433972,0.869732,0.776643} | squiggly | squiggly | |
{0.501897,0.359726,0.932515,0.79651} | diamond | diamond | |
{0.525362,0.365584,0.947712,0.846014} | diamond | diamond | |
{0.517361,0.335775,0.943038,0.824905} | diamond | diamond | |
{0.581068,0.401325,0.8107,0.771076} | squiggly | squiggly | |
{0.549407,0.339043,1.,0.832328} | diamond | diamond | |
{0.570248,0.365295,1.,0.853363} | diamond | diamond | |
{0.570248,0.365295,1.,0.849756} | diamond | diamond | |
{0.592828,0.425771,0.803846,0.784146} | squiggly | squiggly | |
{0.541958,0.378795,0.922619,0.841921} | diamond | diamond | |
{0.60962,0.438328,0.820313,0.776181} | squiggly | squiggly | |
{0.612613,0.442503,0.788104,0.773027} | squiggly | squiggly | |
{0.707744,0.539281,0.945098,0.891947} | oval | oval | |
{0.70187,0.534805,0.944664,0.888238} | oval | oval | |
{0.704807,0.543732,0.944882,0.890094} | oval | oval | |
{0.736264,0.567767,0.950355,0.918046} | oval | oval | |
{0.733516,0.555482,0.943463,0.907918} | oval | oval | |
{0.741823,0.572004,0.9375,0.904698} | oval | oval | |
{0.555556,0.371749,0.987654,0.851451} | diamond | diamond | |
{0.713693,0.540691,0.958763,0.882272} | oval | oval | |
{0.708978,0.527836,0.962069,0.885473} | oval | oval |
Play Set