speed up check_nobles_for_player

This commit is contained in:
2025-11-16 15:30:11 -05:00
parent 55e652a51d
commit 6ce622e93e

View File

@@ -331,6 +331,14 @@ def enforce_token_limit(
game.bank[color] += amount game.bank[color] += amount
def _check_nobles_for_player(player: PlayerState, noble: Noble) -> bool:
# this rule is slower
for color, cost in noble.requirements.items(): # noqa: SIM110
if player.discounts[color] < cost:
return False
return True
def check_nobles_for_player( def check_nobles_for_player(
game: GameState, game: GameState,
strategy: Strategy, strategy: Strategy,
@@ -340,11 +348,7 @@ def check_nobles_for_player(
if game.noble_min_requirements > max(player.discounts.values()): if game.noble_min_requirements > max(player.discounts.values()):
return return
candidates = [ candidates = [noble for noble in game.available_nobles if _check_nobles_for_player(player, noble)]
noble
for noble in game.available_nobles
if all(player.discounts.get(color, 0) >= requirement for color, requirement in noble.requirements.items())
]
if not candidates: if not candidates:
return return