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 = ["pyyaml==6.0.3"]
# ///
"""Writes research_notes/gdd03-regions.approved-draft.yaml (#1691): the per-identity membership and opening-control
values of the owner-approved region draft, so a test can compare the imported evidence against the approved draft
without the 2.4 MB draft living in the repository.
uv run tools/regions_draft_reference.py <path to regions-1691.draft.yaml> [output]
The header records the draft's path, byte size and SHA-256, so anyone holding the approved file can rerun this and
get the same output. For each region, in the draft's order: id, capital_place_id, binding_status and opening_control
status and value; for each member, in the draft's order: id, region_id, binding_status and opening_control status,
value and date. Then every other opening_control in the draft (the reception site, hexes and facilities), in document
order, by its path and with its status, value and date. Nothing else is copied (no sources, names or coordinates)."""
from __future__ import annotations
import hashlib
import json
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parent))
import yaml12 # noqa: E402
ROOT = Path(__file__).resolve().parents[1]
OUT = ROOT / "research_notes" / "gdd03-regions.approved-draft.yaml"
DRAFT_PATH = "docs/drafts/regions-1691.draft.yaml"
def flow(row: dict) -> str:
"""One row as a YAML flow mapping on one line; JSON scalars are valid YAML and keep null distinct from text."""
return "{ " + ", ".join(f"{k}: {json.dumps(v, ensure_ascii=False)}" for k, v in row.items()) + " }"
def segment(item, index: int) -> str:
"""A list item's path segment: its string id, else "q,r" for a hex, else its index (mirrored in Gdd03RegionAuthoringTests)."""
if isinstance(item, dict):
if isinstance(item.get("id"), str):
return item["id"]
if "q" in item and "r" in item:
return f"{item['q']},{item['r']}"
return str(index)
def controls(node, path: list[str], out: list[tuple[str, dict]]) -> None:
"""Every opening_control under node, in document order, with its path."""
if isinstance(node, dict):
for key, value in node.items():
if key == "opening_control":
out.append(("/".join(path), value))
controls(value, path + [str(key)], out)
elif isinstance(node, list):
for i, item in enumerate(node):
controls(item, path + [segment(item, i)], out)
def ancillary(path: str) -> bool:
"""Not a region's own control (regions/<id>) or a member's (regions/<id>/members/...): those are listed above."""
parts = path.split("/")
return not (parts[0] == "regions" and (len(parts) == 2 or parts[2] == "members"))
def reference(raw: bytes) -> str:
draft = yaml12.load(raw.decode("utf-8"))
out = [
"# Generated by tools/regions_draft_reference.py from the owner-approved #1691 region draft; do not edit by hand.",
"# Per-identity membership and opening control, plus every other opening control by path. Gdd03RegionAuthoringTests",
"# compares the imported evidence (gdd03-regions-capitals-fields.yaml) with it, identity by identity.",
"source:",
f" file: {DRAFT_PATH}",
f" bytes: {len(raw)}",
f" sha256: {hashlib.sha256(raw).hexdigest()}",
"regions:",
]
for r in draft["regions"]:
control = r["opening_control"]
fields = {"id": r["id"], "capital_place_id": r["capital_place_id"], "binding_status": r["binding_status"],
"control_status": control.get("status"), "control_value": control.get("value")}
out += [(" - " if i == 0 else " ") + f"{k}: {json.dumps(v, ensure_ascii=False)}" for i, (k, v) in enumerate(fields.items())]
out.append(" members:")
for m in r["members"]:
control = m["opening_control"]
out.append(" - " + flow({"id": m["id"], "region_id": m["region_id"], "binding_status": m["binding_status"],
"control_status": control.get("status"), "control_value": control.get("value"),
"control_date": control.get("date")}))
found: list[tuple[str, dict]] = []
controls(draft, [], found)
out.append("ancillary_controls:")
for path, control in found:
if ancillary(path):
out.append(" - " + flow({"path": path, "status": control.get("status"), "value": control.get("value"),
"date": control.get("date")}))
return "\n".join(out) + "\n"
def main(argv: list[str]) -> int:
if len(argv) not in (2, 3):
print(__doc__, file=sys.stderr)
return 2
out = Path(argv[2]) if len(argv) == 3 else OUT
out.write_text(reference(Path(argv[1]).read_bytes()), encoding="utf-8")
return 0
if __name__ == "__main__":
sys.exit(main(sys.argv))