Repository navigation
feat(farming-analyzer): model encounters, combat styles and map difficulty - #35
Merged
Merged
Conversation
…culty Safety saturated at 1.0 on every Burnt Forest circuit because the direct aggro pack of spread-out spawns is one, so the playtester kept choosing maps where packs of three to eight formed from wanderers, chases and retreats. Add an encounter model per map. It reads spawn positions, aggression, detection and engaged radius, chase range, ally calls by Int and spawn-point title, random_move wanderers and their limits, casters with spell damage types, archers, and terrain: walkable regions, kite room, open fields, doorways, corridors and seams, including spawns on tiled neighbours. It estimates the expected and bad-pull attackers from the best pull squares in an easiest-first clear, and the health trough of each pull on an arrival-aware timeline against the character's healing. --combat-style (melee, melee-pack, ranged-kite, aoe-kite) with --healing-per-second and --kite-distance makes that style-aware safety part of safety_score. Without it, existing outputs are unchanged and the new fields are reported; JSON gains schema_version 2. Add a `report` subcommand with a documented JSON schema for map makers and the Tilewright editor: per-map and per-zone difficulty by level band and style, hotspots and the reasons behind each rating. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Dependency Review✅ No vulnerabilities or license issues found.Scanned FilesNone |
A target the character cannot hurt has an infinite kill time, which overflowed the wanderer spread and stopped the whole scan whenever an aggressive wanderer was near. Such pulls now use a finite horizon for spreads, calls and arrivals and are reported as not farmable. Kiting uptime ignored pack size, so huge slow packs rated perfectly safe. Each attacker beyond the first now closes one of eight escape directions, and the player-speed default is an explicit, documented assumption. Match the server more closely: slow_move halves only idle speed, called passive monsters fight, and directly placed monsters neither call nor answer; the alliance-parent and sleep deviations are documented. Circuits take all pull and safety fields from one member, seams without crossable tiles are omitted, and missing living.c or spellist.h warns instead of silently degrading. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Once a pack pinned a kiter, the stepping-away penalty still lengthened every kill, so nine or more slow attackers cost a kiter more than a melee character. The penalty now shrinks with the open escape directions, and each kiting pull also costs the same pack standing and fighting and takes the cheaper of the two. An unkillable monster that is passive or deals no damage is now left alone instead of making the whole map lethal. The README states the CI gap as deferred scope and the report's map list as attackable spawn-point monsters, passive ones included. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An AoE attack damages every monster in its footprint, and a damaged monster turns on its attacker, so under aoe-kite a passive monster inside the footprint joins the pull. An unkillable passive monster that deals damage is therefore not left alone for AoE styles; only one that deals no damage is. Document the accepted limits of the kite-or-stand comparison: it holds within one pull, not across styles with different bad pulls, and the standing alternative reuses the kiting timeline. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Member
Author
|
Self-review of origin/main..401c137: 7b77dc9, 0de0144, bbc87e0 and 401c137. Reviewed:
Findings on 7b77dc9, fixed in 0de0144:
Findings on 0de0144, fixed in bbc87e0:
Findings on bbc87e0, fixed in 401c137:
Accepted and declined:
Checks at 401c137:
Playtester follow-up (separate PR):
|
zoeyrose
marked this pull request as ready for review
November 25, 2026 23:29
zoeyrose
added a commit
to atrinik/playtester
that referenced
this pull request
Nov 26, 2026
…#140) ## Summary On 2026-11-25 Sera died four times in the Burnt Forest. Every spot there rated safety 1.0 and direct pack 1. This PR locks the farming analyzer v3.11.0 (https://github.com/atrinik/tools/releases/tag/v3.11.0, from atrinik/tools#35) and runs its encounter model on her real style, healing and speed. The owner decided to **keep the XP choice and warn only**. That was shown with what ranking by the model would cost: her estimated XP falling from 6.1 M to 0.76 M an hour. Her spot ranking, safety, risky floor, the pack cap from #130 and the seam-exposure adjustment are all identical to main's. **Lock** - `farming_analyzer` moves to v3.11.0 (commit `594c759`, `sha256:650ad637…`). - `classic_server.required_paths` gains `src/server/living.c`, `src/include/spellist.h` and `src/include/config.h`. The analyzer reads these for ally calls, caster damage types and server constants. The locked v5.99.0 server archive already contains them. - THIRD_PARTY_NOTICES and the README install line are updated. `preflight` verifies the release on GitHub. **Two runs, and why** With `--combat-style`, v3.11.0 lowers `spot_safety_score` to min(old estimate, encounter safety). `safety_score`, the balanced and safety scores, and those views' order follow it, and the old estimate is not reported separately. So the ranking and the encounter model run separately. - **Ranking run.** She chooses by this run. It passes no style, and it re-runs only when main would: `materially_differs` (which no longer includes style or healing), a savebed change, or 6 h. It also passes `--healing-per-second`, which feeds only the encounter model. - **Encounter run** (`_run_encounters`: its own task and process; her ranking never waits for it). It passes: - `--combat-style`: `melee` with her weapon; `ranged-kite` while Wizardry trains with spells only, mirroring `FarmTask.spell_only_training`; - `--healing-per-second`, measured: the median of her landed heal-spell casts (potions and scrolls excluded), over a swing plus a 1 s cast (the cadence from #128), capped by SP regeneration at her cheapest heal's cost. This is documented as an upper bound. Her live heals have a median of 12 HP, so she passes 3 HP/s; - `--character-speed`; - `--top 5000`, so every ranked candidate gets a rating. - **When the encounter run runs.** Not until a heal has landed. With 0 HP/s every pull would rate as unhealed and nearly every spot would warn. After that it runs for each new ranking, and at most every 10 min for a new style or a 15% healing change; neither re-runs the ranking. A failed run keeps the ranking, shows on the Farming tab, and is retried after 15 min. A ranking that falls due first kills a running encounter run, so the two never share the host's cores. A result that outlives its ranking attaches nothing. - **Merge.** Encounter fields attach to spots with the same path and map paths, because a circuit's path names only basenames. An identity the run rates two ways is skipped rather than mis-attached. Only schema-2 reports with `encounter_applied` are read. **Warn only** - `farm-spot-selected` is unchanged from main. - Whenever her spot's rating changes, the farm circuit records a `farm-spot-encounter` decision with the style, encounter safety, expected and bad-pull packs, and the first three `encounter_reasons`. That covers the spot it starts on, a switch, and a re-rated spot. A spot left unrated keeps what was noted for it. - If the spot's `encounter_safety` is below 0.8 or its `worst_pack` is above 6, she also records a `farm-spot-encounter-warning`, and the warning is kept on the client together with its circuit. - The dashboard's `farm-encounter` warning alert reads that state, and only while autoplay's child is that circuit. So it ends when autoplay farms another circuit, leaves farming or stops, and it does not depend on the 2,000-entry decision history. - The Farming tab adds an "Encounters" line per spot, flagged when it warns, with every reason in its tooltip. The thresholds are documented in COMBAT.md, "Encounter warnings". **Real-content check** (her live state, locked bundle, the real world graph, through `FarmAnalyzer._run` and `analyzer_farm_selection`) - Every view's old fields and order are identical between this branch's ranking run and main's invocation (no style, no healing). - Measured: the ranking run takes 26.5 s and the encounter run 26.4 s on this machine. - She farms the same spot as main: `circuit[world_16_72 + world_17_72 + world_17_73 + world_18_73]`, at 6.3 M XP/h. - It now carries the warning: "encounter safety 0.33 < 0.8, bad pull 8 > 6", with `world_17_72`'s reasons. ## Tests - Full suite: `run_tests_parallel.py --workers 12` ran 1414 of 1414 OK (after merging origin/main d8cd223). - CTest 3/3 passed. compileall, py_compile and `git diff --check` are clean. - `doctor` passes against a bundle installed offline from the new lock. `preflight` passes; its first attempt reported a transient `lock-availability` error and the rerun passed. - New or changed tests: - `AnalyzerFarmSelectionTests.test_spot_choice_is_unchanged_by_encounter_fields`: with schema-2 data present, the pick and the seam ranking equal those for the same spots without encounter fields, for any-pack, cap-2 and cap-1 kits, and seam exposure folds in as before. - `AnalyzerFarmSelectionTests.test_the_selected_spot_records_its_encounter_reasons_and_warning`: the warning decision and alert appear for a dense spot (worst_pack 9, encounter safety 0.79) and not for a sparse one, and `farm-spot-selected` keeps main's text. The alert ends once autoplay's child is another circuit or none, and survives a cleared decision history. - `AnalyzerFarmSelectionTests.test_the_spot_she_starts_on_is_warned_about_and_re_rated` covers: - the spot a circuit is created on; - no re-record while unchanged; - re-rated safe, then dangerous; - unrated after a failed run; - a new circuit on a safe spot. - `FarmAnalyzerTests.test_the_analyzer_runs_with_her_style_healing_and_speed` checks that: - the ranking run comes alone and has no style, and her ranked fields stay pre-encounter. The fake analyzer lowers them under a style, as v3.11.0 does; - the encounter run's arguments carry `--combat-style melee`, `--healing-per-second 5.1`, `--character-speed 0.8` and `--top 5000`; - a hung encounter run doesn't hold up her ranking; - a ranking that falls due cancels the hung run, attaches nothing, and leaves a fresh encounter run due; - an encounter run that outlives its ranking attaches nothing (this catches the mutant without the generation check); - a healing change re-runs only the encounter run, onto the same ranking report; - a failed encounter run is retried after the backoff; - no encounter run happens before a heal has landed; - healing and style never count as `materially_differs`. - `FarmAnalyzerTests.test_encounter_ratings_attach_only_to_the_same_spot`: two circuits sharing a basename path get their own ratings, and an identity rated two ways is skipped. - `FarmAnalyzerTests.test_encounter_fields_are_read_only_from_a_schema_2_report`: schema gating, the summary and warning text, and the thresholds. - The two Wizardry tests now assert her style. - The `test_compatibility` lock tests cover the new release, digest and required paths. - **Against the previous head aeebdfd's code:** - `test_encounter_ratings_attach_only_to_the_same_spot` fails (path-only keying gave both circuits one rating); - both alert tests fail (no circuit-bound warning state); - `test_the_analyzer_runs_with_her_style_healing_and_speed` hangs past a 200 s limit (its ranking waited for the hung encounter run). - **Against main's code** all of these fail. The choice-equivalence part of `test_spot_choice_is_unchanged_by_encounter_fields` would pass on main by design; it is a guard, and it fails there only on the new `encounter_warning` import. Against this PR's previous head (e73cdf1), which demoted and capped dense spots, its choice assertions would fail. ## Review - **Previous design.** Independent reviews of fc3d68c and aec74c5 found no P1s. Their fixes still apply here: heal attribution reads the whole time window, the heal and hit text is stripped, the style mirrors `spell_only_training`, and the dashboard guards `encounter_reasons`. - **Warn-only rework.** An independent review of a9f0986 confirmed that her choice is unchanged: `risky_spot`, `spot_safety`, `seam_adjusted` and `seam_ranking` are byte-identical to main, and `--healing-per-second` without a style feeds only the encounter fields. It found one P1, fixed in 5f9b1e8: the warning never fired for the spot autoplay starts a circuit on. Also fixed there: re-rated spots, the encounter-run retry and its error line, Python-driven dashboard flags, and `arguments()` defaulting to unstyled. - **Declined from that review:** - path keying across directories with the same basenames, the same keying main uses; - a larger `--top` for the encounter run, harmless at about 199 candidates; - the cancel window in subprocess creation, the same window main has. - **5f9b1e8.** A delta review found one P2, fixed in the head commit: a warning could linger into a new circuit. Its P3s are fixed there too: the duplicate rating on a switch, the retry re-running the ranking, a stale error, and a failed run clearing a warning. Those fixes, in aeebdfd, were checked only by the tests and not reviewed again. - **aeebdfd.** An independent review found no P0/P1; it confirmed that healing without a style changes no ranked field, that the merge can't overwrite ranked fields, and that the lock tarball matches `git archive v3.11.0`. Fixed in 2ba8e67: - **P2:** a healing or style change re-ran the ranking, so her pick could drift from main's. Now only the encounter run re-runs. - **P3s:** the ranking waited for the encounter run; the first run rated healing as 0; the healing estimate is now documented as an upper bound with the cheapest heal's cost; the alert went stale and depended on the decision history; ratings could attach to the wrong circuit when basenames collide; spots beyond the encounter run's `--top` went unrated; the run-time estimate was off. - **2ba8e67.** A delta review found every fix correct and no P0–P2. Its three P3s are fixed in the head commit: - a ranking that falls due now cancels a running encounter run; - the generation guard is now tested; - the encounter run's `--top` is now asserted as the literal 5000. This test fails against 2ba8e67 (`CancelledError not raised`) and against a mutant without the generation check. - **60d86c5.** A follow-up found a race. An encounter process that has exited but hasn't been reaped yet makes `kill()` raise `ProcessLookupError`, which would have surfaced inside `poll()`. Fixed in 4bbebbd: the cancel path, the encounter run's own cancel path and the shared timeout kill now suppress it. Its test, where `kill` raises and `poll` still starts the ranking, fails against 60d86c5. The head commit has not been reviewed again. ## Not verified - **Calibration.** The 0.8 and 6 warning thresholds are calibrated on one character and one zone, as is the analyzer's model. - **Cost.** The encounter run is a second `nice`d analyzer process, about 15 to 30 s, after each ranking and on a healing or style change. - **Healing estimate.** It is a median of landed heals, and a heal near full HP reports less, so the estimate is low. Nothing was checked against live fights. - **Commit footer.** The merge commit has no Co-Authored-By line. I did not amend it, as asked. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The farming analyzer now models encounters per map, so a spot's safety depends on how many monsters a pull really brings and on how the character fights.
The motivating case: on 2026-11-25 the playtester character Sera, a level 37 melee fighter with minor healing, died four times in the Burnt Forest. Every Burnt Forest circuit scored safety 1.0. The old estimate,
min(1, HP / (danger × max_aggro_pack)), uses only the direct aggro pack. Authored spawns there are more than three tiles apart, so that pack is always 1. In reality packs of 3–8 formed from wanderers (random_move), chases of up to 9 tiles, and retreats past other spawns.Changes
Encounter model (
farming_analyzer/encounter.py). For each map it reads:max(9, item_power);monster_signal_chance[Int]chance per AI action, read fromserver/living.c, answered by allies within1.5 × item_power − 1tiles or by spawn points with the sametitle;item_race×item_levellimits;abilityspells resolved throughinclude/spellist.h;It also reads the terrain: walkable regions, open fields, kite room, doorways, corridors, dead ends and crossable seams.
Every heuristic cites the server code it stands for by file and line. The server and content are read as data at runtime, and no GPL code is copied.
How a map is rated.
--healing-per-second.Combat styles.
--combat-styletakesmelee,melee-pack,ranged-kiteoraoe-kite. Each style has its own footprint.--character-speedthrough the same server conversion as route timing. Without it, the documented assumption is speed 1.0, which is 8 tiles/s at the default tick.--kite-distancesets how far a kiter moves.Unkillable targets. An aggressive, damaging target the character cannot hurt (infinite kill time) makes the pull not farmable: its need is infinite and the map's encounter safety is 0. Its spreads, calls and arrival times use a 120 s horizon. An unkillable monster that deals no damage is left alone and never pulled. Single-target styles also leave alone an unkillable passive monster.
AoE provokes passives. Under
aoe-kite, passive monsters inside the AoE footprint are hit, turn on the character and join the pull. So a passive, damaging, unkillable one makes the pull not farmable.Safety.
encounter_safety = 0.75 × (1 − need/HP) + 0.25 × 1/(1 + bad-pull need/HP). It is not saturated in either direction.Backward compatibility. Without
--combat-style,safety_scoreand every existing field are unchanged. The new fields are reported formeleewithencounter_applied: false. With a style,spot_safety_scoreis the lower of the old estimate andencounter_safety. JSON adds"schema_version": 2(version 1 had none).--ignore-encountersturns the model off.Designer report.
python3 -m farming_analyzer report [--path …] [--levels auto|20,30] [--styles …] [--json]gives per-map and per-zone difficulty by level band and style. Each map lists:It rates a documented reference character, scaled per level and calibrated on Sera. The JSON schema (
atrinik.farming_analyzer.difficulty_reportv1) is documented infarming_analyzer/README.mdfor Tilewright to integrate later; it is not integrated here. The README also lists the next increments: line of sight, retreat paths, ranged cadence, steady state, patrols, zone routes and a Tilewright overlay.Results on real content. Sera's live kit at L37: HP 333, AC 58, WC 44, DAM 82, 3.0 s weapon, speed 0.8, impact 38 and cleave 39, healing 5.5 HP/s.
With kiting crowded by pack size:
ranged-kiterates world_16_74 at 0.78, against 0.79 for melee. Both bad pulls hold 9 attackers, which pin a kiter. The kiter's bad pull spans 4 tiles instead of 3, so it gathers slightly different members (2,085 against 1,833 HP).aoe-kiterates world_16_74 at 0.01, with a 16-attacker bad pull. Before the review fix it rated 1.00.The Forgotten Graveyard (world_14_74) at night flags its skeleton mages as fire/weaponmagic/cold casters.
Tests
python3 -m unittest discover -s farming_analyzer/tests -t .: 94 OK. That's the 53 existing tests plus 41 new ones infarming_analyzer/tests/test_encounter.py:--combat-style, kiting, caster damage types fromability, relative mode, CLI JSONschema_versionand validation, and the report schema and text.aoe-kite(4 targets) makes the pull not farmable, and killable passives in the AoE footprint join;slow_moveidle speed, circuit fields from one member, seams with no crossable tiles omitted, missingliving.c/spellist.hwarnings, and the firestorm spell index read from the server table rather than assumed.BurntForestTest: content-dependent, so it asserts ranges and orderings and is skipped with aCONTENT-DEPENDENTreason without the checkout.python3 -m unittest discover -s tests: 12 OK.python3 -W error -m compileall -q -f .andgit diff --checkare clean.report --jsontakes about 34 s (354 maps, 56 zones).Follow-up for atrinik/playtester
farm_analyzer.pyruns a locked analyzer release, so nothing changes for Sera until:classic_server.required_pathsincludesserver/living.candinclude/spellist.h. Without them the analyzer warns and skips ally calls or spell damage types;farm_analyzer.pypasses her style, healing and speed:--combat-style melee --healing-per-second <measured, about 5.5 with minor healing> --character-speed 0.8. A bow or wand build would passranged-kite, an AoE casteraoe-kitewith--targets-per-attack.Optionally:
max_aggro_packtoexpected_packorworst_pack;encounter_reasonsin her decision log;schema_versionbefore relying on the new fields.Not verified
--hp-per-leveland related flags) before relying on absolute labels.move_type, ranged-attack cadence (shooters use their melee cadence), and steady-state respawn order.chase_rangeis reported but not used by the estimate.tests/, so the analyzer suite, including the content-backed test, ran locally only. Addingfarming_analyzer/teststocheck.ymlis deferred scope, not infeasible. The suite needs the classic server source (exp.c,config.h,living.c,spellist.h) and content.check.ymlalready checks out content pinned by a lock, so a lockedatrinik/classicserver/srccheckout can be added the same way. It is listed as a next increment in the README.🤖 Generated with Claude Code