Created
May 23, 2020 20:53
-
-
Save JohnnyJayJay/37b8cdf5d6a3750f82dd732274c87631 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def add_adjacent_tiles(grid, room, x, y): | |
| room.append((x, y)) | |
| grid[x][y] = 'C' | |
| adjacent_tile_positions = [(x + 1, y), (x - 1, y), (x, y + 1), (x, y - 1)] | |
| for (x, y) in adjacent_tile_positions: | |
| if x < len(grid) and y < len(grid[x]) and grid[x][y] == 'R': | |
| add_adjacent_tiles(grid, room, x, y) | |
| return tiles | |
| def group_tiles_to_rooms(grid): | |
| rooms = [] | |
| for x in range(len(grid)): | |
| for y in range(len(grid[x])): | |
| if grid[x][y] == 'R': | |
| room = [] | |
| add_adjacent_tiles(grid, room, x, y) | |
| rooms.append(room) | |
| return rooms | |
| grid = list(map(lambda x: list(x), """ | |
| 0RRRROOOOOOOOOOO | |
| ORRRO0000OO00OOO | |
| ORR0O00RRR000OOO | |
| OOORRRRRRROO0OOO | |
| OOOOOOORROOO0000 | |
| """.strip().split("\n"))) | |
| print(group_tiles(grid)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment