pelita icon indicating copy to clipboard operation
pelita copied to clipboard

New testing API: is there an equvalent to `game_master.play_round()`?

Open fmaussion opened this issue 5 years ago • 1 comments

I am finally moving to the functional API (my "old" classes seem not to work anymore on latest master) and while updating my tests, I'd like to be able to follow a test game step by step.

Is there a way to do that in the new API? I could only find run_background_game, which runs an entire game, and setup_test_game, which allows to test for single situations.

fmaussion avatar Jan 12 '20 22:01 fmaussion

You have a few options. If following a new game with the Tk UI is enough, then you can simply start it with pelita --stop-at 0 and press Enter (or Shift+Enter) to follow it step by step.

If you want to programmatically run it stepwise, you should do it as it is done in game.py

# we create the initial game state
state = setup_game([team_spec_1, team_spec_2], **other_options)

# Play the game until it is gameover.
while not state.get('gameover'):

    # play the next turn
    state = play_turn(state, allow_exceptions=allow_exceptions)

(original code) https://github.com/ASPP/pelita/blob/85559ec3a8539e4720d999dc1ede08bb17a6fa86/pelita/game.py#L181-L199

I have omitted the controller_exit here, as it is only needed when you want to press quit in the UI. You can set allow_exceptions=True, if you want a crash in a player to stop the iteration directly.

A minor disadvantage is that this will give you the internal API in state, which is slightly different from the one that we use in pelita_template and that run_background_game returns.

Debilski avatar Jan 13 '20 10:01 Debilski