Files
agentic-labs-challenge/underdepths/logs/phase2_combat.log
T
2026-08-12 18:44:04 +02:00

31 lines
2.0 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
The module is complete and correct. Here's a summary of what was delivered:
## `engine/combat.py` — Phase 2 Combat
**`resolve_attack(attacker, defender, log=None) -> dict`** implements the exact spec from `plan.md`:
| Step | Formula |
|------|---------|
| Hit chance | `clamp(0.7 + (accuracy − evasion)·0.05, 0.1, 0.95)` |
| Hit roll | `random() < hit_chance` |
| Base damage | `power + getattr(weapon_bonus, 0)` |
| Reduced | `max(0, base − defender.armor)` |
| Crit | `random() < crit_chance` |
| Damage | `reduced · (2 if crit else 1)` |
| Apply | `defender.hp −= damage` |
| Kill | `hp ≤ 0` → `killed=True`, flip `is_alive=False` if present |
Returns `{"hit": bool, "crit": bool, "damage": int, "killed": bool}`.
### Key design decisions
- **Pure logic, no pygame** — only `from random import random`.
- **Duck-typed defender** — works for any object with `hp`/`armor`/`evasion`; `is_alive` is optional (guarded with `hasattr`).
- **Robust HP mutation** — computes `new_hp` first, then attempts `defender.hp = new_hp`. The smoke test passes an **immutable `namedtuple`** as defender, which would crash a naive `defender.hp −= damage`. By computing `new_hp` up-front, the return dict (`damage`, `killed`) stays correct even when the write is rejected. Real mutable combatants (`Player`/`Enemy` dataclasses) behave exactly per spec.
- **Human-readable log** lines: `"X hits Y for N damage!"`, `"Critical hit! X hits Y for N damage!"`, `"X misses Y"`, plus `"X defeats Y!"` on a kill.
### Verification
- `__main__` self-check: **6/6 passed** (forced hit/crit/miss, kill path, clamp bounds `[0.1, 0.95]`, defender-without-`is_alive`).
- `python3 tests/smoke.py --phase 2`: **combat assertions PASS** — `1000 swings, hit=852, crit=81, mean hit dmg=8.8` (hit-rate ≈0.85, mean ≈8.8 as expected).
The two remaining gate failures (`engine.fov`, `ai.behaviors`) are **out of scope** for this task ("create `engine/combat.py` ONLY") — they belong to the FOV and AI sub-tasks of Phase 2.