@@ -11,6 +11,7 @@ class Gui(VacuumEnvironment):
1111 dirty, clean or can have a wall. The user can change these at each step.
1212 """
1313 xi , yi = (0 , 0 )
14+ perceptible_distance = 1
1415
1516 def __init__ (self , root , width = 7 , height = 7 , elements = ['D' , 'W' ]):
1617 super ().__init__ (width , height )
@@ -122,6 +123,20 @@ def update_env(self):
122123 self .step ()
123124 xf , yf = agt .location
124125
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+
125140
126141def XYReflexAgentProgram (percept ):
127142 """The modified SimpleReflexAgentProgram for the GUI environment."""
@@ -151,18 +166,19 @@ def __init__(self, program=None):
151166 self .direction = Direction ("up" )
152167
153168
154- # TODO: Check the coordinate system.
169+ # TODO:
170+ # Check the coordinate system.
171+ # Give manual choice for agent's location.
155172def main ():
156173 """The main function."""
157174 root = Tk ()
158175 root .title ("Vacuum Environment" )
159176 root .geometry ("420x440" )
160177 root .resizable (0 , 0 )
161178 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' )
166182 next_button = Button (frame , text = 'Next' , height = 2 ,
167183 width = 6 , padx = 2 , pady = 2 )
168184 next_button .pack (side = 'left' )
@@ -171,6 +187,7 @@ def main():
171187 agt = XYReflexAgent (program = XYReflexAgentProgram )
172188 env .add_thing (agt , location = (3 , 3 ))
173189 next_button .config (command = env .update_env )
190+ reset_button .config (command = lambda : env .reset_env (agt ))
174191 root .mainloop ()
175192
176193
0 commit comments