Skip to content

Instantly share code, notes, and snippets.

@jmdejong
Created July 4, 2020 15:20
Show Gist options
  • Select an option

  • Save jmdejong/05b31ac3d8c828d1029e28cd1fe9da88 to your computer and use it in GitHub Desktop.

Select an option

Save jmdejong/05b31ac3d8c828d1029e28cd1fe9da88 to your computer and use it in GitHub Desktop.
# mainloop pseudopython
while True:
for character in room.characters:
Queue unhandled_actions
unhandled_actions.push(character.decide_action())
while unhandled_actions not empty:
action = unhandled_actions.pop()
execute(action)
for reaction in get_reactions(action):
unhandled_actions.push(reaction)
for character in room.characters:
character.inbox.push(action)
# decide_action implementations for the player and npcs
function player.decide_action():
for action in player.inbox.actions:
print(action)
return read_action_from_input()
function npc.decide_action():
reactions = []
for action in npc.inbox.actions:
npc.change_internal_state(action)
reactions.push(npc.get_possible_reactions())
reactions.push(npc.get_default_actions())
return npc.pick_best_action(reactions)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment