Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nimgame-0.1.11.tar.gz (28.8 kB view details)

Uploaded Source

Built Distribution

nimgame-0.1.11-py3-none-any.whl (34.2 kB view details)

Uploaded Python 3

File details

Details for the file nimgame-0.1.11.tar.gz.

File metadata

  • Download URL: nimgame-0.1.11.tar.gz
  • Upload date:
  • Size: 28.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.22.0

File hashes

Hashes for nimgame-0.1.11.tar.gz
Algorithm Hash digest
SHA256 15cfd24220f84889b34ae6b5dd3e08f2d85c939075624d0ff6faf3120a69914c
MD5 86290273dfda2d6afcc083c6a481df8d
BLAKE2b-256 559245cff1ad5bd80548e159b09061cafdda5b458ac33fc6dc1b2ba138dea3b9

See more details on using hashes here.

File details

Details for the file nimgame-0.1.11-py3-none-any.whl.

File metadata

  • Download URL: nimgame-0.1.11-py3-none-any.whl
  • Upload date:
  • Size: 34.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.22.0

File hashes

Hashes for nimgame-0.1.11-py3-none-any.whl
Algorithm Hash digest
SHA256 889b91f232d162c948468b5dae38751c12171050309af32ee78a112ef226ffe2
MD5 0153b9d9e983cd033be8f870dff3b590
BLAKE2b-256 129267d038a8bde31baf6c3095756bf3a3513e65477fc637bb9c8e240f95a70b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page