Question: d. Add a new heuristic function h1(state) that takes a State object called state, and that computes and returns an estimate of how many additional



d. Add a new heuristic function h1(state) that takes a State object called state, and that computes and returns an estimate of how many additional moves are needed to get from state to the goal state. Its estimate should simply be the number of misplaced tiles in the Board object associated with state. Take advantage of the appropriate Board method to determine this value. Make sure that h1 is a function, not a method. Use the existing h0 function as a model, and make sure that h1's header is not indented. Once you have added this function, you can perform the following tests: >s1 State(Board'142358607), None, 'init') >>2 State(Board' 142358670), None, 'init') >>> h1(s1) # the board in sl has 5 misplaced tiles >>> h1(SZ) # the board in s2 has 4 misplaced tiles 4 >g1-GreedySearcher(h0) >>g1 GreedySearcher >>> g2 = Greedysearcher(hl) >>> g2 GreedySearcher: 0 untested, 0 tested, heuristic h1 >>> g1.heurstic(S1) # gl uses h, so its heuristic always returns 0 es >>> g2.heurstic(s1) # g2 uses h1, so its heuristic returns hi's esti :0 untested, 0 tested, heuristic ho >>> g2.priority(s1) # the priority is -1 times the heuristic value d. Add a new heuristic function h1(state) that takes a State object called state, and that computes and returns an estimate of how many additional moves are needed to get from state to the goal state. Its estimate should simply be the number of misplaced tiles in the Board object associated with state. Take advantage of the appropriate Board method to determine this value. Make sure that h1 is a function, not a method. Use the existing h0 function as a model, and make sure that h1's header is not indented. Once you have added this function, you can perform the following tests: >s1 State(Board'142358607), None, 'init') >>2 State(Board' 142358670), None, 'init') >>> h1(s1) # the board in sl has 5 misplaced tiles >>> h1(SZ) # the board in s2 has 4 misplaced tiles 4 >g1-GreedySearcher(h0) >>g1 GreedySearcher >>> g2 = Greedysearcher(hl) >>> g2 GreedySearcher: 0 untested, 0 tested, heuristic h1 >>> g1.heurstic(S1) # gl uses h, so its heuristic always returns 0 es >>> g2.heurstic(s1) # g2 uses h1, so its heuristic returns hi's esti :0 untested, 0 tested, heuristic ho >>> g2.priority(s1) # the priority is -1 times the heuristic value
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
