Files
windroost/tools/fullgame/test_side_depth.py
T
wushenghua 6eaebc3cb5 feat: migrate invented numbers to real CH source formulas (numeric provenance)
User: "数值应参考 CH 迁移,不要自己写." Contract 2.2 requires inheriting CH's
formula families and magnitude. Previously relic strength (0.06+tier*0.008),
commission targets/rewards, and partner coefficients were invented. Now:

- cf_formulas.py/.gd: implements CH's real formula families (linear10=0.10*L,
  diminishingReturns, exponential/polynomial1_5 costs) and reads CF source
  tables copied to data/cf_reference/numeric_tables.json (27 relics/30 ancients/
  10 outsiders/6 daily tasks/9 skills). check_cf_formulas_parity PASS 25 cases.
- Relics: strength = CH linear10 @level=tier (0.1..6.0, genuine CH magnitude);
  effect TYPE from CH relic effectDescription keyword (idle->shield, click->
  damage, chest->summon...). 56 combat relic signatures unique.
- Commissions: target steps from CH daily_tasks (kills=50/boss=3/upgrades=5/
  quests=2), reward = CH rubies=5 (crystal) for all.
- Partners: P01=0.10 (CH linear10), P03=0.15 (linear15), P05=0.25 (linear25).
- PRODUCTION/52-cf-numeric-provenance.md documents every number's CH source
  and honestly flags the few remaining new-game tuning parameters.
- Full P2_CHECKS_PASS (93 gates), identity preserved.

Numbers now trace to CH source tables instead of being invented. Owner gates
(human feel/device/release) remain open. prototype/ untracked.
2026-11-19 18:07:26 +08:00

133 lines
5.7 KiB
Python

