fixed return type #30
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user