1
0
Fork 0

adjust transition probabilities for sim systems

This commit is contained in:
Sean Sube 2024-05-07 20:42:32 -05:00
parent d72c1326f1
commit c1fc16ef81
Signed by: ssube
GPG Key ID: 3EED7B957D362AF1
9 changed files with 93 additions and 77 deletions

View File

@ -5,6 +5,7 @@ from .sleeping_actions import action_sleep
from adventure.logic import init_from_file from adventure.logic import init_from_file
LOGIC_FILES = [ LOGIC_FILES = [
"./adventure/sim_systems/environment_logic.yaml",
"./adventure/sim_systems/hunger_logic.yaml", "./adventure/sim_systems/hunger_logic.yaml",
"./adventure/sim_systems/hygiene_logic.yaml", "./adventure/sim_systems/hygiene_logic.yaml",
"./adventure/sim_systems/mood_logic.yaml", "./adventure/sim_systems/mood_logic.yaml",

View File

@ -1,57 +1,64 @@
from adventure.context import get_dungeon_master, get_agent_for_actor, get_current_context, broadcast from adventure.context import (
broadcast,
get_agent_for_actor,
get_current_context,
get_dungeon_master,
)
def action_attack(target: str) -> str: def action_attack(target: str) -> str:
""" """
Attack a character or item in the room. Attack a character or item in the room.
Args: Args:
target: The name of the character or item to attack. target: The name of the character or item to attack.
""" """
_, action_room, action_actor = get_current_context() _, action_room, action_actor = get_current_context()
# make sure the target is in the room # make sure the target is in the room
target_actor = next((actor for actor in action_room.actors if actor.name == target), None) target_actor = next(
target_item = next((item for item in action_room.items if item.name == target), None) (actor for actor in action_room.actors if actor.name == target), None
)
target_item = next(
(item for item in action_room.items if item.name == target), None
)
dungeon_master = get_dungeon_master() dungeon_master = get_dungeon_master()
if target_actor: if target_actor:
target_agent = get_agent_for_actor(target_actor) target_agent = get_agent_for_actor(target_actor)
if not target_agent: if not target_agent:
raise ValueError(f"no agent found for actor {target_actor.name}") raise ValueError(f"no agent found for actor {target_actor.name}")
reaction = target_agent( reaction = target_agent(
f"{action_actor.name} is attacking you in the {action_room.name}. How do you react?" f"{action_actor.name} is attacking you in the {action_room.name}. How do you react?"
"Respond with 'fighting', 'fleeing', or 'surrendering'." "Respond with 'fighting', 'fleeing', or 'surrendering'."
) )
outcome = dungeon_master( outcome = dungeon_master(
f"{action_actor.name} attacks {target} in the {action_room.name}. {action_room.description}." f"{action_actor.name} attacks {target} in the {action_room.name}. {action_room.description}."
f"{action_actor.description}. {target_actor.description}." f"{action_actor.description}. {target_actor.description}."
f"{target} reacts by {reaction}. What is the outcome of the attack? Describe the result in detail." f"{target} reacts by {reaction}. What is the outcome of the attack? Describe the result in detail."
) )
description = ( description = (
f"{action_actor.name} attacks the {target} in the {action_room.name}." f"{action_actor.name} attacks the {target} in the {action_room.name}."
f"{target} reacts by {reaction}. {outcome}" f"{target} reacts by {reaction}. {outcome}"
) )
broadcast(description) broadcast(description)
return description return description
elif target_item: elif target_item:
outcome = dungeon_master( outcome = dungeon_master(
f"{action_actor.name} attacks {target} in the {action_room.name}. {action_room.description}." f"{action_actor.name} attacks {target} in the {action_room.name}. {action_room.description}."
f"{action_actor.description}. {target_item.description}." f"{action_actor.description}. {target_item.description}."
f"What is the outcome of the attack? Describe the result in detail." f"What is the outcome of the attack? Describe the result in detail."
) )
description = ( description = f"{action_actor.name} attacks the {target} in the {action_room.name}. {outcome}"
f"{action_actor.name} attacks the {target} in the {action_room.name}. {outcome}" broadcast(description)
) return description
broadcast(description) else:
return description return f"{target} is not in the {action_room.name}."
else:
return f"{target} is not in the {action_room.name}."
def action_cast(target: str, spell: str) -> str: def action_cast(target: str, spell: str) -> str:
@ -66,8 +73,12 @@ def action_cast(target: str, spell: str) -> str:
_, action_room, action_actor = get_current_context() _, action_room, action_actor = get_current_context()
# make sure the target is in the room # make sure the target is in the room
target_actor = next((actor for actor in action_room.actors if actor.name == target), None) target_actor = next(
target_item = next((item for item in action_room.items if item.name == target), None) (actor for actor in action_room.actors if actor.name == target), None
)
target_item = next(
(item for item in action_room.items if item.name == target), None
)
if not target_actor and not target_item: if not target_actor and not target_item:
return f"{target} is not in the {action_room.name}." return f"{target} is not in the {action_room.name}."
@ -79,8 +90,6 @@ def action_cast(target: str, spell: str) -> str:
f"What is the outcome of the spell? Describe the result in detail." f"What is the outcome of the spell? Describe the result in detail."
) )
description = ( description = f"{action_actor.name} casts {spell} on the {target} in the {action_room.name}. {outcome}"
f"{action_actor.name} casts {spell} on the {target} in the {action_room.name}. {outcome}"
)
broadcast(description) broadcast(description)
return description return description

View File

