Question: Write a method add_state(self, new_state) that adds takes a single State object called new_state and adds it to the Searchers list of untested states. This
Write a method add_state(self, new_state) that adds takes a single State object called new_state and adds it to the Searchers list of untested states. This method should only require one line of code! It should not return a value.
For the sake of efficiency, we recommend that you do not do something like the following:
self.states = self.states + ... # don't do this!
Rather, we recommend that you either use the += operator or the append method in the list object. We will discuss the reasons for this in lecture.
Examples:
>>> searcher = Searcher(-1) >>> searcher.states [] >>> s = State(Board('142358607'), None, 'init') >>> searcher.add_state(s) >>> searcher.states [142358607-init-0] >>> succ = s.generate_successors() >>> succ [142308657-up-1, 142358067-left-1, 142358670-right-1] >>> searcher.add_state(succ[0]) # add just the first successor >>> searcher.states [142358607-init-0, 142308657-up-1] Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
