War council: guards march to other towns, one fight, then home; main assault

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rope 2026-11-04 16:56:24 +00:00
parent 2b04db3b31
commit a78274803b
5 changed files with 470 additions and 18 deletions

View file

@ -3850,6 +3850,197 @@ class KingdomTest(unittest.TestCase):
game.log(new, T0, "raid", "Trouble")
self.assertIn("Saltmere", self.world["ledger"][-1]["text"])
def garrisoned_home(self):
"""The capital with a full paid barracks and kit."""
city = self.world["city"]
city["buildings"]["barracks"]["level"] = 5
city["wages"] = game.guard_posts(self.world) * game.GUARD_WAGE
city["stockpile"].update(copper_sword=50)
for player in (self.a, self.b):
player["last_active"] = T0
def send(self, to, guards=30, now=T0):
self.a["last_active"] = self.b["last_active"] = now
self.assertIsNone(game.propose_march(self.world, self.a, game.HOME_CITY, to, guards, now))
return self.world["council"][-1]
def test_a_march_goes_on_a_majority_and_takes_kit_and_wage(self):
new = self.found()
self.garrisoned_home()
posts, wages = game.guards_on_duty(self.world), self.world["city"]["wages"]
proposal = self.send(new.here)
self.assertEqual(proposal["status"], "open")
self.assertIsNone(game.vote_march(self.world, self.b, proposal["id"], True, T0))
self.assertEqual(proposal["status"], "sent")
march = self.world["marches"][0]
self.assertEqual(march["guards"], 30)
self.assertEqual(march["kit"]["copper_sword"], 30)
self.assertEqual(self.world["city"]["stockpile"]["copper_sword"], 20)
self.assertEqual(self.world["city"]["wages"], wages - 30 * game.GUARD_WAGE)
self.assertEqual(game.guards_on_duty(self.world), posts - 30)
def test_the_votes_cast_decide_when_the_hour_is_up(self):
new = self.found()
self.garrisoned_home()
self.world["players"]["c"] = game.new_player("c", "Cy", "miner", T0)
self.world["players"]["d"] = game.new_player("d", "Di", "miner", T0)
proposal = self.send(new.here)
game.tick(self.world, T0 + game.VOTE_TIME - 1, random.Random(1))
self.assertEqual(proposal["status"], "open")
game.tick(self.world, T0 + game.VOTE_TIME, random.Random(1))
self.assertEqual(proposal["status"], "sent")
def test_a_tie_keeps_the_guards_home(self):
new = self.found()
self.garrisoned_home()
self.world["players"]["c"] = game.new_player("c", "Cy", "miner", T0)
self.world["players"]["d"] = game.new_player("d", "Di", "miner", T0)
proposal = self.send(new.here)
game.vote_march(self.world, self.b, proposal["id"], False, T0)
game.tick(self.world, T0 + game.VOTE_TIME, random.Random(1))
self.assertEqual(proposal["status"], "rejected")
self.assertEqual(self.world["marches"], [])
def test_one_march_per_town_before_the_council(self):
new = self.found()
self.garrisoned_home()
self.world["players"]["c"] = game.new_player("c", "Cy", "miner", T0)
self.world["players"]["d"] = game.new_player("d", "Di", "miner", T0)
self.send(new.here)
self.assertIn("already", game.propose_march(self.world, self.b, game.HOME_CITY, new.here, 5, T0))
def test_you_cant_send_more_than_are_paid_and_posted(self):
new = self.found()
self.garrisoned_home()
too_many = game.guards_on_duty(self.world) + 1
self.assertIn("paid", game.propose_march(self.world, self.a, game.HOME_CITY, new.here, too_many, T0))
def march(self, new, guards=30):
self.b["last_active"] = self.a["last_active"] = T0
proposal = self.send(new.here, guards)
game.vote_march(self.world, self.b, proposal["id"], True, T0)
return self.world["marches"][0]
def test_marching_guards_count_only_once_they_arrive(self):
new = self.found()
self.garrisoned_home()
march = self.march(new)
self.assertNotIn("reinforcements", game.defence(new)["parts"])
game._muster_tick(self.world, T0 + game.MARCH_TIME)
self.assertEqual(march["status"], "there")
self.assertEqual(game.defence(new)["parts"]["reinforcements"], game.march_power(march))
self.assertGreater(game.march_power(march), 0)
def test_posts_stay_empty_while_their_guards_are_away(self):
new = self.found()
self.garrisoned_home()
before = game.guards_on_duty(self.world)
self.march(new)
self.world["city"]["wages"] = 10**6
self.assertEqual(game.guards_on_duty(self.world), game.guard_posts(self.world) - 30)
self.assertLess(game.guards_on_duty(self.world), before)
def test_home_defence_falls_by_about_what_arrives(self):
new = self.found()
self.garrisoned_home()
home_before = game.defence(self.world)["total"]
march = self.march(new)
game._muster_tick(self.world, T0 + game.MARCH_TIME)
self.assertAlmostEqual(home_before - game.defence(self.world)["total"], game.march_power(march), delta=1)
def test_a_late_company_turns_back(self):
new = self.found()
self.garrisoned_home()
game.tick(self.world, T0 + 1, random.Random(4))
threat = game.upcoming_raid(new)
march = self.march(new)
march["for"] = threat["slot"]
threat["status"] = "done"
game._muster_tick(self.world, T0 + game.MARCH_TIME)
self.assertEqual(march["status"], "returning")
def test_after_the_fight_they_march_home_with_their_kit(self):
new = self.found()
self.garrisoned_home()
march = self.march(new)
game._muster_tick(self.world, T0 + game.MARCH_TIME)
now = T0 + game.MARCH_TIME + 10
lines = game._reinforcements_fought(new, 0.1, 0, now, random.Random(1))
self.assertIn("stood with us", lines[0])
self.assertEqual(march["status"], "returning")
self.assertLessEqual(march["kit"]["copper_sword"], 30)
left = march["kit"]["copper_sword"]
game._muster_tick(self.world, now + game.MARCH_TIME)
self.assertEqual(self.world["marches"], [])
self.assertEqual(self.world["city"]["stockpile"]["copper_sword"], 20 + left)
self.assertEqual(game.guards_away(self.world), 0)
def test_a_lost_fight_kills_guards_and_home_mourns(self):
new = self.found()
self.garrisoned_home()
march = self.march(new)
game._muster_tick(self.world, T0 + game.MARCH_TIME)
pop = self.world["city"]["population"]
lines = game._reinforcements_fought(new, 0.4, 0.5, T0 + game.MARCH_TIME, random.Random(1))
self.assertIn("fell", lines[0])
self.assertEqual(march["guards"], 30 - int(30 * 0.25))
self.assertEqual(self.world["city"]["population"], pop - int(30 * 0.25))
def test_reinforcements_turn_a_raid(self):
new = self.found()
self.garrisoned_home()
march = self.march(new)
game._muster_tick(self.world, T0 + game.MARCH_TIME)
now = T0 + game.MARCH_TIME + 5
new["events"].append({"id": 901, "kind": "raid", "status": "upcoming", "fire_at": now, "slot": now, "strength": game.defence(new)["total"] - 1,
"sabotage": 0.0, "recon": 0, "jitter": 0, "group": "the Red Hand", "trait": "x", "announced": T0})
self.world["bank_risk_after"] = now + 1
game.tick(self.world, now, random.Random(1))
report = next(e for e in new["events"] if e["id"] == 901)["report"]
self.assertTrue(report["title"].startswith("Victory"))
self.assertGreater(report["parts"]["reinforcements"], 0)
self.assertEqual(march["status"], "returning")
def big_towns(self):
new = self.found()
new["city"]["tier"] = game.MAIN_TIER
new["city"]["population"] = 90.0
return new
def test_main_assault_keeps_the_kingdom_total(self):
new = self.big_towns()
total = sum(game.threat_base(world, T0) for world in (self.world, new))
shifts = []
for world in (self.world, new):
base = game.threat_base(world, T0)
shifts.append(base + game._assault_shift(world, {"slot": 1234.0}, base, T0))
self.assertAlmostEqual(sum(shifts), total)
def test_every_town_agrees_who_takes_the_main_assault(self):
new = self.big_towns()
for slot in range(40):
events = [{"slot": float(slot)}, {"slot": float(slot)}]
game._assault_shift(self.world, events[0], game.threat_base(self.world, T0), T0)
game._assault_shift(new, events[1], game.threat_base(new, T0), T0)
self.assertNotEqual(events[0]["main"], events[1]["main"])
def test_main_assault_needs_two_big_towns(self):
new = self.found()
event = {"slot": 1.0}
self.assertEqual(game._assault_shift(self.world, event, 100.0, T0), 0.0)
self.assertEqual(game._assault_shift(new, event, 100.0, T0), 0.0)
self.assertNotIn("main", event)
def test_scouts_only_spot_the_main_assault_at_full_intel(self):
new = self.big_towns()
game.tick(self.world, T0 + 1, random.Random(4))
threat = game.upcoming_raid(new) or game.upcoming_raid(self.world)
threat["main"] = True
world = new if threat in new["events"] else self.world
self.assertNotIn("main", game.event_view(world, threat, T0 + 1))
threat["recon"] = 10**6
self.assertIn("main", game.event_view(world, threat, threat["fire_at"] - 3600))
def test_old_saves_gain_towns(self):
doc = json.loads(json.dumps(self.world.doc))
doc["version"] = 39