docs: the damage reward, and the v7 migration in deploy examples
rewards-learning: the catalog row, "Damage rewards" (what counts as the fly's attack, the magnitudes against the catalog, what cannot be farmed, why `damage` has no feed counter, the measured press-to-payout delay against the 5 s trace, the migration) and an honesty paragraph. flysim.md: v7 -> v8 under "Restoring across an adapter version", with the exact compatibility-string change. macros-wram: hWhoseTurn, wPlayerMoveNum, wEnemyMonPartyPos and the stale wEnemyMon. Deploy examples name pokered-unique8-v7 (example.env: add v6 to keep the pre-v0.6.0 milestone archives restorable).
This commit is contained in:
parent
3914f824ce
commit
e9d8f1a753
8 changed files with 138 additions and 13 deletions
|
|
@ -89,8 +89,9 @@ decoder preset to use.
|
|||
disassembly at commit 0cd19d3 (`symbols.rs`), gates rewards on a playable state, baselines already
|
||||
achieved flags on the first sample so a restore never replays them, and pays only positive
|
||||
rewards: story flags, exploration coverage (capped per map), new areas, Pokédex entries, trainer
|
||||
flags, decaying wild wins, badges, exits found outdoors, catches, conversations indoors and items
|
||||
picked up (`docs/rewards-learning.md`). Version `pokered-unique8-v7`; a deploy that names the
|
||||
flags, decaying wild wins, badges, exits found outdoors, catches, conversations indoors, items
|
||||
picked up and the HP the fly's own attacks remove in battle (`docs/rewards-learning.md`).
|
||||
Version `pokered-unique8-v8`; a deploy that names the
|
||||
previous version in `FLY_ACCEPT_ADAPTERS` migrates its checkpoints instead of refusing them.
|
||||
- Ratchet (`ratchet.rs`): a 38-rung ladder (boot, bedroom, Pallet Town, Oak's lab, starter, parcel,
|
||||
Pokédex, each town, each badge, the Elite Four, Champion). On first reaching a higher rung in a
|
||||
|
|
|
|||
|
|
@ -398,6 +398,19 @@ on-screen ticker cannot disagree with what the sim did.
|
|||
slot from before a `v6`-era pickup cannot pay for it (`docs/rewards-learning.md`, "The seed").
|
||||
`STATE_VERSION` stays 4.
|
||||
|
||||
**`v7` -> `v8`** (2026-09-29, the damage reward). `pokered-unique8-v8`'s `migrates_from()` is
|
||||
`["pokered-unique8-v7", "pokered-unique8-v6"]`: the live run is `v7`, and `v6` still composes,
|
||||
because `v7`'s own step (the item seed on the first sample without `items:seeded`) is still in
|
||||
this build and the damage state starts empty either way. The deploy that ships it sets
|
||||
`FLY_ACCEPT_ADAPTERS=pokered-unique8-v7`; naming `v7` does not admit a `v6` checkpoint, which
|
||||
needs its own id. One optional field is added, `damageCounts` (the wild keys that have paid
|
||||
damage), and one optional object inside a battle in flight, `battle.damage` (the per-battle
|
||||
marks and what the battle has paid). A `v7` state has neither and restores with no wild key paid
|
||||
and, if the checkpoint was taken mid-battle, every enemy Pokémon marked at the HP it has when
|
||||
first read, so nothing it lost before the restore is paid. `STATE_VERSION` stays 4. The
|
||||
compatibility string moves in segment 1 only: `.../pokered-unique8-v7/...` becomes
|
||||
`.../pokered-unique8-v8/...`, every other segment byte-identical.
|
||||
|
||||
- **Restarting a run from an earlier rung** (2026-09-22). `FLY_RESET_STATE=1` throws the run away;
|
||||
`infra/bin/fly-reset-to-milestone <N>` keeps it and rewinds it. It archives both stores to a
|
||||
dated directory, rewrites `milestone-<N>.checkpoint` with the ratchet's `attempts` and
|
||||
|
|
|
|||
|
|
@ -155,6 +155,21 @@ which neither `gen_symbols.py` nor `resolve_wram.py` resolves, and a hand-writte
|
|||
thing those tools exist to refuse. "The fly had the joypad and was standing still on the frame
|
||||
before the box opened, and the box is about the thing it faces" is the same fact read out of WRAM.
|
||||
|
||||
### The damage reward's reads (2026-09-29)
|
||||
|
||||
**New 2026-09-29** (`damage`, `docs/rewards-learning.md`, "Damage rewards"). The two WRAM names were
|
||||
resolved by `services/flysim/tools/resolve_wram.py` from `ram/wram.asm` at the pinned commit and
|
||||
are bracketed by addresses `symbols.rs` already carried. The HRAM byte is the second hand-counted
|
||||
HRAM address in the crate, after row 63's `hJoyLast`, and is held to the same standard: counted
|
||||
from that pinned anchor and checked against the section's end, then pinned on the cartridge.
|
||||
|
||||
| what | symbol | address | notes | verified |
|
||||
| --- | --- | --- | --- | --- |
|
||||
| whose side is acting | `hWhoseTurn` | `$FFF3` | "0 on player's turn, 1 on enemy's turn" (`ram/hram.asm`). Counted from `hJoyLast` (`$FFB1`) with each `UNION` at its largest member; the nine bytes after it end at `$FFFE`, the end of HRAM. `ExecutePlayerMove` writes 0 before the fly's move and `MainInBattleLoop` 1 before the enemy's; `HandlePoisonBurnLeechSeed` picks whose HP to cut by it. MEM-01's memory image captures HRAM, so the session runtime reads the same byte. | survey (`tests/rom_damage.rs`, the row 67 state: every enemy HP drop with 0, every own HP drop with 1) |
|
||||
| the move executing | `wPlayerMoveNum` | `$cfd2` | the first of the six move bytes `ExecutePlayerMove` loads; `STRUGGLE` (`$a5`) for a Pokémon with no PP. Bracketed by `wWalkCounter` and `wEnemyMonSpecies`. | survey (BUBBLE `$91` and TACKLE `$21` read on the frames their hits landed) |
|
||||
| which enemy slot is out | `wEnemyMonPartyPos` | `$cfe8` | `battle_struct`'s third field (`macros/ram.asm`: Species, HP, PartyPos, aliasing BoxLevel); `$ff` until a trainer's first send-out, then the 0-based party slot. Bracketed by `wEnemyMonHP` and `wEnemyMonStatus`. | trace (`pokemon_red/tests.rs`), survey |
|
||||
| (stale) the enemy | `wEnemyMonSpecies` ... `wEnemyMonMaxHP` | as above | **not cleared between battles**: `InitBattleVariables` leaves `wEnemyMon` alone, and a trainer battle sets `wIsInBattle` a whole transition before `LoadEnemyMonData`. The first samples of a battle can hold the last battle's Pokémon at the HP it finished on; the damage rule marks a target only once it reads full. | disassembly, trace |
|
||||
|
||||
### Battle menu and cursor, own turn against forced switch
|
||||
|
||||
`HandleMenuInput` is shared by every menu in the game, so which menu is up is read from where it
|
||||
|
|
|
|||
|
|
@ -178,8 +178,9 @@ achievements.
|
|||
| Badge | +3 | each newly set badge bit |
|
||||
|
||||
That is the prototype's catalog as it shipped, kept here as history. The live one is
|
||||
`docs/rewards-learning.md`: `pokered-unique8-v7` adds `boundary` (v5), `catch` (v6), and `talk` and
|
||||
`item` with no `boundary` payout indoors (v7, the operator's decision of 2026-09-23).
|
||||
`docs/rewards-learning.md`: `pokered-unique8-v8` adds `boundary` (v5), `catch` (v6), `talk` and
|
||||
`item` with no `boundary` payout indoors (v7, the operator's decision of 2026-09-23), and `damage`
|
||||
(v8, the operator's decision of 2026-09-29).
|
||||
|
||||
Every value is positive; there were no loss or blackout penalties. Values in a frame summed into
|
||||
`R`, then `m = tanh(R)`. PAM stimulation ran 80 to 400 ms depending on reward kind, with
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
# Rewards and learning
|
||||
|
||||
The live reward catalog of the Pokémon Red adapter, `pokered-unique8-v7`. The code of record is
|
||||
The live reward catalog of the Pokémon Red adapter, `pokered-unique8-v8`. The code of record is
|
||||
`services/flysim/crates/flybrain-gb/src/pokemon_red/` (`catalog.rs` holds the values, `mod.rs` the
|
||||
gates and the rules); this page says what each rule pays for and why it is allowed to. The
|
||||
prototype's own `docs/rewards-learning.md` in `fly-plays-pokemon` is where the first seven rules
|
||||
|
|
@ -27,6 +27,7 @@ change what the fly can do.
|
|||
| `catch` | `wildwin` | +0.30, +0.10 | 150 ms | A wild Pokémon kept by a ball: +0.30 for a species this run had never owned, +0.10 for a repeat; at most three payouts per species for the lifetime of the ledger |
|
||||
| `talk` | `explore` | +0.10 | 100 ms | A conversation the fly opened with a person or a sign **indoors**, paid when its box closes; once per `(map, sprite slot or sign text id)` for the lifetime of the ledger |
|
||||
| `item` | `explore` | +0.15 | 120 ms | An item ball or a hidden item picked up, on any map; once per item for the lifetime of the ledger |
|
||||
| `damage` | -- | +0.20 per whole Pokémon, in proportion; +0.05 knockout | 80 ms | HP the fly's own attack removed from the enemy (since v8): its share of the target's max HP, below the lowest HP that target has shown this battle; +0.05 when the hit knocks out a trainer's Pokémon; at most 0.50 a battle; a wild battle at 1, 1/2, 1/3 for its first three per `(map, species, level)`, then nothing |
|
||||
|
||||
Every value is positive: there are no loss or blackout penalties, and `catalog::rule("blackout")`
|
||||
is `None` by test. The values in one frame sum into `R`, and the network reinforces once with
|
||||
|
|
@ -34,7 +35,8 @@ is `None` by test. The values in one frame sum into `R`, and the network reinfor
|
|||
|
||||
The feed-kind column is `RewardKind::from_adapter` in `services/flysim/crates/flysim/src/snapshot.rs`:
|
||||
`docs/feed-protocol.md` publishes seven counters, and an adapter kind that has no counter of its
|
||||
own shares the nearest one. It still reaches the page as an event with its own label.
|
||||
own shares the nearest one. It still reaches the page as an event with its own label. `damage` is
|
||||
the one Pokémon kind with no counter at all ("Damage rewards" below says why).
|
||||
|
||||
Two consequences of that sharing are worth stating rather than discovering. `catch` publishes on
|
||||
`wildwin` because a catch is a wild battle the fly won by keeping the Pokémon, and *not* on
|
||||
|
|
@ -177,6 +179,85 @@ half, 0.10, once, keyed under the building's id as it always was; walking out pa
|
|||
person, far below a badge. Everything is once per thing for the lifetime of the ledger, so no
|
||||
building can be farmed.
|
||||
|
||||
## Damage rewards
|
||||
|
||||
The operator's decision of 2026-09-29, chosen over a pad rule that would have withheld a stat move
|
||||
once it had been used: pay the fly for the HP its own attack removes from the Pokémon it is
|
||||
fighting. It is a catalog change, an operator decision like the catch and engagement rewards, not a
|
||||
loop-review fix. It answers row 67 (`infra/docs/macros-traps.md`): the live fly lost the Pewter
|
||||
Gym's Jr. Trainer 29 times running, choosing TAIL WHIP 155 times, BUBBLE 23 and TACKLE 0, and
|
||||
nothing in the catalog paid for anything that happened inside a battle it did not win. The pad
|
||||
offered every move; the readout's favourite was the one move that cannot win. The code is
|
||||
`pokemon_red/damage.rs`.
|
||||
|
||||
**What counts as the fly's attack.** A drop in `wEnemyMonHP` on a sample where `hWhoseTurn`
|
||||
(`$FFF3`) reads 0 and `wPlayerMoveNum` is not `STRUGGLE`. At the pinned commit
|
||||
(`engine/battle/core.asm`), `ApplyDamageToEnemyPokemon` subtracts the damage inside
|
||||
`ExecutePlayerMove`, with `hWhoseTurn` 0, once per hit of a multi-hit move. Everything else that
|
||||
lowers the enemy's HP lands with it 1: the enemy's poison and burn ticks and a Leech Seed on the
|
||||
enemy (`HandlePoisonBurnLeechSeed` picks whose HP to cut *by* `hWhoseTurn`), its recoil, its
|
||||
confusion self-hit, its own Explosion or Self-Destruct, and the HP it pays for a Substitute. A
|
||||
Leech Seed on the fly heals the enemy, and HP going up never pays. Damage into an enemy Substitute
|
||||
never touches `wEnemyMonHP`. `STRUGGLE` is the move the cartridge executes for a Pokémon with no
|
||||
PP; the fly chose FIGHT, not the move, so it pays nothing (winning still pays what winning pays).
|
||||
`tests/rom_damage.rs` pins the address on the cartridge from the live row 67 state: every drop of
|
||||
the enemy's HP lands with `hWhoseTurn` 0 and every drop of the fly's own with 1.
|
||||
|
||||
**How much.** 0.20 per whole enemy Pokémon's max HP, paid in proportion on the sample the HP
|
||||
drops -- BUBBLE for 10 of Diglett's 24 is 0.083, TACKLE for 4 of Sandshrew's 33 is 0.024. The hit
|
||||
that knocks out a trainer's Pokémon adds 0.05 on the same event. At most **0.50 a battle**, which is
|
||||
the `trainer` rule's own value: a battle's worth of damage is worth what winning it is, and the
|
||||
Jr. Trainer's two Pokémon reach it exactly (2 x (0.20 + 0.05)). A wild knockout adds nothing here
|
||||
because the `battle` rule already pays it, on the way out of the battle. Next to the rest of the
|
||||
catalog: a wild battle's damage (0.20) is twice its knockout (0.10) and equal to a new area (0.20);
|
||||
a trainer battle's (0.50) is the trainer's flag; a gym's is a sixth of the badge (3.0).
|
||||
|
||||
**What cannot be farmed.**
|
||||
|
||||
- *Heal.* Each target keeps the lowest HP it has shown this battle, and only HP below that pays. A
|
||||
Potion, Recover, Rest or a drain lifts the HP; the same HP is not paid twice.
|
||||
- *Switch.* A target is `(wEnemyMonPartyPos, species, level)`, so a trainer's Pokémon that goes out
|
||||
and comes back keeps its mark, and two Weedles of one level are two targets.
|
||||
- *A stale enemy.* `InitBattleVariables` does not clear `wEnemyMon`, and a trainer battle sets
|
||||
`wIsInBattle` a whole transition before `LoadEnemyMonData` runs, so the first samples of a
|
||||
battle can hold the last battle's Pokémon at the HP it finished on -- in the row 67 ring, the
|
||||
same trainer's Diglett in the same slot. A target is marked the first time it reads full HP,
|
||||
which is how every enemy Pokémon enters a battle in this game, so the stale one neither pays nor
|
||||
hides the real one's first hit.
|
||||
- *The battle.* 0.50 at most, whatever the party size.
|
||||
- *Wild Pokémon.* A wild battle pays at the wild-KO rule's scale, 1, 1/2, 1/3, for its first three
|
||||
battles per `(map, species, level)` that paid any damage (`damageCounts`), then nothing; attacking
|
||||
a wild Pokémon and running from it counts. A rollback blocks every key that has paid, the way it
|
||||
blocks a paid wild KO or catch.
|
||||
- *Trainers* keep no lifetime ledger. A trainer is fought again only after the fly has lost to it
|
||||
(or after a rollback), and each of those battles is bounded by the cap. In the row 67 ring that
|
||||
is the point: every lost battle pays for the hits that landed, and the hits that land are the
|
||||
moves that win.
|
||||
|
||||
**Feed.** `damage` publishes on no counter (`RewardKind::from_adapter` is `None`). Every other
|
||||
Pokémon kind shares the nearest counter, and the nearest here is `wildwin`, but the stage folds
|
||||
that row into "N wild wins": false of a trainer battle, and false of a battle the fly goes on to
|
||||
lose. A hit reaches the page as a reward event with its own label, `HIT #<species> FOR <n> HP`
|
||||
(`... KO` for a knockout; the species is the cartridge's internal index, as `CAUGHT #<species>` is),
|
||||
and the event log, `/status` and the checkpoint carry it; it is only left out of
|
||||
`game.rewardCounts` and the ticker's per-kind copy, the way the platformer's `started` and `clear`
|
||||
are. No feed kind was added. One visible consequence the operator should review on a PNG before
|
||||
release: those rows are not folded, so a battle adds one ticker row per hit.
|
||||
|
||||
**Learning.** A payout reinforces the recent spike history with `m = tanh(R)` over a 5 s
|
||||
eligibility trace ([plasticity](plasticity.md)). Measured on the cartridge from the row 67 state
|
||||
(`tests/rom_damage.rs`), the HP drops 176 frames (2.9 s) after the `MOVE n` press when the fly
|
||||
moves first and about 420 frames (7 s) when the Jr. Trainer's Pokémon does -- its attack and text
|
||||
come first. So the choice's trace is at a half to a quarter when its hit is paid, and the previous
|
||||
turn's choice, one turn (about 7.5 s) earlier still, at a tenth to a twentieth. That ratio is the
|
||||
whole mechanism: nothing tells the readout which move to press. A hit is small (0.02 to 0.10), so what it can move per battle is small too; whether
|
||||
the brain learns the attacking move inside a few brain hours is a measurement, not a promise, and
|
||||
the first one is `infra/docs/macros-traps.md`, row 68.
|
||||
|
||||
**Migration.** `v7` -> `v8` adds `damageCounts` and, inside a battle in flight, `battle.damage`;
|
||||
both are optional and a `v7` state restores with no wild key paid and its battle's Pokémon marked
|
||||
where they stand. See `docs/design/flysim.md`, "Restoring across an adapter version".
|
||||
|
||||
## Gates
|
||||
|
||||
Semantic rewards are enabled for exactly one cartridge, the SHA-256 in `SUPPORTED_ROM`. Any other
|
||||
|
|
@ -276,6 +357,15 @@ body picks the macro; the descending neurons press the buttons.**
|
|||
|
||||
## Honesty
|
||||
|
||||
The catalog now includes damage (v8). It is the first rule that pays for something inside a battle
|
||||
the fly may still lose, and the closest the catalog has come to grading a *choice*: the moves are
|
||||
all on the pad, and the one that lands pays. It is still a reward read out of WRAM after the frame,
|
||||
not a press: nothing in the adapter picks a move, removes one from the pad or tells the readout
|
||||
which is good, and a move pays only if the cartridge says it took HP off the enemy. The pad rule
|
||||
the operator declined (withholding a stat move once used) would have been the doctrine change; this
|
||||
one leaves the pad exactly as the scene deals it. It is also bounded on purpose: at most what winning
|
||||
pays, per battle, and a wild Pokémon only three times.
|
||||
|
||||
The catalog now includes conversations and items (v7). Paying for a conversation is the closest
|
||||
the catalog has come to paying for a *button*: A is what opens one. It is still a reward, not a
|
||||
press. Nothing in the adapter presses A, chooses when, or tells the fly who is there; the payout is
|
||||
|
|
|
|||
|
|
@ -322,8 +322,9 @@ if [ -n "$RELEASE_TARBALL" ]; then
|
|||
#
|
||||
# FLY_ACCEPT_ADAPTERS is the *other* override, and the opposite one: it keeps
|
||||
# the run. It names adapter version strings whose checkpoints the new build
|
||||
# may migrate — e.g. FLY_ACCEPT_ADAPTERS=pokered-unique8-v6 for the deploy
|
||||
# that adds the engagement rewards (v7; v5 -> v6 was the catch reward's).
|
||||
# may migrate — e.g. FLY_ACCEPT_ADAPTERS=pokered-unique8-v7 for the deploy
|
||||
# that adds the damage reward (v8; v6 -> v7 was the engagement rewards', v5 -> v6
|
||||
# the catch reward's).
|
||||
# It only applies when the adapter segment is the
|
||||
# ONLY difference between the two strings and the new build's adapter says it
|
||||
# can read that one; a dataset, kernel, emulator or state-format change is
|
||||
|
|
@ -377,7 +378,7 @@ The difference is usually an adapter/ladder or dataset version bump. Three ways
|
|||
* deploy a build whose string matches (check out the commit the running release was built from), or
|
||||
* if the ADAPTER VERSION is the only segment that differs and the new build documents a
|
||||
migration from the old one, re-run with FLY_ACCEPT_ADAPTERS set to the adapter id in the live
|
||||
string (e.g. FLY_ACCEPT_ADAPTERS=pokered-unique8-v6). The run is kept; flysim applies the same
|
||||
string (e.g. FLY_ACCEPT_ADAPTERS=pokered-unique8-v7). The run is kept; flysim applies the same
|
||||
rule at restore. See docs/design/flysim.md, \"Restoring across an adapter version\", or
|
||||
* accept losing everything the brain has learned and re-run with FLY_RESET_STATE=1, which
|
||||
archives ${state_dir}'s checkpoints to ${state_dir}.<timestamp> (kept, not deleted) and
|
||||
|
|
|
|||
|
|
@ -282,7 +282,7 @@ pct exec $CTID -- /opt/fly/bin/fly-reset-to-milestone $N
|
|||
# (a) the running release already wrote that checkpoint -> nothing to deploy, skip to 5.
|
||||
# (b) the new build bumps the ADAPTER VERSION and nothing else -> name the checkpoint's
|
||||
# adapter so the gate and flysim both migrate instead of refusing:
|
||||
FLY_ACCEPT_ADAPTERS=pokered-unique8-v6 infra/05-deploy.sh <release-env> <release-tarball>
|
||||
FLY_ACCEPT_ADAPTERS=pokered-unique8-v7 infra/05-deploy.sh <release-env> <release-tarball>
|
||||
# The gate logs "the adapter version is the only difference, and it is named; the run is KEPT
|
||||
# and migrated", and writes FLY_ACCEPT_ADAPTERS into /etc/fly/fly.env so flysim applies the
|
||||
# same rule at restore. Anything else about the string differing is still a refusal.
|
||||
|
|
|
|||
10
infra/env/example.env
vendored
10
infra/env/example.env
vendored
|
|
@ -340,9 +340,13 @@ FLY_FEED_VIA=direct
|
|||
# two strings AND the new build's adapter declares a migration from that one. A
|
||||
# dataset, kernel, plasticity, emulator or state-format difference is still a
|
||||
# refusal. Set it for the one deploy that needs it and leave it out afterwards;
|
||||
# 05-deploy writes it into /etc/fly/fly.env only while it is set. The v0.6.0
|
||||
# deploy (pokered-unique8-v7, the engagement rewards) is the one that needs:
|
||||
# FLY_ACCEPT_ADAPTERS=pokered-unique8-v6
|
||||
# 05-deploy writes it into /etc/fly/fly.env only while it is set. The deploy
|
||||
# of pokered-unique8-v8 (the damage reward) over the live v7 run needs:
|
||||
# FLY_ACCEPT_ADAPTERS=pokered-unique8-v7
|
||||
# and, to keep the milestone archives written before v0.6.0 restorable as
|
||||
# fallbacks and fly-reset-to-milestone targets, also names v6 (v8 reads both):
|
||||
# FLY_ACCEPT_ADAPTERS=pokered-unique8-v7,pokered-unique8-v6
|
||||
# (v0.6.0's, pokered-unique8-v7 over v6, needed pokered-unique8-v6.)
|
||||
|
||||
# --- push mode --------------------------------------------------------------
|
||||
# local: flypush.service stays disabled, everything else identical to prod.
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue