-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopen_labyrinth.py
More file actions
87 lines (81 loc) · 3.73 KB
/
open_labyrinth.py
File metadata and controls
87 lines (81 loc) · 3.73 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
__author__ = 'k22li'
"""
The labyrinth has no walls, but pits surround the path on each side. If a player falls into a pit, they lose. The labyrinth is presented as a matrix (a list of lists): 1 is a pit and 0 is part of the path. The labyrinth's size is 12 x 12 and the outer cells are also pits. Players start at cell (1,1). The exit is at cell (10,10). You need to find a route through the labyrinth. Players can move in only four directions--South (down [1,0]), North (up [-1,0]), East (right [0,1]), West (left [0, -1]). The route is described as a string consisting of different characters: "S"=South, "N"=North, "E"=East, and "W"=West.
open-labyrinth
Input: A labyrinth's map. A list of lists with 1 and 0.
Output: A route. A string that contain "W", "E", "N" and "S"." \
"""
#Your code here
#You can import some modules or create additional functions
def checkio(data):
#Your code here
#It's main function. Don't remove this function
#It's using for auto-testing and must return a result for check.
col = row = 1
startPoint = data[col][row]
sum = start
print startPoint
#replace this for solution
#This is just example for first maze
return "SSSSSEENNNEEEEEEESSWWWWSSSEEEESS"
#Some hints
#Look to graph search algorithms
#Don't confuse these with tree search algorithms
#This code using only for self-checking and not necessary for auto-testing
if __name__ == '__main__':
print(checkio([
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
[1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1],
[1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1],
[1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1],
[1, 0, 1, 0, 1, 0, 0,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