-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement probability distribution calculation
- Loading branch information
Showing
7 changed files
with
86 additions
and
8 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from catan.balance.probability_distribution import measure_probability_distribution | ||
from catan.balance.resource_clustering import measure_resource_clustering | ||
from catan.balance.resource_distribution import measure_resource_distribution | ||
|
||
|
||
# The process behind each of these methods was inspired by Board Game Analysis's blog post: | ||
# https://www.boardgameanalysis.com/what-is-a-balanced-catan-board/ | ||
|
||
def calculate_balance(board): | ||
resource_distribution_score = measure_resource_distribution(board) | ||
resource_clustering_score = measure_resource_clustering(board) | ||
probability_distribution_score = measure_probability_distribution(board) | ||
return resource_distribution_score |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from catan.board.terrain_hexes import terrain_hex_distribution, TerrainType | ||
|
||
|
||
def measure_probability_distribution(board): | ||
# There are 58 total dots across all of the number tiles (the dots being those under the number) | ||
total_num_dots = 58 | ||
|
||
# Calculates how many TerrainHexes there are, excluding the desert | ||
total_num_hexes = sum(list(terrain_hex_distribution.values())) - terrain_hex_distribution['DESERT'] | ||
|
||
# Using this number and the terrain_hex_distribution, we can calculate the expected payout of each TerrainType | ||
# (minus TerrainType.DESERT) based on how many TerrainHexes with that TerrainType are on the board | ||
expected_payouts = {terrain_type: terrain_hex_distribution[terrain_type] * total_num_dots / total_num_hexes for | ||
terrain_type in list(terrain_hex_distribution.keys()) if terrain_type != 'DESERT'} | ||
|
||
# Count the total number of dots per resource | ||
terrain_dot_counts = {terrain_type: 0 for terrain_type in list(expected_payouts.keys())} | ||
|
||
# Iterate over every NumberToken (to do this we must iterate over every TerrainHex) | ||
for terrain_hex_row in board.hexes: | ||
for terrain_hex in terrain_hex_row: | ||
if terrain_hex.terrain_type != TerrainType.DESERT: | ||
number_token = terrain_hex.number_token | ||
terrain_dot_counts[terrain_hex.terrain_type.name] += number_token.dot_count | ||
|
||
# Calculate the sum of the squares of the differences between actual dots counts and the expected payout | ||
return sum({terrain_type: (expected_payouts[terrain_type] - terrain_dot_counts[terrain_type]) ** 2 | ||
for terrain_type in list(expected_payouts.keys())}.values()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters