Translate Opportunist, Aggressive and Risky trainer AI

Add the AI_Opportunist, AI_Aggressive and AI_Risky scoring layers with
the ROM's stall, reckless and risky tables, HP thresholds, last-wins
ties and strict knockout test. AIDamageCalc is ported as a
pre-variation damage estimate, including a critical-hit flag left over
from an earlier move, which the original also reads. Smart remains the
only refused layer, so the rival stays gated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Sébastien QUEROLandClaude Opus 5.5 committed 2026-09-24 14:36:46 +02:00
1 parent 3e92936cb9
commit 0d1bedb3b1
10 files changed
+294 -11

No files matched your search

+38
View File
@@ -157,3 +157,41 @@ Mystery Egg), Route 30/46. NPCs do not roam yet.
Next: NPC roaming movement (`map_objects.asm` random walk/spin, radius and
visibility rules, deterministic RNG in tests), trainer sight lines and trainer
battles, Route 30 and Mr. Pokémon, capture and the catching tutorial.
## Trainer AI continuation: 2026-09-24
The trainer foundation was subsequently committed through `3e92936`. The next
AI increment translates Opportunist, Aggressive and Risky scoring, including
the ROM's stall/reckless/risky tables and Aggressive/Risky's deterministic
pre-variation damage estimate. Smart is now the only refused move-scoring layer,
so the rival remains gated. Continue with Smart before the rival, or with
trainer sight lines and normal trainer-object scripts for the already-supported
Youngster and Bug Catcher classes on Route 30.
## AI layer review: 2026-09-24 (resumed from Codex)
Claude Code checked Codex's uncommitted Opportunist, Aggressive and Risky layers
against `engine/battle/ai/scoring.asm`. The HP thresholds, `AI_50_50` (≥128),
`79 percent - 1` (200), last-wins ties, the power < 2 and reckless exclusions,
the strict-borrow KO test and the constant-damage paths all match.
One fix: `AIDamageCalc` goes through `EnemyAttackDamage` and
`BattleCommand_DamageCalc`, and both read `wCriticalHit`. A flag left over from
an earlier move therefore selects unboosted stats (ignoring screens) and
doubles the estimate. `enemyAIDamage` now reads the native `criticalHit`
instead of hard-coding `false`. It also reuses `truncate`. A local-ROM test
fixes the estimate at 4, 3 (Reflect) and 6 (leftover critical).
Known side effects of `AIDamageCalc` that are not modelled: it overwrites
`wCurDamage`, `wTypeModifier`, `wAttackMissed` and `hBattleTurn`. `CheckTurn`
resets the modifier and miss flag before each move. Whether the `wCurDamage`
overwrite can reach Counter/Mirror Coat still needs checking before those
effects are ported.
Final checks: 147 unit tests with the local ROM; 42 Chromium/WebKit browser
tests; native and reference builds; reference, release and vendor checks;
`git diff --check`. Not committed.
Next (unchanged): Smart AI before the rival, or trainer sight lines and
normal trainer-object scripts for Route 30's Youngster and Bug Catcher.