Skip to content

feat(farming-analyzer): charge the approach maps to a spot's safety - #34

Merged
zoeyrose merged 5 commits into
mainfrom
feat/analyzer-approach-danger
Nov 15, 2026
Merged

zoeyrose merged 5 commits into
mainfrom
feat/analyzer-approach-danger

Conversation

@zoeyrose

Copy link
Copy Markdown
Member

Summary

A farm spot's safety_score now includes the maps the character has to cross to reach it, not only the spot's own monsters. It becomes the lower of the spot's own safety and the safety of the least dangerous approach.

The motivating case: on 2026-11-14 the playtester character Sera, level 36 with no fire, acid or poison protection, died five times on the Underground City entrance map (underground_city_0_0). Its level-32 puddings and jellies were not part of any circuit's score, so the analyzer rated those circuits at 0.69–0.99 safety.

Changes

Connectivity graph. It is built in the same pass as terrain, at about the same scan time. Edges come from:

  • type-66 exits (slaying);
  • tile_path_N headers;
  • walkable coordinate seams.

Approach origins. These are surface world_X_Y tiles, savebed maps, and the new --approach-origin MAP option.

Approach search. A bounded bottleneck search (--max-approach-maps, default 16) finds the path whose most dangerous map is least dangerous. Each map's danger reuses the existing monster and damage model, including the character's protections.

New output fields. These are added to every result: spot_safety_score, approach_status, approach_origin, approach_maps, approach_danger, approach_safety_score, approach_worst_map and approach_danger_flags. Existing fields keep their names. safety_score can now only go down. --ignore-approach turns the feature off.

Not modelled: scripted teleports, keys and locked doors, and running past monsters.

Validation

  • python3 -m unittest discover -s farming_analyzer/tests -t .: 34 OK. That's the 26 existing tests plus 8 new ones in test_approach.py.
  • tests: 12 OK. map-checker-qt/tests: 28 OK.
  • compileall -W error and git diff --check are clean.
  • On real content, the Underground City circuits now report approach maps through underground_city_0_0 with fire, acid and poison flags.

Follow-up

The playtester locks analyzer v3.8.0. Once this is released, the playtester needs a lock bump, and its farm_analyzer.py field whitelist has to pass the new fields through.

🤖 Generated with Claude Code

A circuit could rate safety 0.69-0.99 while the only way in crossed a far
deadlier map: Sera (level 36, no fire/acid/poison protection) died five
times on the Underground City entrance, whose level-32 puddings and jellies
the analyzer never scored because it looked only at the circuit's own maps.

Build a map graph from authored exits, tile_path_N headers and walkable
coordinate-map seams, and run a bounded, deterministic bottleneck search
from the nearest origin (surface world tile, savebed map or the new
--approach-origin) to each spot. Each crossed map is charged for its worst
aggressive encounter with the existing monster, damage and protection
model, cached per map. safety_score becomes the lower of the spot and
approach safeties; the spot-only value stays in spot_safety_score, and new
approach_* fields expose the path, origin, worst map, danger and flags.
--ignore-approach restores the spot-only score and --max-approach-maps
bounds the search.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

Dependency Review

✅ No vulnerabilities or license issues found.

Scanned Files

None

zoeyrose and others added 4 commits November 14, 2026 15:45
Address review of the approach-danger change:

- Charge an approach pack by sequential exposure: every engaged monster
  keeps attacking until it dies, killed in Smith's-rule order. The
  Underground City entrance slime cluster rises from ~127 to ~288 expected
  damage for a Sera-like level 36 profile.
- Re-expand a map reached with fewer hops so a long zero-danger path can
  no longer block a shorter, more dangerous one inside the hop limit.
- Flag unreachable spots with approach_unknown and add the opt-in
  --unreachable-approach-safety cap.
- Derive tiling as the server's derive_map_filename_tiles() does: any
  basename with two or three short numeric words, eight same-depth
  directions including diagonal corners.
- Charge surface entrance tiles when crossed; savebed and explicit origins
  stay free. Add --approach-origins-only, normalize and validate
  --approach-origin, and ignore savebeds carried in containers.
- Test the reviewer's hop-limit repro, disconnected maps, tile paths,
  savebeds, relative/absolute slaying, nested exits, missing targets,
  depth-only and diagonal seams, plus a content-gated Underground City
  regression.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Linking whole maps credited exits a character cannot stand next to. The
world_2_69 exit_green sits on a two-tile pocket reachable only from inside
the Underground City, so 81 city results took that phantom entrance and
stayed at safety 1.0 for a Sera-like profile at 244 HP.

