-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrecursive-test.py
78 lines (67 loc) · 1.85 KB
/
recursive-test.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
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
76
77
from maze1 import maze
import random
import pygame
import time
pygame.init()
x = 0
y = 0
size = 5
solution = [[0] * size for j in range(size)]
screen = pygame.display.set_mode([size*60,size*60])
screen.fill((255,255,255))
while True:
for r in range(0,size):
for c in range(0,size):
if maze[r][c] == 0:
color = (255,255,255)
elif maze[r][c] == 1:
color = (0,0,0)
elif maze[r][c] == 2:
color = (0,255,0)
elif maze[r][c] == 3:
color = (255,0,0)
pygame.draw.rect(screen, color, pygame.Rect(c*60,r*60,60,60))
pygame.display.flip()
pygame.draw.rect(screen,(0,0,255),pygame.Rect(x*60,y*60,60,60))
pygame.display.flip()
i = random.choice(("x", "y"))
print(i) # for debugging
if i == "x":
z = random.choice((-1,1))
x = x + z
print(x) # for debugging
if x < 0:
x = x - z
continue
elif x > size - 1:
x = x - z
continue
if maze[y][x] == 0:
solution[y][x] = maze[y][x]
elif maze[y][x] == 1:
solution[y][x] = maze[y][x]
x = x - z
print(solution) # for debugging
print(x)
if i == "y":
z = random.choice((-1,1))
y = y + z
print(y) # for debugging
if y < 0:
y = y - z
continue
elif y > size - 1:
y = y - z
continue
if maze[y][x] == 0:
solution[y][x] = maze[y][x]
elif maze[y][x] == 1:
solution[y][x] = maze[y][x]
y = y - z
print(solution) # for debugging
print(y)
if maze[y][x] == 3:
solution[y][x] = maze[y][x]
print(solution)
break
time.sleep(.5)