-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboard.py
More file actions
50 lines (44 loc) · 1.59 KB
/
board.py
File metadata and controls
50 lines (44 loc) · 1.59 KB
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
from collections import OrderedDict
from graphics import *
from random import randint
def path_tiles(position, path_prob, window, px_size, padding, maze_prob, win):
"""
Generate tiles for the maze
:param position: coordinate of tile
:param path_prob: probability if path or obstacle
:param window: size of window
:param px_size: tile size
:param maze_prob: probability for obstacles
"""
x, y = position
rect = Rectangle(Point(x, y), Point(x + px_size, y + px_size))
if (x == padding and y == padding) or (x == window-px_size and y == window-px_size):
rect.setFill("red")
prob_value = False
else:
if path_prob >= maze_prob:
rect.setFill("white")
prob_value = False
else:
rect.setFill("black")
prob_value = True
rect.draw(win)
return prob_value
def build_maze(maze_prob, size):
"""
Get the maze size and generate maze
:param size: dimension of the maze
:param maze_prob: probability for obstacles
"""
board_tiles = OrderedDict()
px_size = 10
padding = 5
window = (px_size * size) + padding
win = GraphWin('Mazerunner', window + padding, window + padding)
for xpos in range(padding, window, px_size):
for ypos in range(padding, window, px_size):
path_prob = randint(0, 101) / 100
position = (xpos, ypos)
board_tiles[position] = path_tiles(position, path_prob, window, px_size, padding, maze_prob, win)
visited_cells = board_tiles.copy()
return visited_cells, window, padding, px_size, win