-
Notifications
You must be signed in to change notification settings - Fork 66
Expand file tree
/
Copy pathMazeRunner.py
More file actions
106 lines (103 loc) · 4.09 KB
/
Copy pathMazeRunner.py
File metadata and controls
106 lines (103 loc) · 4.09 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
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
def maze_runner(maze, directions):
startX = 0 ; startY = 0
for y in range(len(maze)):
for x in range(len(maze)):
if maze[x][y] == 2:
startX = y
startY = x
for dire in directions:
if dire == "N": startY = startY - 1
if dire == "E": startX = startX + 1
if dire == "S": startY = startY + 1
if dire == "W": startX = startX -1
if startY < 0 or startY > len(maze)-1 or startX < 0 or startX > len(maze)-1 or maze[startY][startX] == 1: return "Dead"
if maze[startY][startX] == 3: return "Finish"
return "Lost"
# import random
# test.describe("Random tests")
#
# maze = [[1,1,1,1,1,1,1,1,0,1],
# [1,3,1,0,1,0,0,0,0,1],
# [1,0,1,0,0,0,1,1,0,1],
# [1,0,1,1,1,1,1,0,0,1],
# [1,0,1,0,0,0,0,0,0,1],
# [1,0,1,0,1,0,1,0,0,1],
# [1,0,1,0,1,0,0,0,0,0],
# [1,0,1,0,1,0,1,1,0,1],
# [1,0,0,0,1,0,0,0,0,1],
# [1,1,1,0,1,1,1,1,2,1]]
#
# test.describe("Example tests")
#
# test.it("Should return Finish")
# test.assert_equals(maze_runner(maze,["N","N","N","W","W","W","N","N","W","W","S","S","S","S","W","W","N","N","N","N","N","N","N"]), "Finish", "Should return Finish")
# test.it("Should return Lost")
# test.assert_equals(maze_runner(maze,["N","N","N","N","N","N","N","N","W","W","W","S","W","W","N"]), "Lost")
# test.it("Should return Dead")
# test.assert_equals(maze_runner(maze,["N","N","N","N","N","E","E","S","S","S","S","S","S"]), "Dead")
# test.it("Should return Dead")
# test.assert_equals(maze_runner(maze,["N","W","W","W","W"]), "Dead")
# test.it("Should return Lost")
# test.assert_equals(maze_runner(maze,["N","N","N","N","N","N","N","N","N","S","S","S","S","S","S","S","S","S"]), "Lost")
# test.it("Should return Dead")
# test.assert_equals(maze_runner(maze,["N","E","E"]), "Dead")
# test.it("Should return Finish")
# test.assert_equals(maze_runner(maze,["N","W","W","W","N","N","N","N","W","W","S","S","S","S","W","W","N","N","N","N","N","N","N","S","S"]), "Finish")
# test.it("Should return Lost")
# test.assert_equals(maze_runner(maze,["N","W","W","W","N","N"]), "Lost")
# test.it("Should return Lost")
# test.assert_equals(maze_runner(maze,["N","N","N","E"]), "Lost")
# test.it("Should return Dead")
# test.assert_equals(maze_runner(maze,["N","N","N","W","W","W","N","N","W","W","S","S","S","S","S","S"]), "Dead")
# test.it("Should return Finish")
# test.assert_equals(maze_runner(maze,["N","W","W","W","N","N","N","N","W","W","S","S","S","S","W","W","N","N","N","N","N","N","N"]), "Finish")
#
# def maze_runner2(maze, directions):
# startX = 0 ; startY = 0
# for y in range(len(maze)):
# for x in range(len(maze)):
# if maze[x][y] == 2:
# startX = y
# startY = x
#
# for dire in directions:
# if dire == "N": startY = startY - 1
# if dire == "E": startX = startX + 1
# if dire == "S": startY = startY + 1
# if dire == "W": startX = startX -1
# if startY < 0 or startY > len(maze)-1 or startX < 0 or startX > len(maze)-1 or maze[startY][startX] == 1: return "Dead"
# if maze[startY][startX] == 3: return "Finish"
#
# return "Lost"
#
# for rtest in range(139):
# maze = []
# l = random.randint(5, 7)
# for z in range(l):
# t = []
# t.extend([0] * l)
# maze.extend([t])
# w = random.randint(1, l*l-10)
# for z in range(w):
# x = random.randint(0,l-1)
# y = random.randint(0,l-1)
# maze[x][y] = 1
# x = random.randint(0,l-1)
# y = random.randint(0,l-1)
# maze[x][y] = 3
# x = random.randint(0,l-1)
# y = random.randint(0,l-1)
# maze[x][y] = 2
#
# directions = []
# m = random.randint(1,60)
# for x in range(0,m):
# d = random.randint(0,4)
# if d == 0: directions.extend("N")
# if d == 0: directions.extend("E")
# if d == 0: directions.extend("S")
# if d == 0: directions.extend("W")
#
# solution = maze_runner2(maze, directions)
# test.it("Should return "+solution)
# test.assert_equals(maze_runner(maze,directions), solution)