Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Add a new heuristic function h1(state) that takes a Stateobject called state, and that computes and returns an estimate of how many additional moves are

Add a new heuristic function h1(state) that takes a Stateobject 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 h1s header is notindented.

Once you have added this function, you can perform the following tests:

>>> s1 = State(Board('142358607'), None, 'init') >>> s2 = State(Board('142358670'), None, 'init') >>> h1(s1) # the board in s1 has 5 misplaced tiles 5 >>> h1(s2) # the board in s2 has 4 misplaced tiles 4 >>> g1 = GreedySearcher(h0) >>> g1 GreedySearcher: 0 untested, 0 tested, heuristic h0 >>> g2 = GreedySearcher(h1) >>> g2 GreedySearcher: 0 untested, 0 tested, heuristic h1 >>> g1.heuristic(s1) # g1 uses h0, so its heuristic always returns 0 0 >>> g2.heuristic(s1) # g2 uses h1, so its heuristic returns h1's estimate 5 >>> g2.priority(s1) # the priority is -1 times the heuristic value -5

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

DB2 11 The Ultimate Database For Cloud Analytics And Mobile

Authors: John Campbell, Chris Crone, Gareth Jones, Surekha Parekh, Jay Yothers

1st Edition

ISBN: 1583474013, 978-1583474013

More Books

Students also viewed these Databases questions

Question

13-6 How will MIS help my career?

Answered: 1 week ago