forked from noops-challenge/mazebot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
75 lines (62 loc) · 1.87 KB
/
main.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
from Maze import Maze
import requests
import json
def get(path):
baseURL = "https://api.noopschallenge.com"
url = "".join([baseURL, path])
res = requests.get(url)
return res.json()
def post(path, json):
baseURL = "https://api.noopschallenge.com"
url = "".join([baseURL, path])
res = requests.post(url, json=json)
return res.json()
def postSolution(solution, postPath):
return post(postPath, {"directions": solution})
def getSampleMaze(path):
with open(path) as handle:
sampleMazeJSON = json.load(handle)
return sampleMazeJSON
def getRandomMaze(minSize, maxSize):
basePath = "/mazebot/random"
args = ""
if (minSize and maxSize):
args = f"?minSize={minSize}&maxSize={maxSize}"
path = "".join([basePath, args])
return get(path)
def startRace(username):
path = "/mazebot/race/start"
startingMazeUrl = post(path, {"login": username})["nextMaze"]
maze = Maze(get(startingMazeUrl))
print(maze.mazePath)
solution = maze.solve()
print(solution)
res = postSolution(solution, maze.mazePath)
nextMaze = res["nextMaze"]
while nextMaze:
maze = Maze(get(nextMaze))
print(maze.mazePath)
solution = maze.solve()
print(solution)
res = postSolution(solution, maze.mazePath)
print(res)
nextMaze = res["nextMaze"]
def doSolveRandomMaze(minSize = 60, maxSize = 60):
maze = Maze(getRandomMaze(minSize,maxSize))
solution = maze.solve()
print(solution)
res = postSolution(solution, maze.mazePath)
print(res)
def doRaceChallenge(username = "bcowell"):
startRace(username)
def doSolveSampleMaze():
path = "sampleMaze.json"
maze = Maze(getSampleMaze(path))
solution = maze.solve()
print(solution)
def main():
#doSolveRandomMaze()
#doRaceChallenge()
doSolveSampleMaze()
if __name__ == "__main__":
main()