genetic_alg #34

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

View File

@ -35,17 +35,19 @@ def dfs(grid: npt.NDArray, visited: Dict[Tuple[int, int], bool], position: Posit
dfs(grid, visited, neighbour, rows, cols)
def count_islands(grid: npt.NDArray, positions: List[Position], rows: int = ROWS, cols: int = COLUMNS) -> int:
def get_islands(grid: npt.NDArray, positions: List[Position], rows: int = ROWS, cols: int = COLUMNS) -> List[Position]:
"""it returns list of all islands roots"""
visited = {}
for position in positions:
visited[(position.row, position.col)] = False
islands = 0
roots = []
for position in positions:
if not visited[(position.row, position.col)]:
dfs(grid, visited, position, rows, cols)
roots.append(position)
islands += 1
return islands
return roots

View File

@ -1,6 +1,6 @@
from map_importer_exporter import export_map
from genome import Genome
from common import count_islands
from common import get_islands
def main() -> None:
@ -8,7 +8,8 @@ def main() -> None:
print(example_genome.knights_red)
print(example_genome.knights_blue)
print(example_genome.grid)
print(count_islands(example_genome.grid, example_genome.sands + example_genome.waters))
islands = get_islands(example_genome.grid, example_genome.knights_red)
print(f'Roots {islands} and islands count {len(islands)}')
# export_map(example_genome.grid) fixme: FileNotFoundError