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

Uploaded Source

Built Distribution

nimgame-0.1.3-py3-none-any.whl (32.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for nimgame-0.1.3.tar.gz
Algorithm Hash digest
SHA256 d0acd2dde0a561250ad2ca9085721f12590f65d02404c97ee1fa332b78f51f7d
MD5 98477ff26c5e0acb577fd9c400717ed5
BLAKE2b-256 e82253cdd0633b71aab38bb4ce59a24991d1c35ce56a9303b736dbb4886856fe

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for nimgame-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 81c4593098d69d3e7d45b06cd5ac731199e84783e9beaf9e5fa3bd888a5c9cec
MD5 48a00a8d54725aaedd1c953b80a2e7b5
BLAKE2b-256 8991def32e773007c8320ba84c27eda81a36898d237b037a4c1536d8840257d1

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