Files
windroost/p2_godot_sample/scripts/world_content_test.gd
T
wushenghua 3be8a4591a feat: L3 world structure + automation over 600 nodes (FULL_GAME_GOAL)
Continued FULL_GAME_GOAL. The full content pack existed but the runtime had no
way to index or simulate it. Added:
- world_content.gd: read-only index over full_game_content.json (symlinked into
  the Godot project) — regions/chapters/nodes/event lookup and scenario_for_node
  producing sim-ready scenarios, additive to the 10-node LaunchContent.
- world_content_test: 5 regions / 60 chapters / 600 nodes indexed; 420 combat
  nodes generate scenarios with resolvable enemies; chapter structure valid;
  a sample node per region runs the real sim to a win (17->54 ticks by region).
- automation.py (authoritative, design 9.3): auto-chain normal nodes, stop at
  events/elite/boss/trial, garrison/offline bounded to 8h, failure reason report.
- test_automation: full-world traversal counterfactual — auto clears N01/N02
  then correctly stops at event N03, proving state-dependent choices are never
  auto-resolved at 600-node scale.

Both gates registered; full P2_CHECKS_PASS. Live slice routing untouched.
prototype/ untracked.
2026-11-18 14:08:49 +08:00

121 lines
4.4 KiB
GDScript

extends SceneTree
## L3 world structure evidence: 600 nodes / 60 chapters / 5 regions indexed,
## every node generates a valid battle scenario with resolvable enemies.
const WorldContent = preload("res://scripts/world_content.gd")
const P2BattleSim = preload("res://scripts/battle_sim.gd")
const OUTPUT_PATH := "res://artifacts/world_content_test.json"
var _problems: Array = []
var _steps: Array = []
func _init() -> void:
_run.call_deferred()
func _check(cond: bool, msg: String) -> void:
if not cond:
_problems.append(msg)
func _record(name: String, data: Dictionary) -> void:
var e := data.duplicate()
e["step"] = name
_steps.append(e)
func _run() -> void:
var c: Dictionary = WorldContent.content()
_check(not c.is_empty(), "full-game content pack must load")
var regions: Array = WorldContent.regions()
var chapters: Array = WorldContent.chapters()
var nodes: Array = WorldContent.nodes()
_check(regions.size() == 5, "5 regions expected, got %d" % regions.size())
_check(chapters.size() == 60, "60 chapters expected, got %d" % chapters.size())
_check(nodes.size() == 600, "600 nodes expected, got %d" % nodes.size())
_record("structure", {"regions": regions.size(), "chapters": chapters.size(), "nodes": nodes.size()})
# Every node must produce a scenario with resolvable enemies (where it has a wave).
var combat_nodes := 0
var bad := 0
for n in nodes:
var nid := str(n.get("id", ""))
var waves: Array = n.get("waves", [])
if waves.is_empty():
continue # event/shop/supply nodes have no battle
combat_nodes += 1
var sc: Dictionary = WorldContent.scenario_for_node(nid, 0)
if sc.is_empty():
_problems.append("no scenario for %s" % nid); bad += 1; continue
var ids: Array = sc.get("enemy_ids", [])
if ids.is_empty():
_problems.append("no enemies in scenario for %s" % nid); bad += 1; continue
var specs: Dictionary = sc.get("enemy_specs", {})
for eid in ids:
if not specs.has(eid):
_problems.append("missing spec for %s in %s" % [eid, nid]); bad += 1
elif float(specs[eid].get("hp", 0)) <= 0:
_problems.append("nonpositive hp for %s in %s" % [eid, nid]); bad += 1
if bad > 10:
break
_record("scenarios", {"combat_nodes": combat_nodes, "bad": bad})
# Chapter indexing: R1 has 12 chapters, each with 10 nodes.
for r in regions:
var chs: Array = WorldContent.chapters(r)
_check(chs.size() == 12, "%s should have 12 chapters, got %d" % [r, chs.size()])
for ch in chs:
var ns: Array = WorldContent.nodes(ch)
if ns.size() != 10:
_problems.append("%s has %d nodes, expected 10" % [ch, ns.size()])
break
_record("chapter_structure", {"regions_checked": regions.size()})
# Event lookup for a chapter resolves.
var ev: Dictionary = WorldContent.event_for_chapter("R1-C01")
_check(not ev.is_empty(), "R1-C01 should have an event")
_record("event_lookup", {"id": ev.get("id", "")})
# A representative combat node per region must actually run in the sim to
# a terminal state (structure alone could still hide a bad stat).
var rules := P2BattleSim.load_rules()
var ran: Array = []
for r in regions:
var chs: Array = WorldContent.chapters(r)
var first_node: Array = WorldContent.nodes(chs[0])
var nid := str(first_node[0].get("id", ""))
var sc: Dictionary = WorldContent.scenario_for_node(nid, 0)
if sc.is_empty():
_problems.append("no scenario for sample %s" % nid)
continue
var state := P2BattleSim.create_state(rules, sc, 10001, 60.0)
var guard := 0
while not state["finished"] and guard < 3000:
P2BattleSim.step_state(rules, state)
guard += 1
_check(bool(state["finished"]), "sample node %s should reach terminal state" % nid)
ran.append({"node": nid, "result": state.get("result", "?"), "ticks": guard})
_record("sim_samples", {"nodes": ran})
_finish()
func _finish() -> void:
var passed := _problems.is_empty()
var report := {"schema": 1, "kind": "windroost_world_content_test",
"overall": "PASS" if passed else "FAIL", "problems": _problems, "steps": _steps}
var dir := ProjectSettings.globalize_path("res://artifacts")
DirAccess.make_dir_recursive_absolute(dir)
var f := FileAccess.open(dir.path_join("world_content_test.json"), FileAccess.WRITE)
if f != null:
f.store_string(JSON.stringify(report, "\t", true)); f.close()
for e in _steps:
print("WORLD_STEP %s" % JSON.stringify(e))
if passed:
print("WORLD_PASS 600-node world structure valid")
else:
print("WORLD_FAIL %s" % "; ".join(_problems))
quit(0 if passed else 1)