Make initial build phase tick-able (and replay-able). Replay game functionality. #30
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
For machine learning, we need to be able to iterate over all the states of a game. Saving the state and game object to the database on every tick proved to be too slow (increase avg finish time of a game from ~5 secs to ~1 min). So we instead make the refactors necessary to be able to have a function
replay_game
that given a game, can yield all the states of that game. In particular, we had to make the Initial Building Phase to go through thegame.execute(action)
mechanism like everything else.As such, we created new
ActionType
s that tell the .execute function not to charge for initial roads for example.Similarly, we change the Discard logic to be just another branching spot in the game logic, so that a tree-exploring algorithm can decide with the same API as the rest of the decisions.
Another item necessary to replay games was to seed the game (to ensure e.g. card-stealing happens in the same way).
We refactored the database layer to allow storing game_states as opposed to finalized games, as we first tried to save the state on each tick. This proved to be too slow, but we keep the extra power for now.