-
Notifications
You must be signed in to change notification settings - Fork 0
/
steps.py
264 lines (247 loc) · 12.2 KB
/
steps.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'untitled.ui'
#
# Created by: PyQt5 UI code generator 5.15.9
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt5 import QtCore, QtGui, QtWidgets
class Steps_window(object):
def setupUi(self, Form):
def setupUi(self, Form):
Form.setObjectName("Form")
Form.resize(853, 572)
self.frame_3 = QtWidgets.QFrame(Form)
self.frame_3.setGeometry(QtCore.QRect(10, 10, 819, 117))
self.frame_3.setMinimumSize(QtCore.QSize(819, 100))
self.frame_3.setMaximumSize(QtCore.QSize(39999, 183))
self.frame_3.setFrameShape(QtWidgets.QFrame.StyledPanel)
self.frame_3.setFrameShadow(QtWidgets.QFrame.Raised)
self.frame_3.setObjectName("frame_3")
self.label = QtWidgets.QLabel(self.frame_3)
self.label.setGeometry(QtCore.QRect(170, 30, 550, 51))
font = QtGui.QFont()
font.setPointSize(14)
font.setBold(True)
font.setWeight(75)
self.label.setFont(font)
self.label.setObjectName("label")
self.frame = QtWidgets.QFrame(Form)
self.frame.setGeometry(QtCore.QRect(10, 429, 819, 117))
self.frame.setMinimumSize(QtCore.QSize(300, 100))
self.frame.setFrameShape(QtWidgets.QFrame.StyledPanel)
self.frame.setFrameShadow(QtWidgets.QFrame.Raised)
self.frame.setObjectName("frame")
self.pushButton = QtWidgets.QPushButton(self.frame)
self.pushButton.setGeometry(QtCore.QRect(60, 40, 130, 30))
self.pushButton.setObjectName("pushButton")
self.pushButton_2 = QtWidgets.QPushButton(self.frame)
self.pushButton_2.setGeometry(QtCore.QRect(630, 40, 130, 30))
self.pushButton_2.setObjectName("pushButton_2")
self.label_13 = QtWidgets.QLabel(self.frame)
self.label_13.setGeometry(QtCore.QRect(416, 40, 100, 30))
font = QtGui.QFont()
font.setPointSize(12)
font.setBold(True)
font.setWeight(75)
self.label_13.setFont(font)
self.label_13.setObjectName("label_13")
self.lineEdit = QtWidgets.QLineEdit(self.frame)
self.lineEdit.setGeometry(QtCore.QRect(370, 40, 41, 30))
self.lineEdit.setObjectName("lineEdit")
self.frame_4 = QtWidgets.QFrame(Form)
self.frame_4.setGeometry(QtCore.QRect(10, 133, 819, 290))
self.frame_4.setMinimumSize(QtCore.QSize(300, 290))
self.frame_4.setMaximumSize(QtCore.QSize(30000, 30000))
self.frame_4.setFrameShape(QtWidgets.QFrame.StyledPanel)
self.frame_4.setFrameShadow(QtWidgets.QFrame.Raised)
self.frame_4.setObjectName("frame_4")
self.horizontalLayout = QtWidgets.QHBoxLayout(self.frame_4)
self.horizontalLayout.setObjectName("horizontalLayout")
self.frame_2 = QtWidgets.QFrame(self.frame_4)
self.frame_2.setMinimumSize(QtCore.QSize(250, 250))
self.frame_2.setMaximumSize(QtCore.QSize(250, 300))
self.frame_2.setFrameShape(QtWidgets.QFrame.StyledPanel)
self.frame_2.setFrameShadow(QtWidgets.QFrame.Raised)
self.frame_2.setObjectName("frame_2")
self.line_10 = QtWidgets.QFrame(self.frame_2)
self.line_10.setGeometry(QtCore.QRect(220, 0, 10, 210))
self.line_10.setFrameShape(QtWidgets.QFrame.VLine)
self.line_10.setFrameShadow(QtWidgets.QFrame.Sunken)
self.line_10.setObjectName("line_10")
self.line_11 = QtWidgets.QFrame(self.frame_2)
self.line_11.setGeometry(QtCore.QRect(10, 0, 215, 5))
self.line_11.setFrameShape(QtWidgets.QFrame.HLine)
self.line_11.setFrameShadow(QtWidgets.QFrame.Sunken)
self.line_11.setObjectName("line_11")
self.line_12 = QtWidgets.QFrame(self.frame_2)
self.line_12.setGeometry(QtCore.QRect(10, 70, 215, 5))
self.line_12.setFrameShape(QtWidgets.QFrame.HLine)
self.line_12.setFrameShadow(QtWidgets.QFrame.Sunken)
self.line_12.setObjectName("line_12")
self.line_13 = QtWidgets.QFrame(self.frame_2)
self.line_13.setGeometry(QtCore.QRect(10, 210, 215, 5))
self.line_13.setFrameShape(QtWidgets.QFrame.HLine)
self.line_13.setFrameShadow(QtWidgets.QFrame.Sunken)
self.line_13.setObjectName("line_13")
self.line_14 = QtWidgets.QFrame(self.frame_2)
self.line_14.setGeometry(QtCore.QRect(10, 140, 215, 5))
self.line_14.setFrameShape(QtWidgets.QFrame.HLine)
self.line_14.setFrameShadow(QtWidgets.QFrame.Sunken)
self.line_14.setObjectName("line_14")
self.line_15 = QtWidgets.QFrame(self.frame_2)
self.line_15.setGeometry(QtCore.QRect(150, 0, 10, 210))
self.line_15.setFrameShape(QtWidgets.QFrame.VLine)
self.line_15.setFrameShadow(QtWidgets.QFrame.Sunken)
self.line_15.setObjectName("line_15")
self.line_16 = QtWidgets.QFrame(self.frame_2)
self.line_16.setGeometry(QtCore.QRect(80, 0, 10, 210))
self.line_16.setFrameShape(QtWidgets.QFrame.VLine)
self.line_16.setFrameShadow(QtWidgets.QFrame.Sunken)
self.line_16.setObjectName("line_16")
self.line_17 = QtWidgets.QFrame(self.frame_2)
self.line_17.setGeometry(QtCore.QRect(10, 0, 10, 210))
self.line_17.setFrameShape(QtWidgets.QFrame.VLine)
self.line_17.setFrameShadow(QtWidgets.QFrame.Sunken)
self.line_17.setObjectName("line_17")
self.label_2 = QtWidgets.QLabel(self.frame_2)
self.label_2.setGeometry(QtCore.QRect(25, 10, 50, 50))
self.label_2.setObjectName("label_2")
self.label_5 = QtWidgets.QLabel(self.frame_2)
self.label_5.setGeometry(QtCore.QRect(90, 10, 50, 50))
self.label_5.setObjectName("label_5")
self.label_6 = QtWidgets.QLabel(self.frame_2)
self.label_6.setGeometry(QtCore.QRect(160, 10, 50, 50))
self.label_6.setObjectName("label_6")
self.label_7 = QtWidgets.QLabel(self.frame_2)
self.label_7.setGeometry(QtCore.QRect(20, 80, 50, 50))
self.label_7.setObjectName("label_7")
self.label_8 = QtWidgets.QLabel(self.frame_2)
self.label_8.setGeometry(QtCore.QRect(90, 80, 50, 50))
self.label_8.setObjectName("label_8")
self.label_9 = QtWidgets.QLabel(self.frame_2)
self.label_9.setGeometry(QtCore.QRect(160, 80, 50, 50))
self.label_9.setObjectName("label_9")
self.label_10 = QtWidgets.QLabel(self.frame_2)
self.label_10.setGeometry(QtCore.QRect(20, 150, 50, 50))
self.label_10.setObjectName("label_10")
self.label_11 = QtWidgets.QLabel(self.frame_2)
self.label_11.setGeometry(QtCore.QRect(90, 150, 50, 50))
self.label_11.setObjectName("label_11")
self.label_12 = QtWidgets.QLabel(self.frame_2)
self.label_12.setGeometry(QtCore.QRect(160, 150, 50, 50))
self.label_12.setObjectName("label_12")
self.horizontalLayout.addWidget(self.frame_2)
font1 = QtGui.QFont()
font1.setPointSize(10)
font1.setBold(True)
font1.setWeight(65)
self.nodes_label=QtWidgets.QLabel(self.frame_4)
self.nodes_label.setGeometry(QtCore.QRect(80, 100, 250, 50))
self.nodes_label.setObjectName("nodes_label")
self.nodes_label.setFont(font1)
self.depth=QtWidgets.QLabel(self.frame_4)
self.depth.setGeometry(QtCore.QRect(80, 150, 250, 50))
self.depth.setObjectName("depth")
self.depth.setFont(font1)
self.retranslateUi(Form)
QtCore.QMetaObject.connectSlotsByName(Form)
## Put all labels in list
self.label_list=[
self.label_2,
self.label_5,
self.label_6,
self.label_7,
self.label_8,
self.label_9,
self.label_10,
self.label_11,
self.label_12,
]
font = QtGui.QFont()
font.setPointSize(12)
font.setBold(True)
font.setWeight(75)
# self.red_font = QtGui.QFont()
# self.red_font.setPointSize(12)
# self.red_font.setBold(True)
# self.red_font.setWeight(7
for i in range(9):
self.label_list[i].setFont(font)
self.label_list[i].setAlignment(QtCore.Qt.AlignCenter)
self.pushButton.clicked.connect(self.prev)
self.pushButton_2.clicked.connect(self.next)
self.lineEdit.textChanged.connect(self.change_state)
def retranslateUi(self, Form):
_translate = QtCore.QCoreApplication.translate
Form.setWindowTitle(_translate("MainWindow", "8-Puzzle Solver"))
self.label.setText(_translate("MainWindow", "Number of states to reach goal \"Cost\" is "))
self.label_2.setText(_translate("MainWindow", "TextLabel"))
self.label_5.setText(_translate("MainWindow", "TextLabel"))
self.label_6.setText(_translate("MainWindow", "TextLabel"))
self.label_7.setText(_translate("MainWindow", "TextLabel"))
self.label_8.setText(_translate("MainWindow", "TextLabel"))
self.label_9.setText(_translate("MainWindow", "TextLabel"))
self.label_10.setText(_translate("MainWindow", "TextLabel"))
self.label_11.setText(_translate("MainWindow", "TextLabel"))
self.label_12.setText(_translate("MainWindow", "TextLabel"))
self.pushButton.setText(_translate("MainWindow", "Prev State"))
self.pushButton_2.setText(_translate("MainWindow", "Next State"))
self.label_13.setText(_translate("MainWindow", "/"))
def init_solution(self, res):
self.cost=str(res[0][0])
_translate = QtCore.QCoreApplication.translate
self.label.setText(_translate("MainWindow", "Number of states to reach goal \"Cost\" is "+self.cost))
self.res_list =res[0][1]
self.label_13.setText(_translate("MainWindow", "/"+str(res[0][0])))
self.lineEdit.setText("0")
self.nodes_label.setText(_translate("MainWindow","Nodes Exbanded : "+ str(res[1])))
self.depth.setText(_translate("MainWindow","Search Depth : "+ str(res[2])))
cur_state=self.res_list[0]
for i in range(9):
self.label_list[i].setText(_translate("MainWindow", str(cur_state[i])))
if str(cur_state[i])=="0":
self.label_list[i].setStyleSheet("color: red;")
else:
self.label_list[i].setStyleSheet("color: black;")
def next(self):
_translate = QtCore.QCoreApplication.translate
self.lineEdit.setText(str(int(self.lineEdit.text())+1))
cur_state=self.res_list[int(self.lineEdit.text())]
for i in range(9):
self.label_list[i].setText(_translate("MainWindow", str(cur_state[i])))
if str(cur_state[i])=="0":
self.label_list[i].setStyleSheet("color: red;")
else:
self.label_list[i].setStyleSheet("color: black;")
def prev(self):
_translate = QtCore.QCoreApplication.translate
self.lineEdit.setText(str(int(self.lineEdit.text())-1))
cur_state=self.res_list[int(self.lineEdit.text())]
for i in range(9):
self.label_list[i].setText(_translate("MainWindow", str(cur_state[i])))
if str(cur_state[i])=="0":
self.label_list[i].setStyleSheet("color: red;")
else:
self.label_list[i].setStyleSheet("color: black;")
def change_state(self):
_translate = QtCore.QCoreApplication.translate
try:
cur_state=self.res_list[int(self.lineEdit.text())]
for i in range(9):
self.label_list[i].setText(_translate("MainWindow", str(cur_state[i])))
if str(cur_state[i])=="0":
self.label_list[i].setStyleSheet("color: red;")
else:
self.label_list[i].setStyleSheet("color: black;")
self.lineEdit.setText(str(int(self.lineEdit.text())))
if int(self.lineEdit.text())== 0:
self.pushButton.setEnabled(False)
else:
self.pushButton.setEnabled(True)
if int(self.lineEdit.text())== int(self.cost):
self.pushButton_2.setEnabled(False)
else:
self.pushButton_2.setEnabled(True)
except:
pass