@@ -11,6 +11,7 @@ class Gui(VacuumEnvironment):
11
11
dirty, clean or can have a wall. The user can change these at each step.
12
12
"""
13
13
xi , yi = (0 , 0 )
14
+ perceptible_distance = 1
14
15
15
16
def __init__ (self , root , width = 7 , height = 7 , elements = ['D' , 'W' ]):
16
17
super ().__init__ (width , height )
@@ -122,6 +123,20 @@ def update_env(self):
122
123
self .step ()
123
124
xf , yf = agt .location
124
125
126
+ def reset_env (self , agt ):
127
+ """Resets the GUI environment to the intial state."""
128
+ self .read_env ()
129
+ for i , btn_row in enumerate (self .buttons ):
130
+ for j , btn in enumerate (btn_row ):
131
+ if (i != 0 and i != len (self .buttons ) - 1 ) and (j != 0 and j != len (btn_row ) - 1 ):
132
+ if self .some_things_at ((i , j )):
133
+ for thing in self .list_things_at ((i , j )):
134
+ self .delete_thing (thing )
135
+ btn .config (text = '' , state = 'normal' )
136
+ self .add_thing (agt , location = (3 , 3 ))
137
+ self .buttons [3 ][3 ].config (
138
+ text = 'A' , state = 'disabled' , disabledforeground = 'black' )
139
+
125
140
126
141
def XYReflexAgentProgram (percept ):
127
142
"""The modified SimpleReflexAgentProgram for the GUI environment."""
@@ -151,18 +166,19 @@ def __init__(self, program=None):
151
166
self .direction = Direction ("up" )
152
167
153
168
154
- # TODO: Check the coordinate system.
169
+ # TODO:
170
+ # Check the coordinate system.
171
+ # Give manual choice for agent's location.
155
172
def main ():
156
173
"""The main function."""
157
174
root = Tk ()
158
175
root .title ("Vacuum Environment" )
159
176
root .geometry ("420x440" )
160
177
root .resizable (0 , 0 )
161
178
frame = Frame (root , bg = 'black' )
162
- # create a reset button
163
- # reset_button = Button(frame, text='Reset', height=2,
164
- # width=6, padx=2, pady=2, command=None)
165
- # reset_button.pack(side='left')
179
+ reset_button = Button (frame , text = 'Reset' , height = 2 ,
180
+ width = 6 , padx = 2 , pady = 2 )
181
+ reset_button .pack (side = 'left' )
166
182
next_button = Button (frame , text = 'Next' , height = 2 ,
167
183
width = 6 , padx = 2 , pady = 2 )
168
184
next_button .pack (side = 'left' )
@@ -171,6 +187,7 @@ def main():
171
187
agt = XYReflexAgent (program = XYReflexAgentProgram )
172
188
env .add_thing (agt , location = (3 , 3 ))
173
189
next_button .config (command = env .update_env )
190
+ reset_button .config (command = lambda : env .reset_env (agt ))
174
191
root .mainloop ()
175
192
176
193
0 commit comments