Answered step by step
Verified Expert Solution
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started