-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
119 lines (94 loc) · 3.25 KB
/
server.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
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
107
108
109
110
111
112
113
114
115
116
117
118
119
from flask import Flask, request, jsonify, render_template
from solver.base import Cube
from solver.solve import solve_cross, solve_f2l, solve_oll, solve_pll
app = Flask(__name__)
@app.route("/make_move", methods=["GET"])
def make_move():
# Process input data
cube_string = request.args.get('cube_string')
move = request.args.get('move')
# Run move
cube = Cube.from_string(cube_string)
cube.run_algorithm(move)
# Return output
data = {"cube_string": cube.to_string()}
response = jsonify(data)
response.headers.add('Access-Control-Allow-Origin', '*')
return response
@app.route("/mixup", methods=["GET"])
def mixup():
# Process input data
cube_string = request.args.get('cube_string')
# Run move
cube = Cube.from_string(cube_string)
cube.mix_up()
cube.simplify_move_history()
# Return output
data = {"cube_string": cube.to_string(), "moves": cube.move_history_as_string()}
response = jsonify(data)
response.headers.add('Access-Control-Allow-Origin', '*')
return response
@app.route("/solve/cross", methods=["GET"])
def solve_cross_endpoint():
# Process input data
cube_string = request.args.get('cube_string')
# Run move
cube = Cube.from_string(cube_string)
solve_cross(cube)
cube.simplify_move_history()
# Return output
data = {"cube_string": cube.to_string(), "moves": cube.move_history_as_string()}
response = jsonify(data)
response.headers.add('Access-Control-Allow-Origin', '*')
return response
@app.route("/solve/f2l", methods=["GET"])
def solve_f2l_endpoint():
# Process input data
cube_string = request.args.get('cube_string')
# Run move
cube = Cube.from_string(cube_string)
solve_cross(cube)
solve_f2l(cube)
cube.simplify_move_history()
# Return output
data = {"cube_string": cube.to_string(), "moves": cube.move_history_as_string()}
response = jsonify(data)
response.headers.add('Access-Control-Allow-Origin', '*')
return response
@app.route("/solve/oll", methods=["GET"])
def solve_oll_endpoint():
# Process input data
cube_string = request.args.get('cube_string')
# Run move
cube = Cube.from_string(cube_string)
solve_cross(cube)
solve_f2l(cube)
solve_oll(cube)
cube.simplify_move_history()
# Return output
data = {"cube_string": cube.to_string(), "moves": cube.move_history_as_string()}
response = jsonify(data)
response.headers.add('Access-Control-Allow-Origin', '*')
return response
@app.route("/solve/pll", methods=["GET"])
def solve_pll_endpoint():
# Process input data
cube_string = request.args.get('cube_string')
# Run move
cube = Cube.from_string(cube_string)
solve_cross(cube, minimize_moves=False)
solve_f2l(cube, minimize_moves=False)
solve_oll(cube)
cube._remove_cube_rotations_from_move_history()
solve_pll(cube)
cube.simplify_move_history()
# Return output
data = {"cube_string": cube.to_string(), "moves": cube.move_history_as_string()}
response = jsonify(data)
response.headers.add('Access-Control-Allow-Origin', '*')
return response
@app.route("/")
def index():
return render_template('index.html')
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000, debug=True)