Package: skyzyx-set-game-demo
“Set” is a card game where a group of players try to identify aSetof
cards from those placed face-up on a table.This project usesSemantic Versioningfor
managing backwards-compatibility.API ReferenceThe GameCore ConceptsEachCardhas 4Properties: color, shape, shading, and number.TheDeckis a collection of all of theCards.TheBoardis a subset of theDeck, containing only the cards that
are currently in-play.ASetis a collection of 3 cards which meet certain criteria
(discussed below). When aSetis found in-play on theBoard, theSetis removed from play and logged as such.TheGameencapsulates all of these concepts and keeps track of
them.Game RulesEachCardhas an image on it with 4 orthogonal attributes:Color (red, green, or purple)Shape (diamond, squiggle, or oval)Shading (solid, empty, or striped)Number (one, two, or three)ThreeCardsare a part of aSetif, for eachProperty, the values
are all the same or all different.For example:TheCards“two red solid squiggles”, “one green solid diamond”,
“three purple solid ovals” would make up aSet. (number, shape, and
color are different, shading is the same)TheCards“two red solid squiggles”, “one green solid squiggles”,
“three purple solid ovals” would not make up aSet, because shape
is the same on twoCards, but different on the third.AGameof “Set” starts by dealing 12Cards, face-up. When a
player sees threeCardsthat make up aSet, they yell “Set!” and
grab theCards. NewCardsare dealt from theDeckto replace
them.If no player can find aSet, three moreCardsare dealt (to make
15, then 18, then 21…)TheGameis over when there are noCardsleft in theDeck, and
noSetsleft on the table. The player with the mostSetswins.Game RequirementsYour task is to model theGamein code, and implement the following
methods:A method that takes threeCards, and determines whether the threeCardsmake aSet.A method that given aBoardofCards, will either find aSet,
or determine that there are noSetson the table.A method that will play an entireGameof “Set”, from beginning to
end, and return a list of each validSetsyou removed from theBoard.For this last method, there will be multiple correct solutions, but any
valid list ofSetsis fine.Assumptions“Three cards are a part of a set if, for each property, the values
are all the same or all different.”This is phrased ambiguously, and the examples given lead me to believe
that the following is a more specific description of the rules.Take 3 cards and look at each of their properties one-by-one.If all cards have a different value for that property OR all cards
have the same value for that property, then itmaybe a set.Ifanyproperties of step 2 fail the test, then the group is not a
set.Problem ParametersThis problem uses mathematicalcombinations(as opposed topermutations). This results in 81 combinations (3^4).Any failure of being aSetmeans that the group is not a set, so
fail as early as possible and move-on.Logic(Whereas “Combination” refers to themathematical
concept.)Create the deck of available cards by ensuring that every card is
unique, and that allCombinationsof properties are represented.
Also, shuffle the deck by default.Deal 12 cards to theBoard.Calculate all possibleCombinationsof the cards on theBoard, in
groups of 3.Iterate over eachCombination, applying logic to determine whether
or not thisCombinationrepresents aSet.Collect theSetsby removing theCardswhich are determined to be
part of aSet.When no moreSetscan be found, deal another 3Cardsfrom theDeck.Repeat steps 3–6 until theDeckis empty.RequirementsPython 2.7, 3.3+, PypyPipVirtualEnv is recommended, but not requiredInstallation# Install from Pypipipinstallskyzyx-set-game-demo# Install from local codepipinstall-e.And either include it in your scripts:fromset_game_demoimportSetGame…or run it from the command line.# Application helpset-game-demo-hUsage/ExamplesFrom the Python REPL or a Python script…from__future__importprint_functionfromset_game_demoimportSetGame# Initialize the game.game=SetGame()# Chatty, interactive version of the game.game.play()# Quiet version of the game. Good for code.discovered,sets=game.play_quiet()print("Sets discovered:{}".format(discovered))forsetinsets:game.display_cards(set)From the Terminal…# Chatty, interactive version of the game.set-game-demo# Quiet version of the game.set-game-demo--quietKnown IssuesIn a final release, it would be wise to update therequirements.txtto allow for ranges of known-good versions
instead of locking to one specific version.Conversely, if this is the sole project running in this virtual
environment, locking to a specific known-good version ensures
fewer version-compatibility issues.Future ImprovementsUpdate thetest_dealunit test to verify that we do not attempt
to deal a larger number of cards than the deck contains (couldn’t
quite figure out the right way to callassertRaises()from theunittestpackage through thenose2interface).Support multiplePlayerswho can collect sets and compete for
scores.DevelopmentYou can develop in any supported version of Python.Usingpyenvto manage your
Pythons ishighly-recommended. Testing locallydependson it.InstallVirtualEnvfor
your development environment, andactivatethe environment.pipinstallvirtualenvvirtualenv.vendorsource.vendor/bin/activateInstall therequirements.txt.pipinstall-rrequirements.txtWhen you make changes, make sure that you run the linter and fix
anything that’s broken.makelintTestingWe usetoxto handle local testing
across multiple versions of Python. We install multiple versions of
Python at a time withpyenv.Testing occurs against the following versions:Python 2.7Python 3.3Python 3.4Python 3.5Python 3.6Python 3.7PypyPypy3To begin…Installpyenvon your own before
running tests.You need to install all of the supported versions of Python. (This
will take a while.) If you would prefer to install your own copies of
the supported Python versions (listed above), feel free to manage
them yourself.pyenvinstall3.7.1&&\pyenvinstall3.6.7&&\pyenvinstall3.5.6&&\pyenvinstall3.4.9&&\pyenvinstall3.3.7&&\pyenvinstall2.7.15&&\pyenvinstallpypy-5.7.1&&\pyenvinstallpypy3.5-6.0.0&&\pyenvrehash&&\eval"$(pyenvinit-)"&&\pyenvglobalsystem2.7.153.3.73.4.93.5.63.6.73.7.1pypy-5.7.1pypy3.5-6.0.0To verify that the installation and configuration were successful,
you can runpyenv versions. You should see a*character in
front of every version that we just installed.$pyenvversions*system(setby~/.pyenv/version)*2.7.12(setby~/.pyenv/version)*3.3.6(setby~/.pyenv/version)*3.4.5(setby~/.pyenv/version)*3.5.2(setby~/.pyenv/version)*3.6.0b1(setby~/.pyenv/version)*pypy-5.3.1(setby~/.pyenv/version)*pypy3-2.4.0(setby~/.pyenv/version)The following command will package-up your module and install it
locally, then runnose2to execute the tests in thedefault
system Python.maketestAfter you’ve run that, you can then execute the tests in all
supported versions of Python with the following:toxAPI ReferenceBuilding local docsmakedocsopendocs/set_game_demo/index.htmlBuilding and pushing docsmakepushdocsDocs can be viewed athttps://skyzyx.github.io/set-game-demo/.DeployingTheMakefile(yes,Makefile) has a series of commands to
simplify the development and deployment process.Also installChag. This is
used for managing theCHANGELOGand annotating the Git release
correctly.Updating the CHANGELOGMake sure that theCHANGELOG.mdis human-friendly. Seehttp://keepachangelog.comif you don’t
know how.makeRunningmakeby itself will show you a list of available
sub-commands.$makeallbuildpipcleandocslintpushdocspushpipreadmetagtestversionmake readmeIf you make changes toREADME.md, then this will usePandocto output aREADME.rstfile in thereStructuredTextformat
used bydistutils,Sphinxand most of the Python community.You must havePandocinstalled on your local
system.NOTE:Initial install viabrew install pandoctakes about
8–10 hours. Updates are much faster.Using the
installerismuchfaster for initial installation, but updates are entirely manual.make versionSets the version number that will be used by othermaketasks
related to packaging and bundling.make tagThis will make sure that theCHANGELOG.mdis properly datestamped,
add the CHANGELOG contents to the Git commit message, commit them, then
create a Git commit which can be pushed upstream.make buildpipThis will bundle-up your package in preparation for uploading toPypi.make pushpipThis will take your bundled package and upload it securely toPypiusing thetwinepackage.Drafting a GitHub releaseGo tohttps://github.com/skyzyx/set-game-demo/tagsFind the new tag that you just pushed. Click the ellipsis (…) to
see the commit notes. Copy these.To the right, chooseAdd release notes. YourTag versionshould
be pre-filled.TheRelease titleshould match yourTag version.InsideDescribe this release, paste the notes that you copied on
the previous page.ChoosePublish release.Your release should now be the latest.https://github.com/skyzyx/set-game-demo/releases/latestContributingHere’s the process for contributing:Fork this project to your GitHub account.Clone your GitHub copy of the repository into your local workspace.Write code, fix bugs, and add tests with 100% code coverage.Commit your changes to your local workspace and push them up to your
GitHub copy.You submit a GitHub pull request with a description of what the
change is.The contribution is reviewed. Maybe there will be some banter
back-and-forth in the comments.If all goes well, your pull request will be accepted and your changes
are merged in.Authors, Copyright & LicensingCopyright (c) 2016Ryan ParmanSee also the list ofcontributorswho participated in this project.Licensed for use under the terms of theApache
2.0license.