Play the Game of Nim, interactively or using the API
Project description
About
This package implements the game called Nim. The game can be played interactively in the CLI or in a web browser. You can install this package and play the game. Easy:
> pip install nimgame > nimgame
You can also try the game before installing the package, see the “TryIt” link on the left (when it will work :-))
Those, who are more of the developer kinds, can use the API, after installing the package. The game then can be embedded in other applications and played from any other GUI.
Game Rules
For the general description of the Nim and similar games, see the Wikipedia page.
This game is played by 2 palyers (the computer can be a player). There are coins arranged in heaps. There may be any number of heaps and any number of coins in a heap.
Players take turns. In each turn, a player takes coins from a heap (only 1 heap). It must be at least 1 coin. There is no upper limit (but the heap size).
There are 2 types of the game:
the “normal” game is where the player, who takes the last coin, wins
the “misère” game is where the player, who has to take the last coin, loses
Usage
After instantiating the Nim class, you need to get the heaps set up. The starting heaps then can be analysed and the starting player set. If it is the Computer, it automatically does the 1st move. Then the Player is to do the next move, then the Computer moves, and so on. When no more coins left, the game ends.
import nimgame
nim = nimgame.Nim(error_rate=10) # Make the Computer do 10% errors
nim.setup_heaps() # Create heaps randomly
nim.set_start(myturn=True) # Indicate that the Player wants to start
nim.do_move(nim.Move('b', 4)) # From heap 'B', remove 4 coins
...
if nim.game_end():
exit(0)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file nimgame-0.1.7.tar.gz
.
File metadata
- Download URL: nimgame-0.1.7.tar.gz
- Upload date:
- Size: 28.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.22.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b46ad4e489bea7ee392e664470dd95a794fd0e3ba158a69b44754fa3607292ab |
|
MD5 | f10ffb2bf295e496715ad228fbdfd58f |
|
BLAKE2b-256 | f2d2274ee9490ce5eae33c60358e69bc1a93720f889b16334ba897bb8e6f3e9e |
File details
Details for the file nimgame-0.1.7-py3-none-any.whl
.
File metadata
- Download URL: nimgame-0.1.7-py3-none-any.whl
- Upload date:
- Size: 34.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.22.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f96dca26c0e04fab8fe0a39b8d78e91bc919ef156943edaaa96991e0ddfd2f19 |
|
MD5 | 87e15a42114d8e583212c4afe49fe4e2 |
|
BLAKE2b-256 | a8e6777507c6475049107b9d8f9b57d17661a7ba7d3e91a70020d673e6489f1e |