Game Authoring API
- class chimera.authoring.Player(game, player_name)
Simple class for storing information about a player in a game.
Should not be instantiated directly, but there are several Game methods that will return instances of this class.
- Parameters:
game (Game) –
player_name (str) –
- class chimera.authoring.Game(game_options)
Base class for Chimera games. Adding a game to Chimera involves subclassing this class, and implementing all its abstract methods. Also provides a number of convenience methods that can help with implementing a game.
Each time a new match of a game is created, an instance of a Game class will be created and associated with that specific match. The purpose of the Game class is to specify the logic of the game.
A Game will have one more players, represented by Player objects. These Player objects are created and added to the game by the backend (based on the players that join a match). Each player has an integer identifier, numbered from 0 (e.g., in a four-player game, the players’ identifiers would be 0, 1, 2, 3). Currently, these identifiers are set in the order in which players join a match.
- Parameters:
game_options (dict) –
- abstract property done: bool
Returns True if the game is over, False otherwise.
- abstract property game_state: dict
Returns the game’s state
- get_player_by_id(player_id)
Gets the Player object whose identifier is player_id
- Parameters:
player_id (int) – Player identifier
- Raises:
ValueError – if the identifier is incorrect
- Return type:
Returns: Player object with the given identifier
- abstract property max_players: int
Returns the maximum number of players in the game
The backend will not allow more than these many players to join a match.
- abstract property min_players: int
Returns the minimum number of players in the game
A game cannot start until at least these many players have joined a match.
- notify_update()
If called, notifies the backend that the game’s state has changed, and that a notification should be sent to the players.
Returns: None
- Return type:
None
- property num_players: int
Returns the number of players in the game
- abstract on_end()
This method can be used to write code that must run right once the game over (e.g., to perform any clean-up tasks, freeing up resources, etc.)
Returns: None
- Return type:
None
- abstract on_start()
This method can be used to specify code that must run right before the game starts. Unlike the constructor, when this method is called by Chimera, all the players have already been added to the game.
Returns: None
- Return type:
None
- class chimera.authoring.TwoPlayerGame(game_options)
Convenience class for two-player games
Only implements the min_players and max_players methods, to require exactly two players. Leaves all other abstract methods from Game unimplemented.
- class chimera.authoring.TurnBasedGame(game_options)
Bases:
Game,ABCClass for implementing turn-based games.
In this type of game, the players take turns making moves (at the moment, we only support starting with the first player, and round-robin-ing between all the players). Once all players have taken a turn, they have completed a round.
This class includes convenience methods related to querying and enforcing these turns.
- Parameters:
game_options (dict) –
- property current_player: Player
Returns the current player (i.e., the player whose turn it currently is)
- abstract property done: bool
Returns True if the game is over, False otherwise.
- abstract property game_state: dict
Returns the game’s state
- get_player_by_id(player_id)
Gets the Player object whose identifier is player_id
- Parameters:
player_id (int) – Player identifier
- Raises:
ValueError – if the identifier is incorrect
- Return type:
Returns: Player object with the given identifier
- property is_end_of_round: bool
Returns True if the current player is the last player in the current round, False otherwise
- abstract property max_players: int
Returns the maximum number of players in the game
The backend will not allow more than these many players to join a match.
- abstract property min_players: int
Returns the minimum number of players in the game
A game cannot start until at least these many players have joined a match.
- notify_update()
If called, notifies the backend that the game’s state has changed, and that a notification should be sent to the players.
Returns: None
- Return type:
None
- property num_players: int
Returns the number of players in the game
- abstract on_end()
This method can be used to write code that must run right once the game over (e.g., to perform any clean-up tasks, freeing up resources, etc.)
Returns: None
- Return type:
None
- abstract on_start()
This method can be used to specify code that must run right before the game starts. Unlike the constructor, when this method is called by Chimera, all the players have already been added to the game.
Returns: None
- Return type:
None
- turn_to_next_player()
Advances the turn to the next player
Returns: None
- Return type:
None
- class chimera.authoring.TwoPlayerTurnBasedGame(game_options)
Convenience class for turn-based two-player games
Only implements the min_players and max_players methods, to require exactly two players. Leaves all other abstract methods from TurnBasedGame unimplemented.