In 2010, we visited with my wife’s family for Thanksgiving. While we were winding down for the night, she and her cousins pulled out a game called Set. So we started playing…and I got absolutely crushed.
The rules were pretty simple. A valid “set” is defined as any three cards where all of the four card attributes (color, count, shape, fill) are either the same or different. That is, if you have three cards with two shapes on them, the “count” checks off because it’s the same. If one card is squares, another triangles, and the last circles, then the “shape” attribute checks off because they are all different. However, if one is blue and the other two are red, the set is invalid.
Cross-eyed yet? Here’s the archive of my old blog entry which has a visual aid (from when I was…well…less lazy. Thanks archive.org!).
It was a bit unreal how quickly they were matching these things up. I swear I was playing against friggin’ machines. On the other hand, I’m sure they felt that I had the skillz of a three year old. I had to get better.
If I were a less lazy (or cheap) man, I’d have gone and purchased the game. But instead, I opted, to just make it myself. Also, a digital version would allow faster turn over, allowing more practice in less time (queue Eye of the Tiger).
Looking at this, the first things that stands out to me is the atrocious formatting. I weirdly mixed tabs and spaces (I think I’ll blame that one on the brown acid). It reminds me of how helpful modern tools like editorconfig and eslint (and jslint before it) are.
Additionally, I had a visceral reaction to the
setExists functions. Four nested loops. Generally, this is a no-no. However, this is a good example of practicality over rules from the ivory tower. The
createDeck function only happens once while the
setExists function is only called when the user clicks a button - miles away from being complex logic in a tight loop.
In other words, don’t worry about performance until you’ve made it works and it is proven to be a problem.
Lastly, I’m noticing that I opted for native getters and setters. This was clearly my way of shaking my fist at Microsoft. Yeah…I was knee-deep in IE6 pains at the time. Take that, MS!
See more on GitLab.