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.5.tar.gz (28.8 kB view details)

Uploaded Source

Built Distribution

nimgame-0.1.5-py3-none-any.whl (34.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: nimgame-0.1.5.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.5.tar.gz
Algorithm Hash digest
SHA256 e7ec3cd73db3f0a77372c11c72543462da9c3fda341e17a7f16973d5000547d8
MD5 4c2e4d24ac976f79bddb10d37c256e5c
BLAKE2b-256 af191c907d165874db18055fcc580495b23daec8dddff66e156ebd66a5912043

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for nimgame-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 6d72afd4d2a37ac116428247a18aeb59794ed23569f2394c018be11a4aa9c1cf
MD5 ff639f3c06a5841ba669839a4230f5de
BLAKE2b-256 523d6d422dee8e7425e2d9755c9b2b973b57f6673cfe39ca95ba95cd85b5623c

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