# v1.2 experimental offline simulation Implemented as a separate experimental Python model, parallel to original AIR runtime research. This is useful approximate combat, not an AIR engine replay. ## Public request/result contract `ranch_assistant.battle_simulator.ExperimentalBattleRuntime` implements `inspect(request)` and `run(request, cancel_event=None, timeout=30.0)`. Both accept dicts or objects with the same attributes. Request fields are `context` (`ordinary_stage`, `task_battle`, `task_pass_stage`), `original_data` containing the original `battle` dictionary, `roster` containing the full raw snapshot (or `snapshot.raw`), `team` (original ordered team string), and `battle_position`. Optional `seed` defaults to zero. No game API is called. Every response carries `execution_mode='experimental'`, `approximate=True`, `faithful=False`, `settlement_eligible=False`, `diagnostics`, and `ignored_mechanics`. `supported` means this approximate model can execute; it is never a claim of original engine fidelity or permission to settle. Unsupported objectives/controllers/triggers return `outcome='unsupported'`. An executed result includes natural `win`/`loss`, or technical `timeout`/`cancelled`, `units`, `events`, `elapsed_ms`, AP history, kill counters, and detected anomalies. Any `battle_data` will be explicitly model-derived evidence, never a fabricated victory or an authorization to submit. ### Worker contract ```python request = { "context": "ordinary_stage", # also task_battle / task_pass_stage "original_data": {"battle": original_battle_config}, "roster": snapshot.raw, # full monsters/master/teams/monsterAttributes "team": "teamA", # team name, preserves its ordered monster slots "battle_position": original_battle_position, "seed": 0, } capability = ExperimentalBattleRuntime().inspect(request) result = ExperimentalBattleRuntime().run(request, cancel_event=event, timeout=30.0) # result: # execution_mode: 'experimental'; approximate: True; faithful: False # settlement_eligible: False (offline evidence only, explicit future review required) # requires_realtime_wait: True # supported: bool; outcome: win/loss/timeout/cancelled/unsupported/error # elapsed_ms: modeled game clock; elapsed_seconds: elapsed_ms / 1000 # timeout_kind: wall_clock / resource_limit for technical timeouts # units: per-unit initial stats, hp, position, waiting/active/dead, summon origin # events: bounded deterministic trajectory; trace_truncated / omitted_events explicit # ap: team -> {initial, current, max, spent, recovered}; kills: all enemy deaths # kill_monster: source-selective non-player, non-object, mode==2 death map # anomalies: every anomaly detected, unfiltered; diagnostics; ignored_mechanics # battle_data: trajectory-derived source fields for completed win/loss only; # never treat these as authorized live settlement, never discard anomalies. # battle_data.battleMonIds: original ordered roster instance IDs from selected # team; includes waiting originals, excludes summons, empty for hideTeamMon # execution_status: completed / timed_out / cancelled / unsupported / error # terminal: True only for completed model win/loss # terminal_reason: elimination / battle_time_limit for completed models ``` Natural expiry of `battle.time` is **completed loss**, with `terminal_reason='battle_time_limit'`, `battle_data.win=False`, `leftTime=0`, and the full configured modeled elapsed time. Technical worker timeout is `outcome='timeout'`, `execution_status='timed_out'`, `terminal=False`, and `battle_data=None`. Cancellation also has no battle data. This distinction separates incomplete execution from a completed natural loss. `run` uses `Popen([sys.executable, '-m', 'ranch_assistant.battle_simulator', '--worker'], CREATE_NO_WINDOW on Windows)` with pipes and bounded output. CPU simulation does not run in the GUI process. The worker cannot use sockets; it reads only bundled combat artifacts and one JSON request on stdin. It has no imports of engine, GUI, battle_runtime, or battles. `simulate(request)` is the direct deterministic entrypoint for offline tests. Results return as soon as computation ends, without sleeping for the modeled battle duration. Orchestration owns any cancellable wait before a future reviewed live route. ### Explicit experimental eligibility (latest integration contract) `settlement_eligible=False` and `faithful=False` always refer to original engine fidelity. After an actual supported model completes (including a natural loss), `experimental_settlement_eligible=True` only when `battle_data` was computed and there are no unresolved inputs or detected anomalies. Otherwise `experimental_eligibility_reasons` gives the reason and the flag is false. Inspection and technical timeout/cancel/error never assert experimental eligibility. Known approximate mechanics remain disclosed even when eligible; this does **not** claim that original cheat checks ran or were complete. Integration must use the experimental flag only under the explicitly selected `policy.battle_mode='experimental'`, never the native route. Production integration and the real-time wait remain owned by orchestration; this module does not start or settle any live battle. ## Original inputs and reproducible static data The builder uses `tools.research_battle_v12.recover_table` with the repaired AMF Reader (empty arrays remain `[]`). It rejects any APK whose SHA-256 is not `01678ee3a8465d818d32cbbd94baa0d8253b04b4c57b70ebc5544ed341f1015d`. The retained main SWF SHA-256 is `c6838331a198a22ffa486cbf61cc74c97619e011bc3364c8bb8dc99e269036cf`. The SWF header independently decodes to **50.0 fps**; the fixed model clock therefore advances 20 ms per tick. ```powershell python tools/build_battle_simulation_data.py python tools/build_battle_simulation_data.py --output local_state/battle_simulator/rebuild ``` Both builds were run; the two gzip artifacts and manifest matched byte for byte. Gzip has a fixed zero timestamp, JSON is sorted and compact, and the manifest retains per-table original compressed-member digests, logical names, decoded sizes, APK identity, and 196 attack profiles' retained AS3 source hashes. No personal path or account data enters these artifacts. | Artifact | Bytes | Contents | | --- | ---: | --- | | `combat_tables.json.gz` | 242,430 | 749 species, 266 skill definitions, original numeric/settings/team/potential/entangle/upstar/item tables, default fields, 196 attack profiles | | `combat_battles.json.gz` | 1,465,404 | All 1,178 original stage records' level configs and 1,165 tasks' combat/status steps | | `combat_manifest.json` | manifest | Original source and artifact digests and retained-source fingerprints | The runtime validates identity and compressed/decoded artifact hashes, then freezes dictionaries and arrays recursively. The independent cache does not use Catalog. Normal workers never decode the roughly 62 MB full battle corpus; they receive one original battle config and read the small combat bundle. `combat_battles()` is a lazy public-static research helper. Neither runtime method imports the builder, opens the APK, or contacts the network. ## Implemented trajectory Player HP/ATK/DEF/DEX follow `MonsterVo`: ```text int((base + actualGrowth * (level + min(tpLevel, 4) - 1) + monsterAttributes[stat] + pStat + master.globalStat) * (1 + clamp(feel, 0, 200) / 2000 + game_setting.upStarAdd * upStar)) ``` Growth comes from the raw monster, never a generic Fighter or midpoint player. Potential uses actual `pAtk/pDef/pHp/pDex`. Server `monsterAttributes` supplies the aggregate bonuses once; equipment is not added again. Attack interval is the species interval plus source integer dex adjustment and `atkSpd`; movement uses species speed plus the source two-decimal dex adjustment. Crit and AP cost saving come from the same server attributes. Upstar skill replacements and breakthrough-derived skill levels use the original tables. Missing growth or a nonpositive computed attack interval is rejected, not replaced or clamped. Configured enemies retain their individual authored values. `autoValue` uses the source species midpoint construction, level and global additions. Only authored `scaleAbility`/`scaleHp` fields change configured enemy numbers; they are not user-selectable damage cheats. Normal stage/task combat does not apply the unrelated PvP `pveHpScale` or `pveApStartScale`. Teams preserve the selected snapshot team order and original position mapping `1,4,2,5,6,7,8`. Player field capacity follows unlocked `team_info.battleTeam` slots, capped at four. Enemy capacity comes from original `numMax`. Deployment uses original spawn rectangles, `joinTime` in seconds, and per-team waves. Wave unlock waits 700 ms; scheduled reinforcements are admitted on the source one-second deployment cadence. `hideTeamMon` removes roster combatants and allows authored allies. Summons do not consume field capacity. Player AP starts at `startAp + (master.level-1)*addApByLevel`. Enemy AP starts at authored `ap` with max `2*ap`. The clock recovers one AP per original `apCD=2000` ms; delayed roster joins restore the original fraction of max AP. Automatic deployment has **no invented AP charge**: source `prepareTimeMonster` checks time/wave/capacity, not cost. AP is spent on actual skill casts. Position-command AP spending is outside this automatic model. The model selects spatial targets, moves toward them, tests the source attack box (`abs(dx)