pymastermind
Description
A Python package designed to play, develop strategies/algorithms, and implement the classic MasterMind board game. It even includes a functioning, text-based implementation of MasterMind!
Installation
The source code for pymastermind is hosted on GitHub. You can install matermind through PyPI, with pip:
pip install pymastermind
Requirements
pymastermind requires the following libraries:
- pandas, used by the SelfGame object
- tqdm, used to display progress bars when finding next guess. Note: only some algorithms support progress bars. See "Algorithms" below.
Documentation
Read the full documentation for pymastermind here.
Example Usage
Play
Play a game against your computer, or have your computer play itself, by running main() and following text-based instructions.
>>> main() # initiate the game; print instructions & wait for inputs
Classes
Several useful classes are defined in the pymastermind module.
Code
Code objects are list instances designed to store a MasterMind codes. You can compare two codes by using the .compare() method. What's comparing?
>>> secret_code = Code(['a', 'b', 'c', 'd'])
>>> guess = Code(['b', 'c', 'j', 'd'])
>>> len(secret_code) == len(guess)
True
>>> secret_code.compare(guess)
(1, 2)
Note: code objects must be of the same length to comapre.
Game
Game objects are used to immitate gameplay.
>>> my_game = Game() # default: slots == 4, colors == ['a', 'b', 'c', 'd', 'e', 'f']
>>> secret_code = Code(['e', 'a', 'f', 'f'])
>>> my_game.guess # always the same for given setup; see Wikipedia article
['a', 'a', 'b', 'b']
>>> blacks_and_whites = secret_code.compare(my_game.guess)
>>> blacks_and_whites
(1, 0)
>>> my_game.new_guess(response, algorithm='minmax') # new guess using minmax algorithm (see below)
>>> my_game.guess
['a', 'c', 'c', 'd']
>>> my_game.back() # go back one turn
>>> my_game.guess
['a', 'a', 'b', 'b']
Read the documentation for an in-depth look at all the attributes and methods of a Game.
Algorithms
A new guess can be generated using several different algorithms. Currently, pymastermind has two algorithms implemented:
- random (default algorithm)
- Set the guess to a random secret code possibility
- No progress bar support yet
- minmax
- Set the guess to the guess that has the highest min-max score of all guesses. Read more here.
- Supports progress bars
See the full documentation for a more detailed description of the algorithms.
SelfGame
SelfGame is a subclass of Game that is used to "play" games with specified algorithms and obtain a pandas DataFrame full of information about the games played.
>>> my_self_game = SelfGame() # same defaults, so slots == 4, colors == ['a', 'b', 'c', 'd', 'e', 'f']
>>> df = my_self_game.play() # default: games == 10, algorithm == 'random'
>>> type(df)
<class 'pandas.core.frame.DataFrame'>
>>> df.loc['Game 3', 'Turn 2'] # example query
Time 0 days 00:00:00.000610
Start Possibilities 23
End Possibilities 4
Name: Game 3, dtype: object
License
Metadata
Release files for pymastermind 1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pymastermind-1.2.tar.gz | 10.8 kB | Without provenance | Details for pymastermind-1.2.tar.gz |
Release files / pymastermind-1.2.tar.gz
| Download URL | pymastermind-1.2.tar.gz |
|---|---|
| Size | 10.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4055b4b4d8c796138bcefb76883099b5285bc0d1beccf005fba2afa849069197
|
|
BLAKE2b-256 checksum How to use checksums |
ad6f4ac3be7be642e6c19fa3fddf56469afe7e5af149dbabc42672f9260f28d1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.19.1 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.0
|
Security for pymastermind 1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.