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

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: nimgame-0.1.4.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.4.tar.gz
Algorithm Hash digest
SHA256 5e4f77d4f1225e2e49668104bfa499268216815826143e58beed4c6cc84131fe
MD5 4a72c7e4bebc253b9c9f2eab89bed5fb
BLAKE2b-256 7cd75ab67e34508991c7cd97c6482602a86b40bdf0fcedca54a70c83c27e5b4b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: nimgame-0.1.4-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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 639061e6dfaaf452fd5e9fe5e11d52ba30a808aa15f424dd9d6776707de28b4a
MD5 33c85e33eca540e99c4cfa18a6dc9a31
BLAKE2b-256 c20d2a9610fdfccf068652ba78f736ad46309978a282a7d488fb97db99fc1280

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