restrict multi-step routing to visited locations only
Browse files- src/agents/game_master.py +6 -0
- src/world/state.py +21 -0
src/agents/game_master.py
CHANGED
|
@@ -91,6 +91,12 @@ YOUR RULES:
|
|
| 91 |
Never use a direction that is not listed in the current location's exits.
|
| 92 |
Plan each step: from room_21 the only exit is downstairs to tavern,
|
| 93 |
from tavern north leads to street. So room_21 to street = ['downstairs', 'north'].
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
"""
|
| 95 |
|
| 96 |
GM_PROMPT = """
|
|
|
|
| 91 |
Never use a direction that is not listed in the current location's exits.
|
| 92 |
Plan each step: from room_21 the only exit is downstairs to tavern,
|
| 93 |
from tavern north leads to street. So room_21 to street = ['downstairs', 'north'].
|
| 94 |
+
|
| 95 |
+
10. Multi-step movement is only allowed to locations the player has already visited.
|
| 96 |
+
These are shown in KNOWN MAP.
|
| 97 |
+
If the destination is not in KNOWN MAP, move one step at a time toward it
|
| 98 |
+
using only exits visible in the current location.
|
| 99 |
+
Never guess directions to unvisited locations.
|
| 100 |
"""
|
| 101 |
|
| 102 |
GM_PROMPT = """
|
src/world/state.py
CHANGED
|
@@ -263,6 +263,27 @@ class WorldState:
|
|
| 263 |
# Normalise to list to handle both single direction and multi-step
|
| 264 |
directions = dest if isinstance(dest, list) else [dest]
|
| 265 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 266 |
for direction in directions:
|
| 267 |
loc = self.current_location()
|
| 268 |
if direction in loc.exits and loc.exits[direction] in self.locations:
|
|
|
|
| 263 |
# Normalise to list to handle both single direction and multi-step
|
| 264 |
directions = dest if isinstance(dest, list) else [dest]
|
| 265 |
|
| 266 |
+
# For multi-step paths, check if final destination is visited
|
| 267 |
+
# If not visited, truncate to single step only
|
| 268 |
+
if len(directions) > 1:
|
| 269 |
+
# Simulate the path to find the final location
|
| 270 |
+
simulated_loc = self.player.location
|
| 271 |
+
valid_directions = []
|
| 272 |
+
for direction in directions:
|
| 273 |
+
loc = self.locations.get(simulated_loc)
|
| 274 |
+
if loc and direction in loc.exits and loc.exits[direction] in self.locations:
|
| 275 |
+
next_loc_id = loc.exits[direction]
|
| 276 |
+
next_loc = self.locations[next_loc_id]
|
| 277 |
+
if not next_loc.visited and next_loc_id != self.player.location:
|
| 278 |
+
# Unvisited destination — stop path here, take only this one step
|
| 279 |
+
valid_directions.append(direction)
|
| 280 |
+
break
|
| 281 |
+
valid_directions.append(direction)
|
| 282 |
+
simulated_loc = next_loc_id
|
| 283 |
+
else:
|
| 284 |
+
break
|
| 285 |
+
directions = valid_directions if valid_directions else directions[:1]
|
| 286 |
+
|
| 287 |
for direction in directions:
|
| 288 |
loc = self.current_location()
|
| 289 |
if direction in loc.exits and loc.exits[direction] in self.locations:
|