agentleFS
KonHKonH/GlobalStrategy/.claude/skills/province-config-generator/SKILL.md

province-config-generator

Skill3 starsChanged 2 months agoMITView on GitHub

Run or modify the two-stage province generation pipeline — Stage 1 scripts/utils/generate_provinces.py (geopandas/Voronoi/mapshaper geometry, Natural Earth downloads, province_name.* locale writes) and Stage 2 src/Game.Configs.Loader ProvinceProcessor, which emits Assets/Configs/provinces.json and province_map_features_1880.json. Load when regenerating province data, changing generation constants/calibration, or debugging province ids, names, population, or neighbours.

The file

We split this skill into the rules it gives an agent

1 rule. About 0 are common, 1 is distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Run from the project root:

    line 23

≈ “Common” is an estimate: at least 1 in 5 of the 364,980 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Province Config Generator (Two-Stage Pipeline)

Province-level data (sitting between mapFeatureId and countryId) is generated by a two-stage pipeline. This is a build-time data/config foundation only — no MapRenderer changes, no runtime consumption yet. See Docs/Specs/43_province-division/ for the full spec and plan.

Stage 1 — Python geometry stage (scripts/utils/generate_provinces.py)

Run from the project root:

.venv\Scripts\python.exe scripts\utils\generate_provinces.py [--force-download]

Dependencies (installed into .venv): geopandas, shapely, scipy, pyproj, requests (same venv as the flag-asset tooling — see the flag-assets skill).

New toolchain dependency: Node.js/npx. The final simplify step shells out to npx mapshaper (auto-installed from the npm registry on first run if not already present locally). No package.json is checked into the repo — npx fetches mapshaper on demand. Confirm Node.js is installed on any machine that needs to re-run this script.

What it does

  1. Reconstructs each 1880 country's unioned polygon from Assets/Configs/countries.json (mainMapFeatureIds/secondaryMapFeatureIds, colonial-parent merges already applied) plus the raw feature geometries in Assets/Map/world_1880.json. mapFeatureId is recomputed locally from each raw feature's name property using the same ASCII-normalize + slug algorithm as Program.cs's ToMapFeatureId, so there's no need to round-trip through geojson_world.json/map_entries.json for geometry.
  2. Reprojects to EPSG:6933 (equal-area) purely for km² math; all emitted geometry stays in WGS84 lon/lat to match world_1880.json's convention.
  3. Downloads and caches (skip if present) two Natural Earth datasets into the gitignored .tmp/naturalearth/ directory: ne_10m_admin_1_states_provinces and ne_10m_populated_places (source: naciscdn.org/naturalearth/10m/cultural/).
  4. Per country, applies one of three generation methods:
    • Micro — area < 3,000 km²: single province = country's own polygon, displayName = country's displayName. No admin-1/Voronoi attempted.
    • Option A — geopandas.overlay(admin1, country_polygon, how="intersection"). Accepted only if piece count is in [2, 300] and ≤30% of pieces (by count) are "slivers" (<0.5% of country area). Names come from the admin-1 feature's name/ woe_name property.
    • Option C (fallback when Option A fails the fit-quality gate) — scatter clamp(round(area_km2 / 10_000), 3, 150) seed points (both the divisor and the cap are scaled per-country by PER_COUNTRY_DENSITY_MULTIPLIER, a dict of countryId -> multiplier for areas that need finer detail than the global constants give — e.g. an archipelago that collapses into one Voronoi cell) via rejection sampling with a deterministic RNG seeded from an MD5 hash of countryId (never unseeded — required for reproducible re-runs), build a scipy.spatial.Voronoi tessellation, clip each cell to the country polygon, (population density is separately scaled per-country by COUNTRY_POPULATION_CALIBRATION_1880, a dict of countryId -> multiplier that calibrates the total generated population of isAvailable=true countries to a researched real-world circa-1880 figure; countries without an entry keep the uncalibrated region-band estimate — see step 7 below), and name each province from the nearest ne_10m_populated_places point — search is uncapped by distance, so a cell is named after its closest known settlement however far away, only falling back to a compass-direction name (e.g. "Northern Afghanistan", relative to the country's own bounding box) if the country has zero populated-places entries at all. If Option C itself yields zero valid cells, the country falls back further to the Micro rule so no country is ever left with zero provinces.
  5. Assigns a deterministic provinceId = {countryId}__{slug(name)}, with a numeric suffix (_2, _3, ...) on any in-country name collision.
  6. Serializes the combined result to the gitignored intermediate file .tmp/provinces_intermediate.geojson (properties: provinceId, countryId, displayName, generationMethod, compassKey — the latter is null except for the rare compass-direction fallback case above, and only used by the locale step below — isMainTerritory (True if the majority of the province's area falls within the country's mainMapFeatureIds geometry, False for secondaryMapFeatureIds/colonial holdings — see classify_main_territory), plus a population placeholder, computed in step 7 below).
  7. Runs npx mapshaper -i <file> -simplify keep-shapes <pct>% -o <file> to reduce vertex count for WebGL viability (keep-shapes guarantees no polygon degenerates to zero area). The simplify percentage is a tunable constant (MAPSHAPER_SIMPLIFY_PCT) in the script, currently 10. Afterward, each province's final population is computed from this simplified geometry's area (COUNTRY_REGION/REGION_DENSITY_RANGES-derived density, scaled by COUNTRY_POPULATION_CALIBRATION_1880 where the country has an entry, × simplified polygon area). The final geometry also supplies centroidX/centroidY and an ordinal neighborProvinceIds list. Adjacency uses a Shapely spatial index and requires a non-zero shared boundary-segment length, so point-only contacts are excluded. These properties are written back into .tmp/provinces_intermediate.geojson, so persisted population and topology match the geometry actually shipped to Stage 2.
  8. Writes province_name.{provinceId} locale entries into Assets/Localization/en.asset (the generated name verbatim) and Assets/Localization/ru.asset — settlement/admin-1 proper nouns are run through a deterministic phonetic Latin→Cyrillic transliteration (transliterate_to_cyrillic, a placeholder pending real translation), while compass-direction fallback names use a proper Russian translation table (COMPASS_RU) combined with the country's already-translated country_name.{countryId} entry — never transliterated, since "Northern"/"Central" etc. are real words, not proper nouns. Re-running the script replaces all province_name.* entries in both files but leaves every other key untouched.

At the end, the script prints a per-country generation-method summary (counts of Micro / Option A / Option C countries) and any warnings — e.g. a country that fell back from Option A to Option C (fit-quality rejection), or from Option C to Micro (degenerate/disjoint Voronoi geometry).

Cache locations:

  • .tmp/naturalearth/ — downloaded Natural Earth zips + extracted shapefiles (gitignored)
  • .tmp/provinces_intermediate.geojson — intermediate output consumed by Stage 2 (gitignored)

Stage 2 — C# metadata/validation stage (src/Game.Configs.Loader)

ProvinceProcessor reads the intermediate GeoJSON produced by Stage 1 and the in-memory CountryConfig already built in the same Program.cs run, cross-validates every province's countryId against CountryConfig (per .claude/rules/config_validation.md — a mismatch throws rather than silently proceeding), and writes Assets/Configs/provinces.json (lightweight metadata: provinceId, countryId, generationMethod, population, centroidX, centroidY, isMainTerritory, and neighborProvinceIds — no displayName; province names are localization-only, see province_name.* keys above) and Assets/Configs/province_map_features_1880.json (passthrough geometry FeatureCollection).

Re-run order: Stage 1 (Python) must be run before Stage 2 (C# loader), since Stage 2 consumes Stage 1's intermediate file via loaderConfig.ProvinceGeoJsonSourcePath.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.