Browse Source

Add scoring function 📈

pull/1/head
Jeroen Overschie 4 years ago
parent
commit
7e33c772eb
No known key found for this signature in database
GPG Key ID: 3C6628AF1BF86633
  1. 31
      common/score_evaluation.py
  2. 3
      quick_start.ipynb

31
common/score_evaluation.py

@ -122,3 +122,34 @@ def drop_blocks(field: Field, blocks: List[Block], solution: Solution) -> None: @@ -122,3 +122,34 @@ def drop_blocks(field: Field, blocks: List[Block], solution: Solution) -> None:
for block_id, block_position in zip(solution.block_ids, solution.block_positions):
drop_block(field, blocks[block_id], block_position)
def score_row(row: np.array, rewards: Rewards) -> int:
def color_points(row: list, rewards: Rewards) -> int:
score = 0
for color in row:
if color == "":
score -= 1
else:
score += rewards.points[color]
return score
def multiplication_factor_for_full_color_row(row: list, rewards: Rewards) -> int:
if row[0] != "" and len(set(row)) == 1:
return rewards.multiplication_factors[row[0]]
return 1
full_row = not any(row == "")
empty_row = "".join(row) == ""
score = 0
if not empty_row:
score += color_points(row, rewards)
if full_row:
score *= multiplication_factor_for_full_color_row(row, rewards)
return score
def score_solution(field: Field, rewards: Rewards) -> int:
score = 0
for row in field.values:
score += score_row(row, rewards)
return score

3
quick_start.ipynb

@ -44,7 +44,8 @@ @@ -44,7 +44,8 @@
" parse_puzzle,\n",
" write_solution,\n",
" drop_block,\n",
" drop_blocks\n",
" drop_blocks,\n",
" score_solution,\n",
")"
]
},

Loading…
Cancel
Save