haidark / ZeroSumEval

4 stars 0 forks source link

Redesign GameState and GameManager #16

Closed haidark closed 2 months ago

haidark commented 2 months ago

The specs for the new design are below (credit to @c-rit for the great work)

Core Components:

environment:

GameState is an immutable data class that defines a game fully. It is responsible for fully defining all states and transitions between states, including proper validation and feedback. At minimum, GameState contains three members:

GameManager Class

The GameManager class is responsible for managing the initialization of the game and players, the flow of game rounds, and the evaluation of player moves. Standard configurations for games are used to initialize the game and player roles, and standard fields in the GameState are used for tracking game progress and validation according to the game's rules. All data and data transformations are provided by the game implementation according to the API.

The following are the key methods:

__init__(self, config):

  - Initializes the GameManager with the provided configuration.   - Sets up the game and players.

**`_init_game(self):

`**   - Builds the game instance using the configuration.   - Adds the game to the list of managed games.

_init_players(self):

  - Builds the player instances using the configuration.   - Associates players with their respective roles in the game.   - Raises an error if a player’s role is not defined in the game.

start(self):

  - Begins the game evaluation process.   - Calls the run_game_loop method to run the game.

run_game_loop(self, game_state):

  - Manages the game loop, processing each turn until the maximum number of rounds is reached or a game-ending condition is met.   - Validates game states, queries the current game state, and processes player turns.

process_turn(self, game_state, player):

  - Executes a player’s turn by facilitating the move, updating the game state, and validating the result.   - Handles retries if a player makes an invalid move and logs errors if a player fails to make a valid move after the maximum number of attempts.

haidark commented 2 months ago

thanks @c-rit for the in-person review. merging this