pymasep.common.game =================== .. py:module:: pymasep.common.game Classes ------- .. autoapisummary:: pymasep.common.game.Game Module Contents --------------- .. py:class:: Game(cfg = None) Represents the rules of the game. A game contains templates and initializers. :param cfg: DictConfig containing the configuration. See :ref:`config` for more information. .. py:attribute:: ACTION_NO_ACTION :value: 0 No action .. py:attribute:: ACTION_INIT_OBJECT :value: 1000 Action for initializing object from interface .. py:attribute:: ACTION_INTENTION :value: 2000 The agent wants to validate an intention .. py:attribute:: ACTION_VIDEO_ENDED :value: 10000 The interface agent wants to stop a video. See CutSceneInterfaceState .. py:attribute:: MULTIPLAYER_COORDINATION_TURN :value: 1 Turn by turn game .. py:attribute:: MULTIPLAYER_COORDINATION_WAITING_ALL :value: 2 Waiting all action before next state. Not implemented for interface agents at the moment. .. py:attribute:: MULTIPLAYER_COORDINATION_FREE_FOR_ALL :value: 3 Execute action when it arrives. .. py:attribute:: config configuration of the game .. py:attribute:: initializers initializers available in the game .. py:attribute:: templates templates available in the game .. py:attribute:: default_templates default templates for nature of object. Not used at the moment. .. py:attribute:: root_path root path of the game .. py:attribute:: data_path data path of the game .. py:attribute:: is_rewarded :type: Optional[bool] :value: None is the game rewards agents ? .. py:attribute:: nb_episodes :value: 1 number of episodes of the game. Usually one except for learning/simulation games. .. py:attribute:: max_nb_players maximum number of players (human) in the game .. py:attribute:: possible_players list of possible players names .. py:attribute:: coord_method possible coordinates methods according to the game phase (see State.system object, GamePhase) .. py:method:: define_coord_methods() Define the dictionary of coordination methods according to the game phase .. py:method:: add_templates() Add default templates to the game .. py:method:: add_initializers() This method adds definitions of initializers to the game. .. py:method:: init_state(environment) Create the initial state of the game. Can be reimplemented in subclasses. :param environment: The environment. :return: The initial state .. py:method:: initialize_state(environment) Create the initial state of the game. :param environment: The environment. :return: The initial state .. py:method:: set_system_value(state, key, value) :staticmethod: Set a value to a system characteristic. The charac is set to "State.system" object. :param state: The state where the characteristic have to be set. The state is modified :param key: the name of the characteristic :param value: the value of the characteristic :return: the state modified .. py:method:: get_system_value(state, key) :staticmethod: Get the value of a system characteristic. :param state: The state where to read the value. :param key: The name of the characteristic. The name must exist. :return: The value of the characteristic .. py:method:: create_external_agent(env, external_id) Create an agent for an external thread. Initialized as best as can the game do without external inputs :param env: The environment :param external_id: uuid of the external thread/sub_app :return: the agent .. py:method:: next_state(current_state, actions) :abstractmethod: Calculates the new state according to the current state and the action of the agent. Must be reimplemented in subclasses. :param current_state: The current state :param actions: action of the agents :return: the new state and the additional information about the state (may be None). .. py:method:: reward(previous_state, actions, next_state) :abstractmethod: 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. :param previous_state: The previous state before actions. :param actions: Actions of the agents :param next_state: next state usually calculated by next_state() :return: a dictionary of the reward by agent. .. py:method:: is_final(state) Is the state final? :param state: The state. :return: True if final, False if not .. py:method:: observe_state(state, agent_fname) :classmethod: State Observation function. Calculate the al state according to d from state pS :param state: The state of the environment. :param agent_fname: The agent full name that observes the state :return: the observed state. The result is a state (possibly partial and noisy) and not a general observation. .. py:method:: update_belief(agent_fname, observation, state) :classmethod: 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. :param agent_fname: Fullname of the agent this method updates the belief for :param observation: the observation used to update the belief. :param state: The state of the environment used to update the belief. .. py:method:: add_initializer(initializer) Add an initializer into the initializer dictionary of the game :param initializer: The test_initializer to add .. py:method:: add_template(template) Add a template into the initializer dictionary of the game :param template: The template to add .. py:method:: add_default_template(object_nature, template_name) Add a default template into the initializer dictionary of the game :param object_nature: The type of object to associate :param template_name: the template to associate (must exist in game.templates) .. py:method:: order_agents(current_order, new_agent) :staticmethod: 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 :param current_order: The current order of agent :param new_agent: the new agent to add :return: an ordered list of agents' names that can be used by next_state() to set the next agent that can play