Compare commits

..

2 Commits

Author SHA1 Message Date
Alexander Whitestone
a091a5c9bf fix: give tower NPC room movement purposeful goals (#517)
Some checks failed
Self-Healing Smoke / self-healing-smoke (pull_request) Failing after 26s
Smoke Test / smoke (pull_request) Failing after 27s
Agent PR Gate / gate (pull_request) Failing after 37s
Agent PR Gate / report (pull_request) Successful in 8s
2026-04-22 11:51:47 -04:00
Alexander Whitestone
4afde6da78 test: add tower NPC movement acceptance coverage (#517) 2026-04-22 11:47:21 -04:00
4 changed files with 209 additions and 161 deletions

View File

@@ -454,23 +454,112 @@ class TimmyAI:
class NPCAI:
"""AI for non-player characters. They make choices based on goals."""
GOAL_ROOM_TARGETS = {
"Marcus": {
"sit": "Garden",
"speak_truth": "Threshold",
"remember": "Bridge",
},
"Bezalel": {
"forge": "Forge",
"tend_fire": "Forge",
"create_key": "Forge",
},
"Allegro": {
"oversee": "Threshold",
"keep_time": "Tower",
"check_tunnel": "Bridge",
},
"Ezra": {
"study": "Tower",
"read_whiteboard": "Tower",
"find_pattern": "Tower",
},
"Gemini": {
"observe": "Threshold",
"tend_garden": "Garden",
"listen": "Garden",
},
"Claude": {
"inspect": "Threshold",
"organize": "Tower",
"enforce_order": "Bridge",
},
"ClawCode": {
"forge": "Forge",
"test_edge": "Bridge",
"build_weapon": "Forge",
},
"Kimi": {
"contemplate": "Garden",
"read": "Tower",
"remember": "Bridge",
},
}
GOAL_CYCLES = {
"Marcus": ("sit", "speak_truth", "remember"),
"Allegro": ("oversee", "keep_time", "check_tunnel"),
"Claude": ("inspect", "organize", "enforce_order"),
"ClawCode": ("test_edge", "forge", "build_weapon"),
"Kimi": ("contemplate", "read", "remember"),
}
def __init__(self, world):
self.world = world
def _available_targets(self, available, prefix):
return [a.split(":", 1)[1] for a in available if a.startswith(f"{prefix}:")]
def _target_room_for(self, char_name, goal):
return self.GOAL_ROOM_TARGETS.get(char_name, {}).get(goal)
def _next_direction_toward(self, current_room, target_room):
if current_room == target_room:
return None
frontier = [(current_room, [])]
seen = {current_room}
while frontier:
room, path = frontier.pop(0)
if room == target_room:
return path[0] if path else None
for direction, dest in self.world.rooms[room].get("connections", {}).items():
if dest not in seen:
seen.add(dest)
frontier.append((dest, path + [direction]))
return None
def _move_toward_goal(self, room, target_room):
direction = self._next_direction_toward(room, target_room)
return f"move:{direction}" if direction else None
def _advance_goal_cycle(self, char_name, char):
cycle = self.GOAL_CYCLES.get(char_name)
if not cycle or self.world.tick <= 0:
return
goal = char.get("active_goal")
if goal not in cycle:
return
target_room = self._target_room_for(char_name, goal)
if char.get("room") != target_room:
return
if self.world.tick % 12 != 0:
return
index = cycle.index(goal)
char["active_goal"] = cycle[(index + 1) % len(cycle)]
def make_choice(self, char_name):
"""Make a choice for this NPC this tick."""
char = self.world.characters[char_name]
self._advance_goal_cycle(char_name, char)
room = char["room"]
available = ActionSystem.get_available_actions(char_name, self.world)
# If low energy, rest
if char["energy"] <= 1:
return "rest"
# Goal-driven behavior
goal = char["active_goal"]
if char_name == "Marcus":
return self._marcus_choice(char, room, available)
elif char_name == "Bezalel":
@@ -487,66 +576,96 @@ class NPCAI:
return self._clawcode_choice(char, room, available)
elif char_name == "Kimi":
return self._kimi_choice(char, room, available)
return "rest"
def _marcus_choice(self, char, room, available):
goal = char.get("active_goal", "sit")
target_room = self._target_room_for("Marcus", goal)
if room != target_room:
return self._move_toward_goal(room, target_room) or "rest"
others = self._available_targets(available, "speak")
if goal == "speak_truth" and others:
return f"speak:{random.choice(others)}"
if goal == "remember" and room == "Bridge":
return random.choice(["examine", "rest"])
if room == "Garden" and random.random() < 0.7:
return "rest"
if room != "Garden":
return "move:west"
# Speak to someone if possible
others = [a.split(":")[1] for a in available if a.startswith("speak:")]
if others and random.random() < 0.4:
return f"speak:{random.choice(others)}"
return "rest"
def _bezalel_choice(self, char, room, available):
target_room = self._target_room_for("Bezalel", char.get("active_goal", "forge"))
if room != target_room:
return self._move_toward_goal(room, target_room) or "rest"
if room == "Forge" and self.world.rooms["Forge"]["fire"] == "glowing":
return random.choice(["forge", "rest"] if char["energy"] > 2 else ["rest"])
if room != "Forge":
return "move:west"
if random.random() < 0.3:
return "tend_fire"
return "forge"
def _kimi_choice(self, char, room, available):
others = [a.split(":")[1] for a in available if a.startswith("speak:")]
goal = char.get("active_goal", "contemplate")
target_room = self._target_room_for("Kimi", goal)
if room != target_room:
return self._move_toward_goal(room, target_room) or "rest"
others = self._available_targets(available, "speak")
if goal == "read" and room == "Tower":
return "study" if char["energy"] > 2 else "rest"
if room == "Garden" and others and random.random() < 0.3:
return f"speak:{random.choice(others)}"
if room == "Tower":
return "study" if char["energy"] > 2 else "rest"
return "move:east" # Head back toward Garden
if room == "Bridge":
return random.choice(["examine", "rest"])
return "rest"
def _gemini_choice(self, char, room, available):
others = [a.split(":")[1] for a in available if a.startswith("listen:")]
if room == "Garden" and others and random.random() < 0.4:
return f"listen:{random.choice(others)}"
return random.choice(["plant", "rest"] if room == "Garden" else ["move:west"])
goal = char.get("active_goal", "observe")
target_room = self._target_room_for("Gemini", goal)
if room != target_room:
return self._move_toward_goal(room, target_room) or "rest"
listeners = self._available_targets(available, "listen")
if room == "Garden" and listeners and random.random() < 0.4:
return f"listen:{random.choice(listeners)}"
return random.choice(["plant", "rest"] if room == "Garden" else ["examine", "rest"])
def _ezra_choice(self, char, room, available):
goal = char.get("active_goal", "study")
target_room = self._target_room_for("Ezra", goal)
if room != target_room:
return self._move_toward_goal(room, target_room) or "rest"
if room == "Tower" and char["energy"] > 2:
return random.choice(["study", "write_rule", "help:Timmy"])
if room != "Tower":
return "move:south"
return "rest"
def _claude_choice(self, char, room, available):
others = [a.split(":")[1] for a in available if a.startswith("confront:")]
goal = char.get("active_goal", "inspect")
target_room = self._target_room_for("Claude", goal)
if room != target_room:
return self._move_toward_goal(room, target_room) or "rest"
others = self._available_targets(available, "confront")
if others and random.random() < 0.2:
return f"confront:{random.choice(others)}"
return random.choice(["examine", "rest"])
def _clawcode_choice(self, char, room, available):
goal = char.get("active_goal", "test_edge")
target_room = self._target_room_for("ClawCode", goal)
if room != target_room:
return self._move_toward_goal(room, target_room) or "rest"
if room == "Forge" and char["energy"] > 2:
return "forge"
return random.choice(["move:east", "forge", "rest"])
return random.choice(["examine", "rest"])
def _allegro_choice(self, char, room, available):
others = [a.split(":")[1] for a in available if a.startswith("speak:")]
goal = char.get("active_goal", "oversee")
target_room = self._target_room_for("Allegro", goal)
if room != target_room:
return self._move_toward_goal(room, target_room) or "rest"
others = self._available_targets(available, "speak")
if others and random.random() < 0.3:
return f"speak:{random.choice(others)}"
return random.choice(["move:north", "move:south", "examine"])
return random.choice(["examine", "rest"])
class DialogueSystem:

View File

@@ -1,65 +0,0 @@
# MATH-006: Independent Math Review Gate
*Prevents Timmy from publicly claiming mathematical novelty before human/formal verification.*
## Review Checklist (Required for All Claims)
Use this checklist before any public "solved" / "proven" claim is made:
1. **Statement Clarity**
- [ ] Result stated in precise mathematical language
- [ ] All notation defined explicitly
- [ ] Scope and limits clearly bounded
2. **Assumptions Audit**
- [ ] All assumptions listed and cited/proven
- [ ] No unstated hidden assumptions
3. **Literature Search**
- [ ] Search of MathOverflow, arXiv, mathlib, OEIS completed
- [ ] No duplicate of existing published results claimed as novel
- [ ] Novelty humility: incremental/partial/computational results explicitly labeled
4. **Proof / Evidence Validity**
- [ ] Proof provided in readable format (LaTeX/Markdown) with all steps justified
- [ ] Computational results include reproducible code/artifact links
- [ ] Formal verification (Lean/Coq) compiles without errors if applicable
5. **Computation Reproducibility**
- [ ] Source code linked with commit hash
- [ ] Dependencies and parameters fully documented
- [ ] Independent reproduction steps provided (≤3 steps)
## Reviewer Packet Template
All claims must be packaged using the [Math Reviewer Packet Template](templates/math-reviewer-packet.md) before submission to any review channel.
## Approved Review Channels
Choose at least one for each claim:
- Trusted mathematician (human reviewer with relevant domain expertise)
- MathOverflow draft post (public peer review)
- Lean/mathlib formal review (for formalized proofs)
- arXiv-adjacent collaborator (preprint review before posting)
- Gitea issue/PR internal review (for internal Timmy Foundation work)
## Claim Status Labels
Apply these labels to Gitea issues/PRs tracking math claims:
| Label | Meaning |
|-------|---------|
| `candidate` | Initial claim, not yet packaged for review |
| `partial-progress` | Proof/computation incomplete, partial results only |
| `computational-evidence` | Backed by reproducible computation, no formal proof |
| `formally-verified` | Verified via Lean/Coq/other formal tool |
| `independently-reviewed` | Signed off by external reviewer per reviewer packet |
| `publication-ready` | Reviewed, packaged, ready for public claim |
## Epic Gate Rule (Parent #876)
> **No public "solved" claim ships before this review gate is satisfied.**
> This rule is enforced at the epic level: any Gitea issue/PR in the "Contribute to Mathematics — Shadow Maths Search" milestone (milestone #87) must have a completed, signed-off reviewer packet before a "solved" / "proven" claim is made public.
## Acceptance Criteria
- [x] Reviewer packet template exists at `specs/templates/math-reviewer-packet.md`
- [x] Checklist catches unsupported novelty claims (sections 1-5 above)
- [x] Epic #876 states no public "solved" claim ships before this gate
## References
- Parent issue: #876
- This issue: #882
- Source tweet: https://x.com/rockachopa/status/2048170592759652597

View File

@@ -1,60 +0,0 @@
# Math Reviewer Packet Template
*Use this template to package any claimed mathematical result for independent review before public "solved" claims are made.*
## 1. Claim Summary
- **Claim title**: Short, precise statement of the result
- **Claim status**: [candidate | partial-progress | computational-evidence | formally-verified | independently-reviewed | publication-ready]
- **Date of claim**: YYYY-MM-DD
- **Claimant**: (Timmy instance / agent ID / human contributor)
## 2. Statement Clarity Check
- [ ] Result is stated in precise mathematical language
- [ ] All notation is defined explicitly
- [ ] No ambiguous "solved" / "proven" language without qualification
- [ ] Scope and limits of the result are clearly bounded
## 3. Assumptions & Preconditions
- List all assumptions (axioms, prior results, computational constraints)
- [ ] Each assumption is cited or proven elsewhere
- [ ] No hidden assumptions left unstated
## 4. Literature Search
- [ ] Prior work search conducted (MathOverflow, arXiv, mathlib, OEIS, relevant textbooks)
- [ ] No duplicate of existing published results claimed as novel
- [ ] Novelty humility: acknowledges if result is incremental, partial, or computational
## 5. Proof / Evidence Validity
### For Proof-Based Results
- [ ] Full proof provided in machine-readable format (LaTeX / Markdown)
- [ ] Each step is logically justified
- [ ] No gaps longer than 2 sentences without explicit citation or lemma
### For Computational Results
- [ ] Code/artifact link provided (reproducible environment)
- [ ] Random seeds / parameters fully documented
- [ ] Output verified by independent script (if applicable)
### For Formal Verification
- [ ] Lean / Coq / other formal proof assistant file linked
- [ ] Compiles without errors on standard toolchain
## 6. Reproducibility Package
- [ ] All source code used is linked (repo commit hash / Gitea issue/PR reference)
- [ ] Dependencies listed with versions
- [ ] Minimal reproduction steps provided (3 steps or fewer)
## 7. Review Channel & Sign-off
- **Selected review channel**: (trusted mathematician / MathOverflow draft / Lean/mathlib review / arXiv-adjacent collaborator / other)
- **Reviewer identity**: (handle / name / affiliation)
- **Review date**: YYYY-MM-DD
- **Review outcome**: [APPROVED | REVISION REQUIRED | REJECTED]
- **Reviewer notes**: (free text)
## 8. Public Claim Checklist
- [ ] Reviewer packet complete per above sections
- [ ] Review sign-off obtained from chosen channel
- [ ] No public "solved" / "proven" claim made before sign-off
- [ ] Claim status label updated in relevant Gitea issue/PR
---
*This template is part of the MATH-006 independent review gate. No public novelty claim ships without a completed, signed-off packet.*

View File

@@ -0,0 +1,54 @@
from importlib.util import module_from_spec, spec_from_file_location
from pathlib import Path
ROOT = Path(__file__).resolve().parent.parent
GAME_PATH = ROOT / "evennia" / "timmy_world" / "world" / "game.py"
def load_game_module():
spec = spec_from_file_location("tower_world_game", GAME_PATH)
module = module_from_spec(spec)
assert spec.loader is not None
spec.loader.exec_module(module)
module.random.seed(0)
return module
def _visitor_sets_after_ticks(module, ticks=100):
engine = module.GameEngine()
engine.start_new_game()
visitors = {room: set() for room in engine.world.rooms}
for _ in range(ticks):
engine.run_tick("rest")
for name, char in engine.world.characters.items():
if name == "Timmy":
continue
visitors[char["room"]].add(name)
return visitors
class TestTowerGameNpcPurpose:
def test_goal_driven_room_targets(self):
module = load_game_module()
world = module.World()
npc_ai = module.NPCAI(world)
world.characters["Marcus"]["room"] = "Threshold"
world.characters["Marcus"]["active_goal"] = "sit"
assert npc_ai.make_choice("Marcus") == "move:east"
world.characters["Ezra"]["room"] = "Threshold"
world.characters["Ezra"]["active_goal"] = "study"
assert npc_ai.make_choice("Ezra") == "move:north"
world.characters["Claude"]["room"] = "Threshold"
world.characters["Claude"]["active_goal"] = "enforce_order"
assert npc_ai.make_choice("Claude") == "move:south"
def test_every_room_gets_multiple_npc_visitors_over_100_ticks(self):
module = load_game_module()
visitors = _visitor_sets_after_ticks(module, ticks=100)
assert all(len(names) >= 2 for names in visitors.values()), visitors
assert len(visitors["Bridge"]) >= 3, visitors["Bridge"]