AGENTS.md requires a milestone to prove five play profiles with explicit decision timestamps. The chapter simulator previously had only passive/active. tools/pacing_profiles.py now runs five genuinely different behaviours (normal, active, efficient, adversarial, returning) and records per-node arrival times, every decision timestamp, longest no-decision gap, active-input share, failures and offline efficiency. data/pacing_profiles.json holds the evidence; tools/check_pacing_profiles.py gates it; PRODUCTION/40 documents the results and the honest findings. The profiling exposed a real bug I introduced: the offline gold rate (0.02, a value I had picked without a contract basis) paid 19008 gold for 8h, leveling the first hero to Lv.17 when a normal clear ends at Lv.2-4. tools/tune_offline.py scans rates; 0.001 pays 950 gold (~Lv.4) and keeps returning players in range. The rate now lives in mvp_battle_rules.json progression and is read by both the Godot ProfileStore and the Python simulator, so the two cannot drift. The p3b test derives its expected values from the same shared rate. Two honest findings are recorded, not hidden: efficient is slower than active because weakness windows are not yet a settlement multiplier (tracked in PRODUCTION/39), and concentrated upgrades outperform spread ones in the CH cost curve. tools/run_p2_checks.sh now runs 21 gates; all pass.
334 lines
14 KiB
Python
334 lines
14 KiB
Python
#!/usr/bin/env python3
|
|
"""Five-profile pacing analysis for the first chapter.
|
|
|
|
AGENTS.md requires an incremental milestone to prove five play profiles with
|
|
explicit decision timestamps: normal, active, efficient, adversarial and
|
|
returning. This script drives the deterministic paper runner (same numbers as
|
|
the Godot runtime) with five genuinely different player behaviours and records:
|
|
|
|
* time to each node and to the milestone decisions
|
|
* the longest interval with no player decision
|
|
* active-input share vs idle time
|
|
* dominant upgrades, resource starvation/overflow
|
|
* offline vs online efficiency (returning profile)
|
|
* failed attempts and retry recovery (adversarial profile)
|
|
|
|
No production data is changed. Output: data/pacing_profiles.json.
|
|
|
|
Usage:
|
|
python3 tools/pacing_profiles.py
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import json
|
|
from pathlib import Path
|
|
from typing import Any, Dict, List, Tuple
|
|
|
|
from mvp_validation_sim import Rules, run_scenario
|
|
|
|
ROOT = Path(__file__).resolve().parent.parent
|
|
RULES_PATH = ROOT / "data/mvp_battle_rules.json"
|
|
CONTENT_PATH = ROOT / "data/mvp_launch_content.json"
|
|
OUT_PATH = ROOT / "data/pacing_profiles.json"
|
|
SEED = 10001
|
|
MAX_RETRIES = 3
|
|
|
|
# Event choices from mvp_launch_content.json: rescue/study are the permanent
|
|
# (efficient) options; scavenge/take are the immediate-gold options.
|
|
EFFICIENT_EVENT = {"R1-C01-N04": "rescue", "R1-C01-N07": "study"}
|
|
WASTEFUL_EVENT = {"R1-C01-N04": "scavenge", "R1-C01-N07": "take"}
|
|
|
|
PROFILES = ["normal", "active", "efficient", "adversarial", "returning"]
|
|
|
|
|
|
def read_json(path: Path) -> Dict[str, Any]:
|
|
with path.open("r", encoding="utf-8") as handle:
|
|
return json.load(handle)
|
|
|
|
|
|
class Profile:
|
|
"""Behavioral knobs that make each play style genuinely different."""
|
|
|
|
def __init__(self, name: str) -> None:
|
|
self.name = name
|
|
# Tap cadence: None means never tap.
|
|
self.tap_interval: float | None = 0.8
|
|
self.use_cooldowns = False # storm / ultimate on cooldown
|
|
self.upgrade_strategy = "cheapest" # cheapest | highest_dps | most_expensive
|
|
self.event_strategy = "immediate" # immediate | permanent
|
|
self.retry_on_loss = True
|
|
self.offline_seconds = 0.0
|
|
|
|
if name == "normal":
|
|
pass # the defaults
|
|
elif name == "active":
|
|
self.tap_interval = 0.2
|
|
self.use_cooldowns = True
|
|
elif name == "efficient":
|
|
self.tap_interval = 0.35 # tap mainly during windows
|
|
self.use_cooldowns = True
|
|
self.upgrade_strategy = "highest_dps"
|
|
self.event_strategy = "permanent"
|
|
elif name == "adversarial":
|
|
# A disengaged player: taps erratically, ignores cooldowns and
|
|
# hoards gold instead of investing it. Hoarding is the real waste
|
|
# in this economy (concentrated upgrades are actually efficient).
|
|
self.tap_interval = 0.6
|
|
self.use_cooldowns = False
|
|
self.upgrade_strategy = "hoard"
|
|
self.event_strategy = "immediate"
|
|
elif name == "returning":
|
|
self.tap_interval = 0.8
|
|
self.offline_seconds = 8 * 3600 # capped offline before the run
|
|
else:
|
|
raise ValueError(f"unknown profile {name}")
|
|
|
|
|
|
def build_inputs(profile: Profile, timeout: float, node_type: str) -> List[Dict[str, Any]]:
|
|
events: List[Dict[str, Any]] = []
|
|
if profile.tap_interval is not None:
|
|
# An adversarial player also taps away at trivial nodes; an efficient
|
|
# player focuses taps on elite/boss where shield/weakness windows live.
|
|
t = 0.2
|
|
while t < timeout:
|
|
events.append({"time": round(t, 2), "type": "click_enemy"})
|
|
t += profile.tap_interval
|
|
if profile.use_cooldowns:
|
|
for s in (3.0, 13.0, 23.0):
|
|
if s < timeout:
|
|
events.append({"time": s, "type": "offboard_burst"})
|
|
for s in (5.0, 15.0, 25.0):
|
|
if s < timeout:
|
|
events.append({"time": s, "type": "cast_ultimate", "hero_id": "H01"})
|
|
return events
|
|
|
|
|
|
def upgrade_choice(strategy: str, unlocked: List[str], levels: Dict[str, int],
|
|
heroes: Dict[str, Any], gold: int) -> Tuple[str, int] | None:
|
|
def cost(h: str) -> int:
|
|
return int(round(120.0 * pow(1.15, levels[h] - 1)))
|
|
|
|
affordable = [h for h in unlocked if gold >= cost(h)]
|
|
if not affordable:
|
|
return None
|
|
if strategy == "hoard":
|
|
# Never spend voluntarily; only a retry forces an upgrade.
|
|
return None
|
|
if strategy == "cheapest":
|
|
chosen = min(affordable, key=lambda h: cost(h))
|
|
elif strategy == "highest_dps":
|
|
chosen = max(affordable, key=lambda h: float(heroes[h]["base_dps"]))
|
|
else: # most_expensive - a deliberately poor choice
|
|
chosen = max(affordable, key=lambda h: cost(h))
|
|
return chosen, cost(chosen)
|
|
|
|
|
|
def simulate(content: Dict[str, Any], rules: Rules, profile: Profile, seed: int) -> Dict[str, Any]:
|
|
heroes = {str(r["id"]): r for r in content["heroes"]}
|
|
enemies = {str(r["id"]): r for r in content["enemies"]}
|
|
boss = content["boss"]
|
|
|
|
unlocked: List[str] = ["H01", "H02", "H03"]
|
|
levels: Dict[str, int] = {h: 1 for h in unlocked}
|
|
gold = 0
|
|
crystal = 0
|
|
decisions: List[Dict[str, Any]] = []
|
|
nodes: List[Dict[str, Any]] = []
|
|
elapsed = 0.0
|
|
manual_inputs = 0
|
|
auto_ticks = 0
|
|
failures = 0
|
|
retries: Dict[str, int] = {}
|
|
|
|
def roster_dps() -> float:
|
|
return sum(float(heroes[h]["base_dps"]) * (1.0 + 0.25 * (levels[h] - 1)) for h in unlocked)
|
|
|
|
# Returning profile: bounded offline gold before the first node.
|
|
offline_gold = 0
|
|
if profile.offline_seconds > 0:
|
|
capped = min(profile.offline_seconds, 8 * 3600)
|
|
# Authoritative rate lives in the shared rules file (same source as
|
|
# the Godot runtime); no duplicated balance number here.
|
|
offline_rate = float(
|
|
read_json(RULES_PATH)["progression"]["offline_gold_per_dps_second"]
|
|
)
|
|
offline_gold = int(capped * roster_dps() * offline_rate)
|
|
gold += offline_gold
|
|
decisions.append({"time": 0.0, "type": "offline_claim", "detail": f"+{offline_gold} gold"})
|
|
|
|
for node in content["nodes"]:
|
|
node_id = str(node["id"])
|
|
node_type = str(node.get("type", ""))
|
|
if node_type == "event":
|
|
choice_key = (EFFICIENT_EVENT if profile.event_strategy == "permanent" else WASTEFUL_EVENT)
|
|
choice = choice_key.get(node_id, "rescue")
|
|
gain_gold = 70 if choice in ("scavenge", "take") else 35
|
|
gain_crystal = 0 if choice in ("scavenge", "take") else (2 if node_id.endswith("N07") else 1)
|
|
gold += gain_gold
|
|
crystal += gain_crystal
|
|
decisions.append({
|
|
"time": round(elapsed, 1), "type": "event_choice",
|
|
"detail": f"{node_id}:{choice}",
|
|
})
|
|
nodes.append({
|
|
"node": node_id, "type": "event", "result": "resolved",
|
|
"at_sec": round(elapsed, 1), "gold": gold, "crystal": crystal,
|
|
})
|
|
continue
|
|
|
|
waves: List[List[str]] = node.get("waves", [])
|
|
won = False
|
|
node_duration = 0.0
|
|
for attempt in range(1, MAX_RETRIES + 1):
|
|
retries[node_id] = attempt
|
|
won = True
|
|
node_duration = 0.0
|
|
for wi, wave in enumerate(waves):
|
|
specs: Dict[str, Any] = {}
|
|
ids: List[str] = []
|
|
for enemy_id in wave:
|
|
enemy_id = str(enemy_id)
|
|
ids.append(enemy_id)
|
|
spec = enemies.get(enemy_id, boss if enemy_id.startswith("B-") else {})
|
|
specs[enemy_id] = {
|
|
"hp": float(spec.get("hp", spec.get("base_hp", 0.0))),
|
|
"armor": float(spec.get("armor", 1.0)),
|
|
"shield": float(spec.get("shield_max", 0.0)),
|
|
"weak_tag": str(spec.get("weak_tag", "")),
|
|
"rebuild_at": list(spec.get("rebuild_at", [])),
|
|
"rebuild_amount": float(spec.get("rebuild_amount", 0.0)),
|
|
}
|
|
inputs = build_inputs(profile, float(node["timeout_sec"]), node_type)
|
|
manual_inputs += len(inputs)
|
|
scenario = {
|
|
"id": node_id, "mode": "auto", "enemy_ids": ids, "enemy_specs": specs,
|
|
"visible_hero_ids": list(unlocked), "roster_hero_ids": list(unlocked),
|
|
"input_events": inputs,
|
|
"timeout_seconds": float(node.get("timeout_sec", 45.0)),
|
|
"hp_scale": float(node.get("hp_scale", 1.0)),
|
|
}
|
|
outcome = run_scenario(rules, scenario, seed + wi + attempt * 100, float(node["timeout_sec"]))
|
|
node_duration += float(outcome["duration_seconds"])
|
|
auto_ticks += int(round(node_duration / 0.1))
|
|
if outcome["result"] != "win":
|
|
won = False
|
|
failures += 1
|
|
break
|
|
if won:
|
|
break
|
|
# Retry recovery: spend gold on one upgrade, then try again.
|
|
choice = upgrade_choice(profile.upgrade_strategy, unlocked, levels, heroes, gold)
|
|
if choice and profile.retry_on_loss:
|
|
h, cost = choice
|
|
levels[h] += 1
|
|
gold -= cost
|
|
decisions.append({"time": round(elapsed + node_duration, 1),
|
|
"type": "retry_upgrade", "detail": f"{h} Lv.{levels[h]}"})
|
|
else:
|
|
break
|
|
|
|
if won:
|
|
gold += int(node.get("gold", 0))
|
|
crystal += int(node.get("crystal", 0))
|
|
decisions.append({"time": round(elapsed + node_duration, 1),
|
|
"type": "node_clear", "detail": node_id})
|
|
for unlock in node.get("unlocks", []):
|
|
if unlock not in unlocked:
|
|
unlocked.append(str(unlock))
|
|
levels[str(unlock)] = 1
|
|
decisions.append({"time": round(elapsed + node_duration, 1),
|
|
"type": "hero_unlock", "detail": str(unlock)})
|
|
# Spend between nodes until no further upgrade is affordable.
|
|
while True:
|
|
choice = upgrade_choice(profile.upgrade_strategy, unlocked, levels, heroes, gold)
|
|
if not choice:
|
|
break
|
|
h, cost = choice
|
|
levels[h] += 1
|
|
gold -= cost
|
|
decisions.append({"time": round(elapsed + node_duration, 1),
|
|
"type": "upgrade", "detail": f"{h} Lv.{levels[h]}"})
|
|
|
|
elapsed += node_duration
|
|
nodes.append({
|
|
"node": node_id, "type": node_type, "result": "win" if won else "loss",
|
|
"at_sec": round(elapsed, 1), "duration": round(node_duration, 1),
|
|
"dps": round(roster_dps(), 1), "gold": gold, "crystal": crystal,
|
|
"attempts": retries.get(node_id, 1),
|
|
})
|
|
|
|
# Derived metrics required by AGENTS.md.
|
|
decision_times = sorted(d["time"] for d in decisions)
|
|
longest_gap = 0.0
|
|
if len(decision_times) > 1:
|
|
longest_gap = max(b - a for a, b in zip(decision_times, decision_times[1:]))
|
|
decided_types = {d["type"] for d in decisions}
|
|
total_actions = manual_inputs + auto_ticks
|
|
active_share = round(manual_inputs / total_actions, 4) if total_actions else 0.0
|
|
|
|
# Dominant upgrade: most levels gained by one hero.
|
|
dominant = max(levels.items(), key=lambda kv: kv[1])[0] if levels else ""
|
|
|
|
return {
|
|
"profile": profile.name,
|
|
"seed": seed,
|
|
"nodes": nodes,
|
|
"decisions": decisions,
|
|
"metrics": {
|
|
"total_sec": round(elapsed, 1),
|
|
"nodes_cleared": sum(1 for n in nodes if n["result"] == "win" and n["type"] != "event"),
|
|
"decision_count": len(decisions),
|
|
"decision_types": sorted(decided_types),
|
|
"first_upgrade_sec": next((d["time"] for d in decisions if d["type"] == "upgrade"), None),
|
|
"first_event_choice_sec": next((d["time"] for d in decisions if d["type"] == "event_choice"), None),
|
|
"first_hero_unlock_sec": next((d["time"] for d in decisions if d["type"] == "hero_unlock"), None),
|
|
"longest_no_decision_sec": round(longest_gap, 1),
|
|
"active_input_share": active_share,
|
|
"manual_inputs": manual_inputs,
|
|
"auto_ticks": auto_ticks,
|
|
"failures": failures,
|
|
"offline_gold": offline_gold,
|
|
"final_gold": gold,
|
|
"final_crystal": crystal,
|
|
"dominant_upgrade": dominant,
|
|
"final_levels": dict(levels),
|
|
},
|
|
}
|
|
|
|
|
|
def main() -> int:
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument("--out", type=Path, default=OUT_PATH)
|
|
parser.add_argument("--seed", type=int, default=SEED)
|
|
args = parser.parse_args()
|
|
|
|
rules = Rules(read_json(RULES_PATH))
|
|
content = read_json(CONTENT_PATH)
|
|
runs = {name: simulate(content, rules, Profile(name), args.seed) for name in PROFILES}
|
|
|
|
report = {
|
|
"schema": 1,
|
|
"kind": "windroost_five_profile_pacing",
|
|
"source": "deterministic paper runner (same model as Godot runtime)",
|
|
"profiles": runs,
|
|
"contract": "AGENTS.md milestone acceptance: five pacing profiles and explicit decision timestamps",
|
|
}
|
|
args.out.write_text(json.dumps(report, ensure_ascii=False, indent=2, sort_keys=True) + "\n", encoding="utf-8")
|
|
|
|
print(f"{'profile':<13} {'clear':>5} {'total':>7} {'decide':>6} {'gap':>6} {'active':>7} {'fail':>4} {'offline':>7}")
|
|
for name in PROFILES:
|
|
m = runs[name]["metrics"]
|
|
print(
|
|
f"{name:<13} {m['nodes_cleared']:>5} {m['total_sec']:>7} {m['decision_count']:>6} "
|
|
f"{m['longest_no_decision_sec']:>6} {m['active_input_share']:>7} "
|
|
f"{m['failures']:>4} {m['offline_gold']:>7}"
|
|
)
|
|
print(f"\nwrote {args.out}")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|