fixed return type

This commit is contained in:
korzepadawid 2022-05-31 22:13:16 +02:00
parent 32847593e6
commit ea105ad140
2 changed files with 8 additions and 5 deletions

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) 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 = {} visited = {}
for position in positions: for position in positions:
visited[(position.row, position.col)] = False visited[(position.row, position.col)] = False
islands = 0 islands = 0
roots = []
for position in positions: for position in positions:
if not visited[(position.row, position.col)]: if not visited[(position.row, position.col)]:
dfs(grid, visited, position, rows, cols) dfs(grid, visited, position, rows, cols)
roots.append(position)
islands += 1 islands += 1
return islands return roots

View File

@ -1,6 +1,6 @@
from map_importer_exporter import export_map from map_importer_exporter import export_map
from genome import Genome from genome import Genome
from common import count_islands from common import get_islands
def main() -> None: def main() -> None:
@ -8,7 +8,8 @@ def main() -> None:
print(example_genome.knights_red) print(example_genome.knights_red)
print(example_genome.knights_blue) print(example_genome.knights_blue)
print(example_genome.grid) 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 # export_map(example_genome.grid) fixme: FileNotFoundError