Spaces:
Runtime error
Runtime error
PPP commited on
Commit ·
67cdcb8
1
Parent(s): da29cc6
fix(validation): restrict rest actions to valid rest locations
Browse files- evaluation/datasets/consistency.json +42 -0
- state_manager.py +14 -8
evaluation/datasets/consistency.json
CHANGED
|
@@ -152,6 +152,48 @@
|
|
| 152 |
"raw_input": "施放火球术"
|
| 153 |
},
|
| 154 |
"expected_valid": false
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 155 |
}
|
| 156 |
],
|
| 157 |
"state_check_cases": [
|
|
|
|
| 152 |
"raw_input": "施放火球术"
|
| 153 |
},
|
| 154 |
"expected_valid": false
|
| 155 |
+
},
|
| 156 |
+
{
|
| 157 |
+
"id": "guard_009",
|
| 158 |
+
"setup": {
|
| 159 |
+
"player": {
|
| 160 |
+
"location": "村庄旅店",
|
| 161 |
+
"hp": 72,
|
| 162 |
+
"morale": 60,
|
| 163 |
+
"sanity": 82
|
| 164 |
+
},
|
| 165 |
+
"world": {
|
| 166 |
+
"current_scene": "村庄旅店"
|
| 167 |
+
}
|
| 168 |
+
},
|
| 169 |
+
"intent": {
|
| 170 |
+
"intent": "REST",
|
| 171 |
+
"target": null,
|
| 172 |
+
"details": "在旅店休息恢复",
|
| 173 |
+
"raw_input": "休息一会儿"
|
| 174 |
+
},
|
| 175 |
+
"expected_valid": true
|
| 176 |
+
},
|
| 177 |
+
{
|
| 178 |
+
"id": "guard_010",
|
| 179 |
+
"setup": {
|
| 180 |
+
"player": {
|
| 181 |
+
"location": "村庄广场",
|
| 182 |
+
"hp": 72,
|
| 183 |
+
"morale": 60,
|
| 184 |
+
"sanity": 82
|
| 185 |
+
},
|
| 186 |
+
"world": {
|
| 187 |
+
"current_scene": "村庄广场"
|
| 188 |
+
}
|
| 189 |
+
},
|
| 190 |
+
"intent": {
|
| 191 |
+
"intent": "REST",
|
| 192 |
+
"target": null,
|
| 193 |
+
"details": "在广场原地休息",
|
| 194 |
+
"raw_input": "休息一会儿"
|
| 195 |
+
},
|
| 196 |
+
"expected_valid": false
|
| 197 |
}
|
| 198 |
],
|
| 199 |
"state_check_cases": [
|
state_manager.py
CHANGED
|
@@ -1491,13 +1491,19 @@ class GameState:
|
|
| 1491 |
return False, f"「{target}」已经装备在身上了。"
|
| 1492 |
return False, f"你的背包中没有「{target}」,无法装备。"
|
| 1493 |
|
| 1494 |
-
# --- 检测 2: SKILL: 必须已习得 ---
|
| 1495 |
-
if action == "SKILL" and target:
|
| 1496 |
-
if target not in self.player.skills:
|
| 1497 |
-
return False, f"你尚未习得技能「{target}」。"
|
| 1498 |
-
|
| 1499 |
-
# --- 检测 3:
|
| 1500 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1501 |
for event in self.event_log:
|
| 1502 |
sc = event.state_changes
|
| 1503 |
if isinstance(sc, dict):
|
|
@@ -1523,7 +1529,7 @@ class GameState:
|
|
| 1523 |
if verb + item_name in raw_input:
|
| 1524 |
return False, f"你的背包中没有「{item_name}」,无法{verb}。"
|
| 1525 |
|
| 1526 |
-
# --- 检测
|
| 1527 |
# 匹配常见的"使用物品"语句模式,提取物品名称并校验
|
| 1528 |
extraction_patterns = [
|
| 1529 |
(r'(?:掏出|拿出|拔出|举起)(.{2,8}?)(?:$|[,。!?,\s来])', "使用"),
|
|
|
|
| 1491 |
return False, f"「{target}」已经装备在身上了。"
|
| 1492 |
return False, f"你的背包中没有「{target}」,无法装备。"
|
| 1493 |
|
| 1494 |
+
# --- 检测 2: SKILL: 必须已习得 ---
|
| 1495 |
+
if action == "SKILL" and target:
|
| 1496 |
+
if target not in self.player.skills:
|
| 1497 |
+
return False, f"你尚未习得技能「{target}」。"
|
| 1498 |
+
|
| 1499 |
+
# --- 检测 3: REST: 当前位置必须允许休息 ---
|
| 1500 |
+
if action == "REST":
|
| 1501 |
+
current_loc = self.world.locations.get(self.player.location)
|
| 1502 |
+
if current_loc is None or not current_loc.rest_available:
|
| 1503 |
+
return False, "这里不适合休息,试着前往旅店或营地。"
|
| 1504 |
+
|
| 1505 |
+
# --- 检测 4: 扫描 raw_input 中是否在使用上下文中引用了未拥有的已知物品 ---
|
| 1506 |
+
known_items: set[str] = set(self.world.item_registry.keys())
|
| 1507 |
for event in self.event_log:
|
| 1508 |
sc = event.state_changes
|
| 1509 |
if isinstance(sc, dict):
|
|
|
|
| 1529 |
if verb + item_name in raw_input:
|
| 1530 |
return False, f"你的背包中没有「{item_name}」,无法{verb}。"
|
| 1531 |
|
| 1532 |
+
# --- 检测 5: 检查 raw_input 中是否提及使用完全未知的物品 ---
|
| 1533 |
# 匹配常见的"使用物品"语句模式,提取物品名称并校验
|
| 1534 |
extraction_patterns = [
|
| 1535 |
(r'(?:掏出|拿出|拔出|举起)(.{2,8}?)(?:$|[,。!?,\s来])', "使用"),
|