- Search over (map, 8-neighbour walkable component) nodes, computed lazily
  and cached. Exits leave from their tile or an adjacent walkable tile and
  land at hp/sp, enter_x/enter_y when out of range, or an adjacent free
  tile; stairs without slaying follow last_heal through the tile table;
  same-map exits move between components.
- Seams join only the edge and corner tiles they connect, using the
  server's tile table (header tile_path_N first, then derived names).
- Origins are components: placed savebeds and every part of an explicit
  origin are free; surface components are charged origins only when their
  surface-seam group touches a savebed or an exit to or from a savebed
  map, so islets and pockets entered from below are not origins.
- Charge a spawn that is aggressive with probability p by p, not p², in
  sequential exposure; document why crossing a pack costs about (n+1)/2
  times farming it.
- Replace the approach_unknown flag with a boolean field, and document
  path results with no approach maps.
- Test islets, surface pockets, dungeon dead ends, enter_x/enter_y
  arrival and seam components, plus a content-gated check that the city
  circuits now approach through 0_0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Record exit sub_type and follow auto-linked exits (no path, hp/sp -1,
  non-zero sub_type) to every same-sub_type exit within five tiles,
  across tiled neighbours, as exit_find() does.
- Charge an approach node only for the spawns standing in its walkable
  component, cached per (map, component); a spawn with no walkable tile
  nearby stays charged everywhere.
- Group surface components once with union-find over seams in either
  direction, so town connectivity no longer depends on visit order.
- Document that the content-gated Underground City test is skipped
  without a content checkout and so does not run in CI.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…mponent

Filtering an approach component's threat to spawns standing in it
dropped casters, archers, flyers and swimmers behind rock, tree or water
lines that block walking but not engagement. Charge every spawn whose own
detection radius reaches a tile of the component by Chebyshev distance,
alongside spawns standing in it, so only genuinely distant components
stay separate. Test a caster behind a walk-blocking line and a pocket
beyond its radius.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@zoeyrose

Copy link
Copy Markdown
Member Author

Self-review

Scope: the full diff 073ed62..450bf75. A fresh-context reviewer read 2ed790a in full, then did delta reviews of b65349d, 4512a52, 50fd6fb and 450bf75. It probed real content with independent tile walks, using the scripts in rev34/. Validation: farming_analyzer 53 OK, tests 12 OK, map-checker-qt 28 OK, compileall -W error, git diff --check.

Round 1 (2ed790a), fixed in b65349d

  • P1, the motivating case barely moved. Packs are now charged by sequential exposure, and a content-gated regression test covers it.
  • P2, the hop-bound search failed open. Fixed with best-hops pruning, with the reviewer's repro as a test.
  • P2, unreachable spots failed open. They now get the approach_unknown flag, plus an optional cap.
  • P3, tiling approximation. Seams are now derived the way the server does it, including diagonals.
  • P3, surface origins were free. They are now charged, and there is a new --approach-origins-only option.
  • P3, smaller items. Origin normalisation and the savebed parent check are fixed.
  • Tests: added.

Round 2 (b65349d), fixed in 4512a52

  • P1, phantom approach via world_2_69. The islet is reachable only from inside the UC. The search now runs over (map, walkable component) nodes with server-style exits and landing, and only surface groups that contain a town count as origins.
  • P3s: _sequential_exposure is documented, mixed-spawn p-weighting is fixed, and approach_unknown is now a boolean field.

Round 3 (4512a52), fixed in 50fd6fb

  • P3, paired auto-link exits. Added _paired_exits, matching exit_find.
  • P3, packs charged across components. Charging is now per component.
  • P3, order-dependent surface labelling. Fixed with union-find.
  • P3, the content-gated test is skipped in CI. This is now documented.

Round 4 (50fd6fb), fixed in 450bf75

  • P2, per-component charging dropped casters and flyers across obstacles that block walking but not sight. A spawn is now charged if its detection radius reaches the component.

Round 5 (450bf75)

No P0–P2. Two items declined:

  • P3: a spawn with no walkable tile nearby is now charged only within its detection radius. This is consistent with the engagement rule.
  • Out of scope: spell range beyond the detection radius. It is documented in the README and would need its own spell-range model.

Known limits, documented: poisoning pulses, keys and locks, scripts and fight variance. At 322 HP the UC circuits still score 1.0 (0_0 pack 288 < 322); at Sera's current 244 HP they score 0.85.

@zoeyrose
zoeyrose marked this pull request as ready for review November 15, 2026 16:22
@zoeyrose zoeyrose self-assigned this Nov 15, 2026
@zoeyrose
zoeyrose requested a review from a team November 15, 2026 16:22
@zoeyrose
zoeyrose merged commit dcb1ef9 into main Nov 15, 2026
6 checks passed
@zoeyrose
zoeyrose deleted the feat/analyzer-approach-danger branch November 15, 2026 16:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant