A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
# /// script
# requires-python = ">=3.11"
# dependencies = ["numpy==2.5.3", "pyyaml==6.0.3"]
# ///
"""Locality -> hex for the gdd-0.3 player regions (R-CITY-006, #1691).
Usage: uv run tools/locality_hexes.py (reads content/map/hexes.json, content/map/localities_1948.yaml and
content/map/region_places_1948.yaml, writes content/map/locality_hexes.yaml)
Owner, 2 November 2026: "Accept localities" (a locality id may be a region member). Each place's hex is the one holding
its coordinates, placed as the game places settlements (hexgrid.settlement_hex: a point in a sea hex takes the nearest
land neighbour). The sim reads the result instead of projecting lon/lat itself, so it needs no trigonometry
(docs/determinism.md), as for settlement_hexes.py and unit_anchor_hexes.py. Rows keep the input order: the localities,
then the region places."""
import json
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parent))
import hexgrid as hg # noqa: E402
import yaml12 # noqa: E402
ROOT = Path(__file__).resolve().parents[1]
MAP = ROOT / "content" / "map"
OUT = MAP / "locality_hexes.yaml"
HEADER = ("# Generated by tools/locality_hexes.py from localities_1948.yaml, region_places_1948.yaml and hexes.json\n"
"# (hexgrid.settlement_hex). Do not edit by hand: rerun the tool after changing any input. Read by the sim only\n"
"# under exact gdd-0.3, to place region members (R-CITY-006).\n")
def places() -> list[dict]:
"""The localities, then the region places, as their files list them."""
loc = yaml12.load((MAP / "localities_1948.yaml").read_text(encoding="utf-8"))["places"]
extra = yaml12.load((MAP / "region_places_1948.yaml").read_text(encoding="utf-8"))["places"]
return loc + extra
def render(hexes: dict, rows: list[dict]) -> str:
"""The file text: one flow mapping per place. A repeated id is an error, not a silent second hex."""
seen: set[str] = set()
lines = [HEADER, "localities:\n"]
for p in rows:
if p["id"] in seen:
raise ValueError(f"duplicate place id {p['id']}")
seen.add(p["id"])
q, r = hg.settlement_hex(p["lon"], p["lat"], hexes)
lines.append(f" - {{ id: {p['id']}, q: {q}, r: {r} }}\n")
return "".join(lines)
def main() -> None:
hexes = json.loads((MAP / "hexes.json").read_text())
rows = places()
OUT.write_text(render(hexes, rows))
print(f"wrote {OUT.relative_to(ROOT)} ({len(rows)} places)")
if __name__ == "__main__":
main()