-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
119 lines (84 loc) · 2.77 KB
/
app.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, render_template, url_for, request, jsonify
import json
import math
import tiles
import tilesSearch
import idastar
from db import helper, handler
app = Flask(__name__,static_folder='static',template_folder='templates')
user_data = {}
moves = 0
time = ""
retraced = 0
dimension = 0
@app.route('/', methods = ['GET', 'POST'])
def index():
if request.method == 'GET':
return render_template('form.html')
if request.method == 'POST':
data = helper._jsonifyData(request)
handler._insert(data)
global user_data
user_data = data
return render_template('index.html')
@app.route("/form")
def form():
return render_template("form.html")
@app.route('/getInitState', methods = ['GET', 'POST'])
def get_init_state():
if request.method == 'POST':
req = request.get_json()
print(req)
# Heuristic Algo v1
# array = req.split('#')
# max = -1
# for itr in array:
# if itr is not "_":
# if int(itr) > max:
# max = int(itr)
# rowCount = math.sqrt(max + 1)
# print(req)
# result = tilesSearch.search(tiles.TileGame(req, int(rowCount)),req,0)
# arr = []
# for i in result :
# arr.append(i[2])
# print(arr)
# return jsonify(arr)
#IDAStar
array = req.split("#")
max = -1
for itr in range(0,len(array)):
if array[itr] is not "_":
if int(array[itr]) > max:
max = int(array[itr])
else:
array[itr] = "0"
# print("Array", array)
rowCount = math.sqrt(max + 1)
for itr in range(0, len(array)):
array[itr] = int(array[itr])
logfile = open("test.txt", "w")
# print("Array", array)
arr, logarr = idastar.play(tuple(array),int(rowCount), logfile)
logfile.close()
print("Solution Array : ", logarr)
return jsonify(logarr)
@app.route('/getFinalVar', methods = ['POST'])
def get_final_var():
req = request.get_json()
global moves, time, retraced, dimension
moves = req['moves']
time = req['time']
retraced = req['retraced']
dimension = req['dimension']
print("Moves",moves)
print("",time)
print("",retraced)
handler._update(user_data, moves, time, retraced, dimension)
return "Received"
@app.route('/success')
def success():
global user_data, moves, time, retraced, dimension
return render_template('success.html', moves = moves, time = time)
if __name__ == '__main__':
app.run(debug=True, port=3000)