Skip to content

Commit

Permalink
Simplify logic in 'get_player_port_resources'.
Browse files Browse the repository at this point in the history
  • Loading branch information
tonypr committed Dec 1, 2023
1 parent 9cf9194 commit 9aa9025
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions catanatron_core/catanatron/models/board.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 9aa9025

Please sign in to comment.