-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexample.py
47 lines (38 loc) · 913 Bytes
/
example.py
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
import shadowcasting
# Minimal shadowcasting example
map_str = '''
##################
#................#
#...###..........#
#...###....#.....#
#...###....#.....#
#..........#.....#
##################
'''[1:] # Use [1:] to remove first newline
width = 18
height = 7
player_location = (9, 3)
map_list = list(map_str.splitlines())
def is_blocking(x, y):
return map_list[y][x] == '#'
is_visible = set()
def reveal(x, y):
is_visible.add((x, y))
shadowcasting.compute_fov(player_location, is_blocking, reveal)
for y in range(height):
for x in range(width):
if (x, y) == player_location:
print('@', end='')
elif (x, y) in is_visible:
print(map_list[y][x], end='')
else:
print(' ', end='')
print()
# expected output:
# ##############
# ............#
# #.......
# #..@.#
# #....#
# ......#
# ########