Skip to main content

“””Play the Game of Nim, interactively or using the API

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 actually TryIt, before installing anything.

Those, who are more of the developer types, can use the API, after installing the package. The game can then be embedded in other applications and played from any other kind of a GUI.

For mathematicians/statisticians, it can also be used for creating statistics by running multiple games. If you know combinatorial game theory terms like sequential game, perfect information, impartial game, Sprague–Grundy theorem, this API can be useful for you.

Game Rules

For the general description of the Nim and similar games, see the Wikipedia page.

The game is played with coins arranged in heaps. There may be any number of heaps and any number of coins in a heap.

Two palyers play the game. The computer can be a player. Players take turns. In each turn, a player takes coins from one (only 1) heap. There is no upper limit of taken coins (but the heap size). At least 1 coin must be taken.

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

API Usage

First, the heaps are to be set up. The starting heaps then can be analysed and the starting player selected. 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)

Release files for nimgame 0.1.15

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for nimgame 0.1.15
File Size Uploaded
nimgame-0.1.15.tar.gz 326.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for nimgame 0.1.15
File Interpreter ABI Platform
nimgame-0.1.15-py3-none-any.whl Python 3 none any Details

Total release size: 366.3 kB

Release files / nimgame-0.1.15.tar.gz

Download URL nimgame-0.1.15.tar.gz
Size 326.7 kB
Tags Source
SHA-256 checksum
How to use checksums
b1633dc390f06116c1dbf424c6f32b62fa204198b45455977e1377c90b1e0d71
BLAKE2b-256 checksum
How to use checksums
ae593276f42927be475d2926bd22b428acecb033cf894a28eb4cdadfb7bdd59a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.22.0

Release files / nimgame-0.1.15-py3-none-any.whl

Download URL nimgame-0.1.15-py3-none-any.whl
Size 39.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e172fa70b8d9788fa0e0bfc98674c04730b15691a4178e4a5fb40055d661ca93
BLAKE2b-256 checksum
How to use checksums
0cfa5b26f3d8c165ccfda50fa5c287981e9873a62782104f48a50cb30505a211
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.22.0

Release history Release notifications | RSS feed

This release

0.1.15 This release

2 release files

0.1.14

2 release files

0.1.13

2 release files

0.1.12

2 release files

0.1.11

2 release files

0.1.10

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page