genetic_alg #34

Merged
s464965 merged 18 commits from genetic_alg into master 2022-06-06 15:19:58 +02:00
4 changed files with 16 additions and 2 deletions
Showing only changes of commit 08329f187b - Show all commits

View File

@ -120,3 +120,12 @@ def find_neighbours(grid: npt.NDArray, col: int, row: int) -> List[Position]:
neighbours.append(Position(row=rr, col=cc))
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

View File

@ -7,7 +7,7 @@ from typing import List
import numpy as np
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 *
@ -72,6 +72,11 @@ class Genome:
score = SAND_COUNT + TREE_COUNT + WATER_COUNT
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
self.fitness = score

View File

@ -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, 0, 0, 0, 0, 2, 3, 0, 0, 0, 0], [0, 0, 0, 0, 0, 6, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 3, 0], [0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0], [2, 0, 1, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 3, 0, 1], [0, 0, 0, 6, 0, 0, 0, 6, 0, 1, 0, 1, 0, 0, 1, 1, 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