(Underdepths) Pass 2
This commit is contained in:
1 parent
4a5a92cb74
commit
b49c285c89
37 files changed
+5590
No files matched your search
@@ -0,0 +1,28 @@
|
||||
Done. `ai/behaviors.py` is implemented and the phase 2 gate passes.
|
||||
|
||||
## Summary
|
||||
|
||||
Created **`ai/behaviors.py`** with the exact required signature:
|
||||
|
||||
```python
|
||||
take_enemy_turn(enemy, game_map, player, enemy_visible:set) -> list[str]
|
||||
```
|
||||
|
||||
### Behaviors implemented (one action per call)
|
||||
- **wander** — 50/50 wait or step to a random walkable 8-neighbour; never seeks the player.
|
||||
- **chase** — player visible → set `last_known_pos`, melee (`resolve_attack`) when Chebyshev-adjacent, else one A* step toward the player (`engine.pathfinding.astar`); not visible → step toward `last_known_pos`, and wander once reached/absent.
|
||||
- **flee** — below 30% max HP, step to the neighbour maximizing Chebyshev distance from the player; otherwise behave as chase.
|
||||
- **ranged** — visible & distance > 3 → ranged shot using `ranged_power` (falling back to `power`) with a distance hit penalty, logging **"fires at you"** and mutating `player.hp`; visible & distance ≤ 2 → kite away; not visible → wander.
|
||||
- **phase** — moves one Chebyshev step toward the player **ignoring walls** (may occupy wall tiles), acting only every other turn; adjacent → melee.
|
||||
- **split** — behaves as chase (splitting-on-death is the death handler's job).
|
||||
|
||||
### Design notes
|
||||
- Mutates enemy/player positions and `player.hp` only; **never** mutates `game_map`.
|
||||
- Unknown behaviors gracefully fall back to wander so a bad roster entry can't crash the loop.
|
||||
- Two robustness adapters, all confined to this file:
|
||||
- **`_AttackerView`** — `resolve_attack` reads `accuracy`/`crit_chance`/`weapon_bonus` directly, but the slotted `Enemy` model only guarantees `power`/`armor`/`name`. The view supplies the enemy's real power/name plus `getattr` combat defaults (picked up automatically if phase 3 adds them).
|
||||
- **`_phase_should_act`** — prefers `enemy._phase_toggled` (per the spec), and falls back to a module-level dict keyed by `id(enemy)` for the slotted enemy (spec also explicitly permits "a module-level set").
|
||||
|
||||
### Verification
|
||||
- `__main__` self-check: exercises chase-advance, adjacent melee, wander bounds, flee, ranged-fire, ranged-kite, phase toggle, split-as-chase, and unknown-behavior fallback → **all passed**.
|
||||
- `python3 tests/smoke.py --phase 2` → **6 passed, 0 failed**, including `AI: goblin chased along corridor (2->3)`.
|
||||
Reference in new issue
Block a user