Only donate what the city uses; sell useless overflow

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rope 2026-10-18 22:40:36 +01:00
parent e3a5f519fc
commit b82f979b4c
3 changed files with 63 additions and 7 deletions

View file

@ -109,6 +109,28 @@ class ActionTest(unittest.TestCase):
self.assertEqual(p["favour"], 1.5) # half favour for overflow
self.assertEqual(p["donated"], 3)
def test_full_bank_sells_what_the_city_cannot_use(self):
world = world_with(("fred", "warrior"))
p = world["players"]["fred"]
p["bank"] = {"copper_ore": game.BASE_STACK - 1}
game.start_action(world, p, "mine_copper", T0)
summary = game.process_player(world, p, T0 + 100, random.Random(1))
self.assertEqual(summary["sold"], {"copper_ore": 3})
self.assertEqual(p["gold"], 3 * game.ITEMS["copper_ore"]["value"])
self.assertNotIn("copper_ore", world["city"]["stockpile"])
self.assertEqual(p["favour"], 0)
def test_only_useful_things_can_be_donated(self):
world = world_with(("fred", "warrior"))
p = world["players"]["fred"]
p["bank"] = {"copper_ore": 10, "bricks": 10, "bread": 5, "iron_helmet": 1, "steel_sword": 1}
self.assertEqual(game.donate(world, p, "copper_ore", 10, T0), "The city has no use for that")
self.assertEqual(game.donate(world, p, "iron_helmet", 1, T0), "The city has no use for that")
for item, qty in (("bricks", 10), ("bread", 5), ("steel_sword", 1)):
self.assertIsNone(game.donate(world, p, item, qty, T0))
self.assertIn("Walls", game.city_uses("bricks"))
self.assertEqual(game.city_uses("bread"), ["the granary"])
def test_full_bank_can_stop_instead(self):
world = world_with(("fred", "warrior"))
p = world["players"]["fred"]