Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/drvinceknight/shut_the_box
Repo with code relevant to the Shut The Box Parlour game
https://github.com/drvinceknight/shut_the_box
Last synced: about 1 month ago
JSON representation
Repo with code relevant to the Shut The Box Parlour game
- Host: GitHub
- URL: https://github.com/drvinceknight/shut_the_box
- Owner: drvinceknight
- Created: 2012-12-30T17:16:41.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2013-01-02T17:02:02.000Z (almost 12 years ago)
- Last Synced: 2024-06-20T00:44:47.483Z (6 months ago)
- Language: Python
- Size: 117 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
#Shut the box
This repo contains files relevant to the parlour game: [Shut the Box](http://en.wikipedia.org/wiki/Shut_the_Box).
The code is written in [Sage](http://sagemath.org/) which is an open source mathematics package based on Python. The code can be used to play shut the box manually or to evaluate playing strategies by passing an autoplay option.
This code is used in this [blog post](http://goo.gl/zViSX) and a demo is given in this [screencast](http://youtu.be/943tIKxV6w8).
#Instructions
##Manual Play
To play the game manually, start Sage, load the library and create an instance of the game:
sage: load("shut_the_box.sage")
sage: game=ShutTheBox()To play the game apply the 'play' method:
sage: game.play()
This will then follow with prompts for the user. A prompt will appear when it is in the users interest to use a single dice (and when this is allowed).
##Autoplay
The game can also be played automatically by passing a string to the play method:
sage: game.play("greedy_play")
There are 4 autoplays currently programmed:
- "random_play": A random set of tiles is picked from the available ones.
- "shortest_play": The set of tiles that uses the least total amount of tailes is picked. For example if [1,7] and [8] are available moves, [8] will be picked.sage: shortest_play([1,7,8],[[1,7],[8]])
8- "longest_play": The set of tiles that uses the most total amount of tailes is picked. For example if [1,7] and [8] are available moves, [1,7] will be picked.
sage: longest_play([1,7,8],[[1,7],[8]])
[1,7]- "greedy_play": The set of tiles that gives the subsequent best chance of being able to play is picked. For example if [1,2,3] are open and 3 is rolled, there are 2 available moves: [1,2] and [3]. Picking [1,2] leaves [3] which can only be played if a 3 is rolled on a 6 sided dice (1/6). Picking [3] leaves [1,2] which can be played if 1,2 or 3 is rolled on a 6 sided dice (1/2). The best choice would be [3].
sage: greedy_play([1,2,3],[[1,2],[3]])
[3]#Experiment
The experiment function collects data comparing all the above autoplays (Ctrl+C quits). This outputs by default to a csv file "Shut_the_Box.csv" but other file names can be passed:
sage: experiment("My_file_name.csv")
The date collected for each autoplay is:
- The final score
- The tile history# License Information #
This work is licensed under a [Creative Commons Attribution-ShareAlike 3.0](http://creativecommons.org/licenses/by-sa/3.0/us/) license. You are free to:
* Share: copy, distribute, and transmit the work,
* Remix: adapt the workUnder the following conditions:
* Attribution: You must attribute the work in the manner specified by the author or licensor (but not in any way that suggests that they endorse you or your use of the work).
* Share Alike: If you alter, transform, or build upon this work, you may distribute the resulting work only under the same or similar license to this one.When attributing this work, please include me.