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:
1 parent
3e92936cb9
commit
0d1bedb3b1
10 files changed
+294
-11
No files matched your search
+1
-1
@@ -71,7 +71,7 @@ Native saves are version 3. Version 2 added scene values by owning map, phone co
|
||||
|
||||
`game/rom/trainers.ts` decodes `TrainerGroups`, `TrainerClassAttributes`, `TrainerClassNames`, `TrainerClassDVs` and map trainer headers. Tests cover all 542 ROM records across 67 classes; CAL2 construction refuses its SRAM-dependent Mystery Gift party.
|
||||
|
||||
`game/battle/ai.ts` translates `AIChooseMove`, `AI_Redundant` and the Basic, Setup, Types, Offensive, Cautious and Status layers. It preserves the original random tie selection and known redundancy quirks. Smart, Opportunist, Aggressive and Risky remain refused, including the rival's AI. Synthetic scoring vectors establish the tested branches; original-engine AI execution parity is still pending.
|
||||
`game/battle/ai.ts` translates `AIChooseMove`, `AI_Redundant` and the Basic, Setup, Types, Offensive, Opportunist, Aggressive, Cautious, Status and Risky layers. It preserves the original random tie selection, known redundancy quirks, HP thresholds, exclusions and the deterministic pre-variation damage estimate used by Aggressive and Risky. Smart remains refused, including the rival's AI. Synthetic scoring vectors establish the tested branches; original-engine AI execution parity is still pending.
|
||||
|
||||
`loadtrainer`, `winlosstext` and `startbattle` now run single-Pokémon trainer battles through the existing battle UI. Tests cover Joey's ROM party/text/reward, RUN refusal, trainer experience, Amulet Coin, CANLOSE behavior, money limits, transactional rollback and midbattle restore. Chromium and WebKit exercise the UI with a test-only script. Production map gates are unchanged. Trainer items, party switching, sight lines, trainer-object interaction and the rival round trip remain unported.
|
||||
|
||||
|
||||
+2
-2
@@ -62,10 +62,10 @@ The emulator-backed prototype is now at `/reference.html`. The default applicati
|
||||
## Implemented: first scripted trainer battle slice
|
||||
|
||||
- ROM decoder for 542 trainer records across 67 classes, all four party formats, class names, DVs, rewards and map trainer headers. SRAM-dependent Mystery Gift parties remain refused.
|
||||
- Native move scoring for Basic, Setup, Types, Offensive, Cautious and Status, with deterministic tie selection. Other scoring layers remain refused.
|
||||
- Native move scoring for Basic, Setup, Types, Offensive, Opportunist, Aggressive, Cautious, Status and Risky, with deterministic tie selection and the original pre-variation damage estimate. Smart remains refused.
|
||||
- Scripted single-Pokémon trainer battles support the challenge, sending out, RUN refusal, experience, win/loss text and prize money, including Amulet Coin. Script results, party changes and rewards commit together; interrupted saves replay from committed state.
|
||||
- Local-ROM tests and Chromium/WebKit tests exercise Youngster Joey through a test-only script. No new maps or trainer encounters are enabled in normal play.
|
||||
- Next: advanced AI, trainer party switching/items, trainer sight lines and normal trainer-object scripts, then the rival and Route 30 story. The rival remains refused because its AI is not yet translated.
|
||||
- Next: Smart AI, trainer party switching/items, trainer sight lines and normal trainer-object scripts, then the rival and Route 30 story. The rival remains refused because Smart AI is not yet translated.
|
||||
|
||||
## In progress: native battles
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in new issue
Block a user