Skip to content

Commit

Permalink
Fix adjacent-same-resource tile production bug (#264)
Browse files Browse the repository at this point in the history
  • Loading branch information
bcollazo committed Dec 1, 2023
1 parent d24e1e2 commit fb34b6f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
16 changes: 8 additions & 8 deletions catanatron_core/catanatron/models/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,15 +290,15 @@ def init_node_production(
return node_production


def get_node_counter_production(adjacent_tiles, node_id):
def get_node_counter_production(
adjacent_tiles: Dict[int, List[LandTile]], node_id: NodeId
):
tiles = adjacent_tiles[node_id]
return Counter(
{
t.resource: number_probability(t.number)
for t in tiles
if t.resource is not None
}
)
production = defaultdict(float)
for tile in tiles:
if tile.resource is not None:
production[tile.resource] += number_probability(tile.number)
return Counter(production)


def build_dice_probas():
Expand Down
15 changes: 15 additions & 0 deletions tests/models/test_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,24 @@
CatanMap,
LandTile,
get_nodes_and_edges,
get_node_counter_production,
DICE_PROBAS,
)


def test_node_production_of_same_resource_adjacent_tile():
# See https://github.com/bcollazo/catanatron/issues/263.
adjacent_tiles = {
1: [
LandTile(1, WOOD, 8, dict(), dict()),
LandTile(2, WOOD, 6, dict(), dict()),
LandTile(3, WOOD, 12, dict(), dict()),
]
}
result = get_node_counter_production(adjacent_tiles, 1)
assert result["WOOD"] == DICE_PROBAS[12] + DICE_PROBAS[6] + DICE_PROBAS[8]


def test_mini_map_can_be_created():
mini = CatanMap.from_template(MINI_MAP_TEMPLATE)
assert len(mini.land_tiles) == 7
Expand Down

0 comments on commit fb34b6f

Please sign in to comment.