From 9aa9025e4d942c16688c007359c88f4f39dc71cb Mon Sep 17 00:00:00 2001 From: tonypr Date: Sat, 4 Nov 2023 12:30:28 -0400 Subject: [PATCH] Simplify logic in 'get_player_port_resources'. --- catanatron_core/catanatron/models/board.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/catanatron_core/catanatron/models/board.py b/catanatron_core/catanatron/models/board.py index 327e3c2d..ff2d97d1 100644 --- a/catanatron_core/catanatron/models/board.py +++ b/catanatron_core/catanatron/models/board.py @@ -274,9 +274,8 @@ def get_player_port_resources(self, color): resources = set() for resource, node_ids in self.map.port_nodes.items(): - for node_id in node_ids: - if self.get_node_color(node_id) == color: - resources.add(resource) + if any(self.is_friendly_node(node_id, color) for node_id in node_ids): + resources.add(resource) self.player_port_resources_cache[color] = resources return resources @@ -341,6 +340,9 @@ def is_enemy_road(self, edge, color): edge_color = self.get_edge_color(edge) return edge_color is not None and self.get_edge_color(edge) != color + def is_friendly_node(self, node_id, color): + return self.get_node_color(node_id) == color + def is_friendly_road(self, edge, color): return self.get_edge_color(edge) == color