Game#
Game is the main class you’ll use to create and run a game.
- class retro.game.Game(agents, state, board_size=(64, 32), debug=False, framerate=24, color='white_on_black')[source]#
Creates a playable game. You will use Game to create games, but don’t need to read or understand how this class works. The main work in creating a
- Parameters:
agents (list) – A list of agents to add to the game.
state (dict) – A dict containing the game’s initial state.
board_size (int, int) – (Optional) The two-dimensional size of the game board. D
debug (bool) – (Optional) Turn on debug mode, showing log messages while playing.
framerate (int) – (Optional) The target number of frames per second at which the game should run.
color (str) – (Optional) The game’s background color scheme. Available colors.
# This example will create a simple game. from retro.game import Game from retro.agent import ArrowKeyAgent agents = [ArrowKeyAgent()] state = {} game = Game(agents, state) game.play()
- add_agent(agent)[source]#
Adds an agent to the game. Whenever you want to add a new agent during the game, you must add it to the game using this method.
- Parameters:
agent – An instance of an agent class.
- get_agent_by_name(name)[source]#
Looks up an agent by name. This is useful when one agent needs to interact with another agent.
- Parameters:
name (str) – The agent’s name. If there is no agent with this name, you will get an error.
- Returns:
An agent.
- get_agents_by_position()[source]#
Returns a dict where each key is a position (e.g. (10, 20)) and each value is a list containing all the agents at that position. This is useful when an agent needs to find out which other agents are on the same space or nearby.
- is_empty(position)[source]#
Checks whether a position is occupied by any agents.
- Parameters:
position (int, int) – The position to check.
- Returns:
A bool
- log(message)[source]#
Write a log message. Log messages are only shown when debug mode is on. They can be very useful for debugging.
- Parameters:
message (str) – The message to log.
- on_board(position)[source]#
Checks whether a position is on the game board.
- Parameters:
position (int, int) – The position to check
- Returns:
A bool