Skip to content

Commit

Permalink
Improve logging in game master trigger components.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 675110361
Change-Id: I33e78cc2a44965cf0f6e4e4a1989bb61e0a1236c
  • Loading branch information
jzleibo authored and copybara-github committed Sep 16, 2024
1 parent a50a731 commit 55df437
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
22 changes: 17 additions & 5 deletions concordia/components/game_master/triggered_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ def __init__(
memory: MemoryT,
players: PlayersT,
clock_now: Callable[[], datetime.datetime],
pre_event_fn: Callable[[PreEventFnArgsT], None] | None = None,
post_event_fn: Callable[[PostEventFnArgsT], None] | None = None,
pre_event_fn: Callable[[PreEventFnArgsT], str] | None = None,
post_event_fn: Callable[[PostEventFnArgsT], str] | None = None,
name: str = ' \n',
verbose: bool = False,
):
Expand All @@ -84,7 +84,7 @@ def __init__(
players: sequence of players who have an inventory and will observe it.
clock_now: Function to call to get current time.
pre_event_fn: function to call with the action attempt before
computing the event.
computing the event. It returns a string to log.
post_event_fn: function to call with the event statement.
name: the name of this component e.g. Possessions, Account, Property, etc
verbose: whether to print the full update chain of thought or not
Expand All @@ -106,6 +106,8 @@ def __init__(
verbose=self._verbose,
)

self._latest_update_log = None

def name(self) -> str:
"""Returns the name of this component."""
return self._name
Expand All @@ -123,21 +125,31 @@ def update_before_event(self, player_action_attempt: str) -> None:
if player_name not in [player.name for player in self._players]:
return
current_scene_type = self._current_scene.state()
self._pre_event_fn(
pre_event_log = self._pre_event_fn(
PreEventFnArgsT(player_name=player_name,
player_choice=choice,
current_scene_type=current_scene_type,
players=self._players,
memory=self._memory)
)
self._latest_update_log = {
'date': self._clock_now(),
'Summary': self.name(),
'Current scene type': current_scene_type,
'Log': pre_event_log,
}

def update_after_event(self, event_statement: str) -> None:
if self._post_event_fn is None:
return
current_scene_type = self._current_scene.state()
self._post_event_fn(
_ = self._post_event_fn(
PostEventFnArgsT(event_statement=event_statement,
current_scene_type=current_scene_type,
players=self._players,
memory=self._memory)
)

def get_last_log(self):
if self._latest_update_log is not None:
return self._latest_update_log
12 changes: 12 additions & 0 deletions concordia/components/game_master/triggered_inventory_effect.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ def __init__(
verbose=self._verbose,
)

self._latest_update_log = None

def name(self) -> str:
"""Returns the name of this component."""
return self._name
Expand All @@ -128,3 +130,13 @@ def update_before_event(self, player_action_attempt: str) -> None:
memory=self._memory,
player=player)
)
self._latest_update_log = {
'date': self._clock_now(),
'Summary': self.name(),
'Current scene type': current_scene_type,
'current active player': player_name,
}

def get_last_log(self):
if self._latest_update_log is not None:
return self._latest_update_log

0 comments on commit 55df437

Please sign in to comment.