tests.testruns¶
Run tests of the Nim Game automatically
play_full_game()
plays one full game automatically, doing the moves for
both parties, according to their set error rates in the Nim
instance
run_many_games()
creates a Nim
instance and runs several games
automatically
- tests.testruns.play_full_game(nim: Nim) dict [source]¶
Play one full game
There is no interaction, both players’ moves are calculated by the program. We just call the 1st player as Computer and the 2nd as Player.
It creates random heaps first. Then, figures out whether Computer is to start. This decision is based on the starting nimsum on Computer’s favour, but with the Computer’s error rate. Player and Computer take turns until the game ends. Moves are calculated with the same algorithm for the Computer and Player, but with different error rates.
- Parameters
nim – the
Nim
instance, created with the init arguments, like error_rate- Returns
The result of the game. Keys in the returned dict:
step_records: a list of statuses at each move
computer_won: a bool stating whether the “Computer” won
- tests.testruns.run_many_games(gamenum: int, error_rate: Union[int, ErrorRate]) None [source]¶
Run several games automatically
This function starts with creating a
Nim
instance with setting the required error rates. It then callsplay_full_game()
for each game. It prints a + when the “Computer” wins, and - when the “Player” wins.Then it prints the percentage the “Computer” won.
- Parameters
gamenum – the number of games to run
error_rate – the required rate of bad decisions to be made by each player