From bfd11367981417f0128e389e7320483e473f6f19 Mon Sep 17 00:00:00 2001 From: John Agapiou Date: Tue, 10 Sep 2024 06:44:14 -0700 Subject: [PATCH] Delete outdated base class and hide private methods PiperOrigin-RevId: 672943454 Change-Id: I835595810781f909999c349b84952bfd7eea5520 --- concordia/environment/game_master.py | 18 +++--- concordia/typing/game_master.py | 83 ---------------------------- 2 files changed, 7 insertions(+), 94 deletions(-) delete mode 100644 concordia/typing/game_master.py diff --git a/concordia/environment/game_master.py b/concordia/environment/game_master.py index 26c5dc91..8eef34c8 100644 --- a/concordia/environment/game_master.py +++ b/concordia/environment/game_master.py @@ -31,7 +31,6 @@ from concordia.typing import agent as agent_lib from concordia.typing import clock as game_clock from concordia.typing import component -from concordia.typing import game_master as simulacrum_game_master from concordia.utils import concurrency from concordia.utils import helper_functions import termcolor @@ -75,7 +74,7 @@ class LogEntry: summary: str -class GameMaster(simulacrum_game_master.GameMaster): +class GameMaster: """A generic game master.""" def __init__( @@ -196,9 +195,6 @@ def extend_history(self, new_history: Sequence[Mapping[str, Any]]): def get_memory(self) -> associative_memory.AssociativeMemory: return self._memory - def get_data_frame(self): - return self._memory.get_data_frame() - def _print(self, entry, color=None): print(termcolor.colored(entry, color or self._log_color)) @@ -209,7 +205,7 @@ def reset(self): def get_player_names(self): return list(self._players_by_name.keys()) - def update_from_player(self, player_name: str, action_attempt: str): + def _update_from_player(self, player_name: str, action_attempt: str): prompt = interactive_document.InteractiveDocument(self._model) concurrency.map_parallel( @@ -292,7 +288,7 @@ def get_externality(externality): return event_statement - def view_for_player(self, player_name): + def _view_for_player(self, player_name): """Send observations to a player.""" for comp in self._components.values(): state_of_component = comp.partial_state(player_name) @@ -303,7 +299,7 @@ def view_for_player(self, player_name): return - def update_components(self) -> None: + def _update_components(self) -> None: concurrency.run_tasks({ f'{component.name}.update': functools.partial( helper_functions.apply_recursively, @@ -318,8 +314,8 @@ def _step_player( player: deprecated_agent.BasicAgent, action_spec: agent_lib.ActionSpec | None = None, ): - self.update_components() - self.view_for_player(player_name=player.name) + self._update_components() + self._view_for_player(player_name=player.name) if action_spec is None: action_spec_this_time = self._action_spec[player.name] @@ -329,7 +325,7 @@ def _step_player( action = player.act(action_spec_this_time) action_spec_this_time.validate(action) - self.update_from_player(action_attempt=action, player_name=player.name) + self._update_from_player(action_attempt=action, player_name=player.name) def step( self, diff --git a/concordia/typing/game_master.py b/concordia/typing/game_master.py deleted file mode 100644 index 82984830..00000000 --- a/concordia/typing/game_master.py +++ /dev/null @@ -1,83 +0,0 @@ -# Copyright 2023 DeepMind Technologies Limited. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - -"""The abstract class that defines simulacrum game master interface. - -This is an environment side simulacrum. It is responsible for providing the -observations for players and providing the outcomes for actions. It also -manages the simulated world dynamics (if there are any). -Reference: Generative Agents: Interactive Simulacra of Human Behavior -https://arxiv.org/abs/2304.03442 -""" - -import abc -from collections.abc import Sequence - - -class GameMaster(metaclass=abc.ABCMeta): - """A game master class.""" - - @abc.abstractmethod - def name( - self, - ) -> str: - """Returns the name of the game.""" - raise NotImplementedError - - @abc.abstractmethod - def update_from_player( - self, - player_name: str, - action_attempt: str, - ) -> str: - """Returns the outcome of the action attempt. - - Args: - player_name: the name of the player performing the action - action_attempt: a description of an action that the player is trying to - perform. It can succeed or fail. - - Returns: - the outcome of the action_attempt. - """ - raise NotImplementedError - - @abc.abstractmethod - def view_for_player( - self, - player_name: str, - ) -> str: - """Returns the view of the game state for a specific player. - - Args: - player_name: the name of the player to generate a view for - - Returns: - the view of the game state for the player. - """ - raise NotImplementedError - - @abc.abstractmethod - def run_episode(self, max_steps: int) -> Sequence[str]: - """Runs a single episode until the end. - - Args: - max_steps: the maximum number of steps - - Returns: - a list of events that happened - """ - - raise NotImplementedError