pymasep.common.game

Classes

Game

Represents the rules of the game.

Module Contents

class pymasep.common.game.Game(cfg=None)

Represents the rules of the game. A game contains templates and initializers.

Parameters:

cfg (omegaconf.DictConfig) – DictConfig containing the configuration. See Configuration for more information.

ACTION_NO_ACTION = 0

No action

ACTION_INIT_OBJECT = 1000

Action for initializing object from interface

ACTION_INTENTION = 2000

The agent wants to validate an intention

ACTION_VIDEO_ENDED = 10000

The interface agent wants to stop a video. See CutSceneInterfaceState

MULTIPLAYER_COORDINATION_TURN = 1

Turn by turn game

MULTIPLAYER_COORDINATION_WAITING_ALL = 2

Waiting all action before next state. Not implemented for interface agents at the moment.

MULTIPLAYER_COORDINATION_FREE_FOR_ALL = 3

Execute action when it arrives.

config

configuration of the game

initializers

initializers available in the game

templates

templates available in the game

default_templates

default templates for nature of object. Not used at the moment.

root_path

root path of the game

data_path

data path of the game

is_rewarded: bool | None = None

is the game rewards agents ?

nb_episodes = 1

number of episodes of the game. Usually one except for learning/simulation games.

max_nb_players

maximum number of players (human) in the game

possible_players

list of possible players names

coord_method

possible coordinates methods according to the game phase (see State.system object, GamePhase)

define_coord_methods()

Define the dictionary of coordination methods according to the game phase

add_templates()

Add default templates to the game

Return type:

None

add_initializers()

This method adds definitions of initializers to the game.

init_state(environment)

Create the initial state of the game. Can be reimplemented in subclasses.

Parameters:

environment – The environment.

Returns:

The initial state

Return type:

pymasep.common.state.State

initialize_state(environment)

Create the initial state of the game.

Parameters:

environment – The environment.

Returns:

The initial state

Return type:

pymasep.common.state.State

static set_system_value(state, key, value)

Set a value to a system characteristic. The charac is set to “State.system” object.

Parameters:
  • state (pymasep.common.state.State) – The state where the characteristic have to be set. The state is modified

  • key (str) – the name of the characteristic

  • value (Any) – the value of the characteristic

Returns:

the state modified

Return type:

pymasep.common.state.State

static get_system_value(state, key)

Get the value of a system characteristic.

Parameters:
  • state (pymasep.common.state.State) – The state where to read the value.

  • key (str) – The name of the characteristic. The name must exist.

Returns:

The value of the characteristic

Return type:

Any

create_external_agent(env, external_id)

Create an agent for an external thread. Initialized as best as can the game do without external inputs

Parameters:
  • env – The environment

  • external_id (str) – uuid of the external thread/sub_app

Returns:

the agent

Return type:

pymasep.common.agent.Agent

abstract next_state(current_state, actions)

Calculates the new state according to the current state and the action of the agent. Must be reimplemented in subclasses.

Parameters:
Returns:

the new state and the additional information about the state (may be None).

Return type:

Tuple[pymasep.common.state.State, Dict]

abstract reward(previous_state, actions, next_state)

Return the reward for all agents depending on the previous_state, actions and the next state. This is the general form, but each game can implement it as they want.

Parameters:
Returns:

a dictionary of the reward by agent.

Return type:

Dict

is_final(state)

Is the state final?

Parameters:

state (pymasep.common.state.State) – The state.

Returns:

True if final, False if not

Return type:

bool

classmethod observe_state(state, agent_fname)

State Observation function. Calculate the al state according to d from state pS

Parameters:
  • state (pymasep.common.state.State) – The state of the environment.

  • agent_fname (str) – The agent full name that observes the state

Returns:

the observed state. The result is a state (possibly partial and noisy) and not a general observation.

Return type:

pymasep.common.state.State

classmethod update_belief(agent_fname, observation, state)

The belief of the agent is updated according to the observation and the state and is updated in the state and the observation. Normally, the copy made a reference to the belief so the belief is shared between state and observation for the agent agent_fname.

Parameters:
  • agent_fname (str) – Fullname of the agent this method updates the belief for

  • observation (pymasep.common.state.State) – the observation used to update the belief.

  • state (pymasep.common.state.State) – The state of the environment used to update the belief.

Return type:

None

add_initializer(initializer)

Add an initializer into the initializer dictionary of the game

Parameters:

initializer (pymasep.common.initializer.Initializer) – The test_initializer to add

Return type:

None

add_template(template)

Add a template into the initializer dictionary of the game

Parameters:

template (pymasep.common.template.Template) – The template to add

Return type:

None

add_default_template(object_nature, template_name)

Add a default template into the initializer dictionary of the game

Parameters:
  • object_nature (str) – The type of object to associate

  • template_name (str) – the template to associate (must exist in game.templates)

Return type:

None

static order_agents(current_order, new_agent)

Implement rules to determine the order of playing agent. Usefull only for MULTIPLAYER_COORDINATION_TURN. At the moment, first in, first out order is implemented

Parameters:
  • current_order (List[str]) – The current order of agent

  • new_agent – the new agent to add

Returns:

an ordered list of agents’ names that can be used by next_state() to set the next agent that can play

Return type:

List[str]