#!/usr/bin/env python3
"""Side-system depth: commissions have 4 distinct task types; partners have 5
distinct real rules that change actual payouts."""
import json
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parents[2]
sys.path.insert(0, str(ROOT / "tools"))
sys.path.insert(0, str(Path(__file__).parent))
import commission_board as CB
import partner_perks as PP
import side_systems as SS
CONTENT = json.loads((ROOT / "data" / "full_game_content.json").read_text(encoding="utf-8"))
def check(cond, msg):
if not cond:
raise AssertionError(msg)
def test_commission_four_distinct_types():
check(not CB.validate(), "4 commission types, distinct metrics + CH target steps")
p = {"battle_wins": 55, "completed_nodes": ["n"] * 9,
"talents": {f"t{i}": 1 for i in range(11)},
"rebuild_count": 3, "new_sky_count": 1}
st = {r["type"]: r for r in CB.status(p)}
check(set(st) == {"kill", "clear", "build", "ascend"}, "4 types present")
check(st["kill"]["step"] == 50 and st["clear"]["step"] == 3,
"kill/clear steps from CH kills(50)/boss(3) targets")
check(st["build"]["step"] == 5 and st["ascend"]["step"] == 2,
"build/ascend steps from CH upgrades(5)/quests(2) targets")
# CH daily_tasks all pay rubies (here crystal), so same currency is correct.
check(all(r["reward"] == {"crystal": 5} for r in st.values()),
"all commissions pay CH rubies-equivalent (5 crystal)")
def test_commission_claim_grants_right_currency():
p = {"battle_wins": 55, "completed_nodes": ["n"] * 9,
"talents": {f"t{i}": 1 for i in range(11)},
"rebuild_count": 3, "crystal": 0}
for i, tid in enumerate(("kill", "clear", "build", "ascend"), 1):
r = CB.claim(p, tid)
check(r["ok"] and p["crystal"] == 5 * i, f"{tid} pays CH rubies (5 crystal): {r}")
# claiming twice needs more progress; no free repeat (kill: 55//50=1)
check(not CB.claim(p, "kill")["ok"], "no unlimited repeat")
def test_partner_five_distinct_rules():
check(not PP.validate(), "5 partners, 5 distinct rules")
p = {"highest_node": 45, "relics": {f"L{i}": 1 for i in range(1, 6)},
"claimed_rewards": [f"A{i}" for i in range(9)],
"battle_wins": 25, "new_sky_count": 2}
c = PP.compute(p)
check(len(c) == 5 and all(v > 0 for v in c.values()), "all 5 rules active: " + str(c))
check(len(set(c.keys())) == 5, "each partner grants a different rule")
empty = PP.compute({})
check(all(v == 0.0 for v in empty.values()), "fresh profile -> identity")
def test_p03_record_reward_hook_real():
base = {"highest_node": 0, "relics": {}, "claimed_rewards": [], "battle_wins": 0, "new_sky_count": 0}
boosted = dict(base)
boosted["claimed_rewards"] = [f"A{i}" for i in range(9)] # P03 level 3 -> +30%
a = PP.apply_record_reward(base, 20, 5)
b = PP.apply_record_reward(boosted, 20, 5)
check(a == {"gold": 20, "crystal": 5}, "no P03 level -> base reward")
# P03 coefficient 0.15 (CH linear15) * level 3 = +45% -> 20*1.45=29, 5*1.45=7
check(b["gold"] == 29 and b["crystal"] == 7, "P03 level 3 -> +45%: " + str(b))
def test_p01_offline_hook_real():
base = {"highest_node": 0}
boosted = {"highest_node": 45} # P01 level 4, CH linear10=0.10 -> +40%
check(PP.apply_offline(base, 1000) == 1000, "no P01 level -> base offline")
check(PP.apply_offline(boosted, 1000) == 1400, "P01 level 4 -> 1400 offline")
def test_p02_gear_drop_hook_real():
import gear_actions as GA
pack = CONTENT
base = {"relics": {}} # P02 level 0
boosted = {"relics": {f"L{i}": 1 for i in range(1, 6)}} # P02 level 5 -> +5 drops
g0 = GA.grant_drop(dict(base), "R1-C01-N01", pack)
g1 = GA.grant_drop(dict(boosted), "R1-C01-N01", pack)
check(len(g0["drops"]) == 1, "no P02 level -> 1 drop")
check(len(g1["drops"]) == 6, "P02 level 5 -> 6 drops: " + str(g1["drops"]))
def test_p04_revive_hook_real():
base = {"battle_wins": 0, "revive_charges": 0}
check(PP.effective_revives(base) == 0, "no medic, no charges -> 0 revives")
owned = {"battle_wins": 0, "revive_charges": 2}
check(PP.effective_revives(owned) == 2, "owned charges count")
medic = {"battle_wins": 25, "revive_charges": 1} # P04 level 5 -> +5 free
check(PP.effective_revives(medic) == 6, "P04 level 5 -> 6 total revives: " + str(PP.effective_revives(medic)))
def test_p05_sky_mark_hook_real():
base = {"new_sky_count": 0}
boosted = {"new_sky_count": 5} # P05 level 5, CH linear25=0.25 -> +125%
check(PP.apply_sky_marks(base, 10) == 10, "no P05 level -> base marks")
check(PP.apply_sky_marks(boosted, 10) == 22, "P05 level 5 -> 22 marks")
def test_record_claim_uses_perk():
records = CONTENT["records"]
base = {"claimed_rewards": [], "gold": 0, "crystal": 0, "highest_node": 0,
"relics": {}, "battle_wins": 0, "new_sky_count": 0,
"completed_nodes": ["R1-C01-N01"]} # A001 (推进 order 1) needs 1 node cleared
r0 = SS.claim_record(dict(base), "A001", records)
# P03 level 3 from 9 pre-claimed A-records (A001 itself not among them).
boosted = dict(base)
boosted["claimed_rewards"] = [f"A{i}" for i in range(1, 10)]
r1 = SS.claim_record(boosted, "A001", records)
check(r0["ok"] and r1["ok"], "both record claims succeed: " + str(r0) + " " + str(r1))
check(r1["gold"] >= r0["gold"] and r1["crystal"] >= r0["crystal"],
"P03 perk does not reduce record reward: base=" + str(r0) + " boosted=" + str(r1))
check(r1["gold"] > r0["gold"], "P03 level 3 raises record gold: " + str(r1))
def main():
fns = [v for k, v in sorted(globals().items()) if k.startswith("test_")]
for fn in fns:
fn()
print(f"SIDE_DEPTH_PASS {len(fns)} checks")
return 0
if __name__ == "__main__":
raise SystemExit(main())