This website gather differents python programs able to find nimbers and P positions in nim games. You can create your own rules and use an unlimited number of heaps (may be longer to process). You can copy-past this code on Jupyter to use it online or you can use it on your own computer.

The differents features on nim games are :
  • Create your own rules
  • Choose a number of heap
  • Find nimbers from a heap of size 0 to size k (you define k)
  • Find losing positions from a heap of size 0 to size k
  • Find a nimber for a given position
  • Display results on a 2D table for games with 2 heaps (see below)
  • Save results in a CSV file
plot grundy wythoffplot losing wythoff
Black points are nimbers equals to 0. For example in those plots we used wythoff's rules.

The differents features on octal game are :
  • Create your own rules using octal code
  • Find the main nimbers
  • Find all the nimbers for every possible position
  • Find a nimber for a given position
  • Search for periodicity
  • Save results in a CSV file

In the differents pages, you will find source codes. The plot feature is only available in the 2-heap games algorithm. In the 3+ heap games page, you can create games with unlimited number of heaps from 1 to "infinity". However, for games with 1 or 2 heaps, the previous programs have better optimisations.
For each nim code, you need to fill a rules function. This function takes the game state and returns the differents allowed moves to play. For each code, you will find an example and an explanation bellow the main code. For the 3+ heap games you also need to fill the variable NBHEAP with the number of heap you are using.

For the Octal game, you can also find the source code. To use it, you don't have to write any rules function. The rules can be written in an octal number. You just have to fill an array. You can even use the console interface to do it.

Python library

  • numpy
  • matplotlib
  • pandas
  • operator
  • time
  • math