From ea105ad1404202d9fa532000a488abce74cf941c Mon Sep 17 00:00:00 2001 From: korzepadawid Date: Tue, 31 May 2022 22:13:16 +0200 Subject: [PATCH] fixed return type --- algorithms/genetic/common.py | 8 +++++--- algorithms/genetic/map_generator.py | 5 +++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/algorithms/genetic/common.py b/algorithms/genetic/common.py index 3f79021..e3f4cc5 100644 --- a/algorithms/genetic/common.py +++ b/algorithms/genetic/common.py @@ -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 diff --git a/algorithms/genetic/map_generator.py b/algorithms/genetic/map_generator.py index 060ebff..e90488f 100644 --- a/algorithms/genetic/map_generator.py +++ b/algorithms/genetic/map_generator.py @@ -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