Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a method num_misplaced(self) that counts and returns the number of tiles in the called Board object that are not where they should be in

Write a method num_misplaced(self) that counts and returns the number of tiles in the called Board object that are not where they should be in the goal state. You should not include the blank cell in this count, even if its not where it should be in the goal state. For example:

>>> b = Board('142358607') >>> b 1 4 2 3 5 8 6 _ 7 >>> b.num_misplaced() # 1,4,5,7,8 tiles are out of place 5 >>> b.move_blank('right') # move 7 tile where it belongs True >>> b 1 4 2 3 5 8 6 7 _ >>> b.num_misplaced() # 1,4,5,8 tiles are still out of place 4 

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

Microsoft SQL Server 2012 Unleashed

Authors: Ray Rankins, Paul Bertucci

1st Edition

0133408507, 9780133408508

More Books

Students also viewed these Databases questions

Question

Whats the right action?

Answered: 1 week ago