Welcome to NimSim’s documentation!

nim.py

Module containing functions necessary for nim game.

@author: hrishit chaudhuri @github: https://www.github.com/hrishitchaudhuri

nim.count_choice(heap, game)

Return user-input to choose number of coins to draw from heap.

Parameters
  • heap (int) – Heap which user chooses to draw coins from.

  • game (nimGame) – Game initialized with user specifications.

Returns

count – Number of coins user chooses to draw from heap.

Return type

int

nim.draw_game(game)

Print current game state.

Parameters

game (nimGame) – Game initialized with user specifications.

Returns

Return type

None.

nim.endMessage(game)

Print message at end of game.

Parameters

game (nimGame) – Game initizalized with user specifications.

Returns

Return type

None.

nim.getPlayer_turn(game)

Obtain and return user play.

Parameters

game (nimGame) – Game initialized with user specifications.

Returns

List containing player turn.

Return type

list

nim.heap_choice(game)

Return user-input to choose heap to play in.

Parameters

game (nimGame) – Game initialized with user specifications.

Returns

heap – Heap which user chooses to draw coins from.

Return type

int

nim.init_menu()

Set up menu for initializing nim game.

Returns

game – Game initialized with user specifications.

Return type

nimGame

nim.input_heaps()

Return user-input for setting number of nim-heaps.

Returns

a – Number of heaps in nim-game set by user.

Return type

int

nim.input_heapsizes(a)

Return user-input for setting size of each nim-heap.

Parameters

a (int) – Number of heaps in nim-game.

Returns

heaps – Array containing height of each nim-heap.

Return type

list

nim.input_start(ipstring)

Return user response to [Y/N] question.

Parameters

ipstring (str) – [Y/N] question to be asked to user.

Returns

player_turn – [Y/N] response given by user.

Return type

str

nim.int_error(func, *args)

Handle ValueErrors in int-returning functions.

Parameters
  • func (function) – Function for which a ValueError has to be handled.

  • *args (tuple) – Arguments to the function.

Returns

Return type

None.

nim.play_turn(game)

Instruct computer or player to play respective turn.

Parameters

game (nimGame) – Game initialized with user specifications.

Returns

Return type

None.

nim.startGame()

Start new nim game.

Returns

Return type

None.

nimClass.py

Module containing class description for nim game.

@author: hrishit chaudhuri @github: https://www.github.com/hrishitchaudhuri

class nimClass.nimGame(heaps, player_turn)

A class to describe a nim game.

bestPlay()

Return best play for computer.

Returns

Computer play in current turn.

Return type

list

isEndgame()

Return game state.

Returns

True if Grundy number of game = 0.

Return type

bool

nimSum()

Return Grundy number of nim game.

Returns

Grundy number of current game state.

Return type

int

Indices and tables