1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import random
def generate_random_grid(n: int, m: int) -> list[list[str]]:
"""
Returns a random n x m grid filled with spaces and W's
with equal probabilities.
Args:
n (int): the number of rows
m (int): the number of columns
Returns:
list[list[str]]: the randomly generated grid
"""
...
def all_coordinates(grid: list[list[str]]) -> list[tuple[int, int]]:
"""
Returns a list of all possible valid coordinates into the provided
grid.
Args:
grid (list[list[str]]): the provided grid
Returns:
list[tuple[int, int]]: a list of valid coordinates into grid
"""
...
def find_random_empty(grid: list[list[str]]) -> tuple[int, int]:
"""
Returns a random pair of coordinates into grid that currently
point to a space.
Args:
grid (list[list[str]]): the grid to search
Returns:
tuple[int, int]: the found pair of coordinates pointing to empty
"""
...
def get_all_directions(coord: tuple[int, int], grid: list[list[str]]) -> set[tuple[int, int]]:
"""
Returns a set of coordinate pairs that represent valid coordinates into grid that
are directly next to the provided `coord`.
Args:
coord (tuple[int, int]): the coordinate pair to look near
grid (list[list[str]]): the grid to look into
Returns:
set[tuple[int, int]]: a set of coordinate pairs of all valid coordinates near `coord`
"""
DIRS: list[tuple[int, int]] = [(0, 1), (1, 0), (0, -1), (-1, 0)]
...
def flood_fill(grid: list[list[str]], coord: tuple[int, int]) -> None:
"""
Repeatedly fills in empty cells in grid with `o`, starting from `coord`
until there are no empty cells reachable from `coord`.
Args:
grid (list[list[str]]): the grid to flood fill
coord (tuple[int, int]): the coordinate pair to start at
Raises:
ValueError: if the coord doesn't point to an empty square
"""
...