forked from s464965/WMICraft
fix monsters count;
This commit is contained in:
parent
ee7a324e5d
commit
fd081d5c56
@ -120,3 +120,12 @@ def find_neighbours(grid: npt.NDArray, col: int, row: int) -> List[Position]:
|
|||||||
neighbours.append(Position(row=rr, col=cc))
|
neighbours.append(Position(row=rr, col=cc))
|
||||||
|
|
||||||
return neighbours
|
return neighbours
|
||||||
|
|
||||||
|
|
||||||
|
def count_in_grid(grid: npt.NDArray, target) -> int:
|
||||||
|
count = 0
|
||||||
|
for row in grid:
|
||||||
|
for col in row:
|
||||||
|
if col == target:
|
||||||
|
count += 1
|
||||||
|
return count
|
||||||
|
@ -7,7 +7,7 @@ from typing import List
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
import numpy.typing as npt
|
import numpy.typing as npt
|
||||||
|
|
||||||
from common import Position, get_islands, AREAS_TO_CROSS, find_neighbours
|
from common import Position, get_islands, AREAS_TO_CROSS, find_neighbours, count_in_grid
|
||||||
from const import *
|
from const import *
|
||||||
|
|
||||||
|
|
||||||
@ -72,6 +72,11 @@ class Genome:
|
|||||||
score = SAND_COUNT + TREE_COUNT + WATER_COUNT
|
score = SAND_COUNT + TREE_COUNT + WATER_COUNT
|
||||||
score = score - len(self.sand_islands) - len(self.tree_islands) - len(self.water_islands)
|
score = score - len(self.sand_islands) - len(self.tree_islands) - len(self.water_islands)
|
||||||
|
|
||||||
|
monsters_count = count_in_grid(self.grid, MAP_ALIASES.get('MONSTER'))
|
||||||
|
if monsters_count < 2:
|
||||||
|
self.fitness = 0
|
||||||
|
return
|
||||||
|
|
||||||
# todo: odległość manhattan od każdej wyspy
|
# todo: odległość manhattan od każdej wyspy
|
||||||
|
|
||||||
self.fitness = score
|
self.fitness = score
|
||||||
|
@ -1 +0,0 @@
|
|||||||
{"map": [[0, 3, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 2, 0, 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