@ -4,7 +4,7 @@ rules:
match: match:
type: actor type: actor
wet: true wet: true
chance: 0.2 chance: 0.1
set: set:
wet: false wet: false
@ -13,7 +13,7 @@ rules:
type: actor type: actor
wet: true wet: true
temperature: hot temperature: hot
chance: 0.5 chance: 0.2
set: set:
wet: false wet: false
@ -21,15 +21,15 @@ rules:
match: match:
type: room type: room
temperature: hot temperature: hot
chance: 0.5 chance: 0.2
trigger: adventure.sim_systems.environment_triggers:hot_room trigger: [adventure.sim_systems.environment_triggers:hot_room]
- group: environment-temperature - group: environment-temperature
match: match:
type: room type: room
temperature: cold temperature: cold
chance: 0.5 chance: 0.2
trigger: adventure.sim_systems.environment_triggers:cold_room trigger: [adventure.sim_systems.environment_triggers:cold_room]
labels: labels:
wet: wet:

View File

@ -4,7 +4,7 @@ rules:
type: item type: item
edible: true edible: true
cooked: false cooked: false
chance: 0.2 chance: 0.1
set: set:
spoiled: true spoiled: true
@ -12,7 +12,7 @@ rules:
type: item type: item
edible: true edible: true
cooked: true cooked: true
chance: 0.1 chance: 0.05
set: set:
spoiled: true spoiled: true
@ -20,7 +20,7 @@ rules:
- match: - match:
type: actor type: actor
hunger: full hunger: full
chance: 0.2 chance: 0.1
set: set:
hunger: hungry hunger: hungry
@ -28,13 +28,13 @@ rules:
- rule: | - rule: |
"hunger" not in attributes "hunger" not in attributes
set: set:
hunger: hungry hunger: full
# thirst logic # thirst logic
- match: - match:
type: actor type: actor
thirst: hydrated thirst: hydrated
chance: 0.2 chance: 0.1
set: set:
thirst: thirsty thirst: thirsty

View File

@ -1,7 +1,7 @@
from adventure.context import get_current_context, get_dungeon_master from adventure.context import get_current_context, get_dungeon_master
def action_wash() -> str: def action_wash(unused: bool) -> str:
""" """
Wash yourself. Wash yourself.
""" """

View File

@ -2,17 +2,23 @@ rules:
- match: - match:
type: actor type: actor
hygiene: clean hygiene: clean
chance: 0.2 chance: 0.1
set: set:
hygiene: dirty hygiene: dirty
- match: - match:
type: actor type: actor
hygiene: dirty hygiene: dirty
chance: 0.2 chance: 0.1
set: set:
hygiene: filthy hygiene: filthy
# initialize hygiene
- rule: |
"hygiene" not in attributes
set:
hygiene: clean
labels: labels:
hygiene: hygiene:
clean: clean:

View File

@ -4,7 +4,7 @@ rules:
match: match:
type: actor type: actor
mood: happy mood: happy
chance: 0.2 chance: 0.1
set: set:
mood: sad mood: sad
@ -12,7 +12,7 @@ rules:
match: match:
type: actor type: actor
mood: happy mood: happy
chance: 0.2 chance: 0.1
set: set:
mood: neutral mood: neutral
@ -20,7 +20,7 @@ rules:
match: match:
type: actor type: actor
mood: angry mood: angry
chance: 0.2 chance: 0.1
set: set:
mood: neutral mood: neutral
@ -28,7 +28,7 @@ rules:
match: match:
type: actor type: actor
mood: neutral mood: neutral
chance: 0.2 chance: 0.1
set: set:
mood: happy mood: happy
@ -36,7 +36,7 @@ rules:
match: match:
type: actor type: actor
mood: neutral mood: neutral
chance: 0.2 chance: 0.1
set: set:
mood: sad mood: sad
@ -44,7 +44,7 @@ rules:
match: match:
type: actor type: actor
mood: sad mood: sad
chance: 0.2 chance: 0.1
set: set:
mood: angry mood: angry
@ -52,7 +52,7 @@ rules:
match: match:
type: actor type: actor
mood: sad mood: sad
chance: 0.2 chance: 0.1
set: set:
mood: neutral mood: neutral
@ -62,7 +62,7 @@ rules:
type: actor type: actor
mood: sad mood: sad
sleep: rested sleep: rested
chance: 0.5 chance: 0.2
set: set:
sleep: tired sleep: tired
@ -70,7 +70,7 @@ rules:
match: match:
type: actor type: actor
hunger: hungry hunger: hungry
chance: 0.5 chance: 0.2
set: set:
mood: angry mood: angry
@ -79,7 +79,7 @@ rules:
type: actor type: actor
mood: angry mood: angry
hunger: full hunger: full
chance: 0.5 chance: 0.2
set: set:
mood: neutral mood: neutral
@ -88,7 +88,7 @@ rules:
type: actor type: actor
mood: neutral mood: neutral
hunger: full hunger: full
chance: 0.5 chance: 0.2
set: set:
mood: happy mood: happy
@ -97,7 +97,7 @@ rules:
type: actor type: actor
mood: happy mood: happy
hunger: hungry hunger: hungry
chance: 0.5 chance: 0.2
set: set:
mood: neutral mood: neutral
@ -106,7 +106,7 @@ rules:
type: actor type: actor
mood: neutral mood: neutral
sleep: tired sleep: tired
chance: 0.5 chance: 0.2
set: set:
mood: sad mood: sad

View File

@ -1,7 +1,7 @@
from adventure.context import get_current_context, get_dungeon_master from adventure.context import get_current_context, get_dungeon_master
def action_sleep() -> str: def action_sleep(unused: bool) -> str:
""" """
Sleep until you are rested. Sleep until you are rested.
""" """

View File

@ -3,7 +3,7 @@ rules:
- match: - match:
type: actor type: actor
sleep: rested sleep: rested
chance: 0.2 chance: 0.1
set: set:
sleep: tired sleep: tired