ContextLab / ContextLab/risk-analysis

Recover continent membership and territory shapes by segmenting map images

Open
#4 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
1
Forks
0
PR merge metrics
No merged PRs in 30d

Description

Blocks the continent-bonus feature family in #1. Split out because it is a self-contained
computer-vision job, not part of the HTML-parsing path.

## The problem

D12's markup exposes territory id, name, adjacency, and label coordinates — but **not continent
membership**. Verified against a real game page (`/game/1889`, World Classic): 42 territory
anchors, zero occurrences of `data-region`, `region`, or `continent`.

```html

```

The catalog reports `num_regions` per map (6 for World Classic, up to 36 for Land of Rus'), so
the count is known — the per-territory assignment is not. Continent bonuses are central to Risk
strategy, so the bonus-weighted-income feature in #1's position-strength model is blocked without
this.

## Approach

Continents are colour-coded on the map artwork itself. Drive the map selection panel with
Playwright, capture each map's image, and segment it.

- `/maps` is **robots-allowed**, as are `/assets/img/maps/.large.jpg` and
`/image/map/.large.circles.jpg`. The `.circles` variant overlays territory markers.
- Topology, by contrast, only exists on `/game/`, which robots.txt disallows — so the image
route is the *better-founded* path, not merely a fallback.
- This runs **once**, over 77 maps, not on any repeating schedule.

Segmentation should yield more than continents:

1. **Continent membership** — cluster territories by the artwork's fill colour at each known
`data-x`/`data-y`, or by segmenting regions directly.
2. **Territory polygons** — actual boundaries rather than just label points. This is what #1 asks
for when it says "high quality vector (plottable at any resolution) with labeled territories
and connections"; the current renderer draws nodes at label coordinates, which is a weaker
substitute.
3. **Adjacency, as a cross-check** — polygons that share a boundary are neighbours.

## Validation is available, and should gate this

`tests/fixtures/game_map1_territories.html` holds ground truth for World Classic straight from
D12: 42 territories, 83 undirected edges, exact adjacency, real names. Segmentation-derived
adjacency must be checked against it rather than trusted. If the pipeline cannot reproduce those
83 edges, it is not ready to run on the other 76 maps.

Report per-map agreement rather than a single aggregate — a method that works on World Classic and
fails on dense 150-territory maps needs to be known as such, not averaged into looking fine.

## Notes

- Map artwork is D12's and trademarked. Derived data (adjacency, membership, polygons) is factual
and fine to publish; **the source JPEGs are not to be redistributed**, and figures must render
our own geometry rather than reproducing their images.
- `region_id` already defaults to 0 throughout the codebase, and `check_invariants` treats a
wholly region-less map as valid rather than an error (map 77, "Brecourt Manor", genuinely has 0
regions). So this issue is additive — nothing needs restructuring to accept its output.

## Depends on

#1 for the `MapTopology` model and the graph layer.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the MapTopology model and graph layer from #1, then inspect the Playwright flow for /maps and the permitted map image routes. Use tests/fixtures/game_map1_territories.html as ground truth and validate segmentation-derived adjacency against its 83 edges before processing other maps. Done means per-map agreement is reported, derived membership, polygons, and adjacency are produced without redistributing source JPEGs.

Written by the indexing model from the issue text.

Assessment

Tech stack
playwright, python
Domain
computer-vision
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.