Can you help me with this code I only need help with two of the parts. I have attached my code in the photo. question that i need help with: the Eight Puzzle consists of a 3 x 3 board of sliding tiles with a single empty space. For each configuration, the only possible moves are to swap the empty tile with one of its neighboring tiles. The goal state for the puzzle consists of tiles 1-3 in the top row, tiles 4-6 in the middle row, and tiles 7 and 8 in the bottom row, with the empty space in the lower-right corner.you will develop two solvers for a generalized version of the Eight Puzzle, in which the board can have any number of rows and columns.  A natural representation for this puzzle is a two-dimensional list of integer values between 0 and r · c -1 (inclusive), where r and c are the number of rows and columns in the board, respectively. In this problem, we will adhere to the convention that the 0-tile represents the empty space. tasks: In the TilePuzzle class, write a method perform_move(self, direction) that attempts to swap the empty tile with its neighbor in the indicated direction, where valid inputs are limited to the strings "up" , "down" , "left" , and "right" . If the given direction is invalid, or if the move cannot be performed, then no changes to the puzzle should be made. The method should return a Boolean value indicating whether the move was successful. >>> p = create_tile_puzzle(3, 3) >>> p.perform_move("up") True >>> p.get_board() [[1, 2, 3], [4, 5, 0], [7, 8, 6]] >>> p = create_tile_puzzle(3, 3) >>> p.perform_move("down") False >>> p.get_board() [[1, 2, 3], [4, 5, 6], [7, 8, 0]] In the TilePuzzle class, write a method scramble(self, num_moves) which scrambles the puzzle by calling perform_move(self, direction) the indicated number of times, each time with a random direction. This method of scrambling guarantees that the resulting configuration will be solvable, which may not be true if the tiles are randomly permuted. Hint: The random module contains a function random.choice(seq) which returns a random element from its input sequence. In the TilePuzzle class, write a method is_solved(self) that returns whether the board is in its starting configuration. >>> p = TilePuzzle([[1, 2], [3, 0]]) >>> p.is_solved() True >>> p = TilePuzzle([[0, 1], [3, 2]]) >>> p.is_solved() False In the TilePuzzle class, write a method copy(self) that returns a new TilePuzzle object initialized with a deep copy of the current board. Changes made to the original puzzle should not be reflected in the copy, and vice versa. >>> p = create_tile_puzzle(3, 3) >>> p2 = p.copy() >>> p.get_board() == p2.get_board() True >>> p = create_tile_puzzle(3, 3) >>> p2 = p.copy() >>> p.perform_move("left") >>> p.get_board() == p2.get_board() False this needs to be in the code: def create_tile_puzzle(rows, cols): pass class TilePuzzle(object): # Required def __init__(self, board): pass def get_board(self): pass def perform_move(self, direction): pass def scramble(self, num_moves): pass def is_solved(self): pass def copy(self): pass def successors(self): pass # Required def find_solutions_iddfs(self): pass # Required def find_solution_a_star(self): pass

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Can you help me with this code I only need help with two of the parts. I have attached my code in the photo.

question that i need help with:

the Eight Puzzle consists of a 3 x 3 board of sliding tiles with a single empty space. For each configuration, the only possible moves are to swap the empty tile with one of its neighboring tiles. The goal state for the puzzle consists of tiles 1-3 in the top row, tiles 4-6 in the middle row, and tiles 7 and 8 in the bottom row, with the empty space in the lower-right corner.you will develop two solvers for a generalized version of the Eight Puzzle, in which the board can have any number of rows and columns. 

A natural representation for this puzzle is a two-dimensional list of integer values between 0 and r · c -1 (inclusive), where r and c are the number of rows and columns in the board, respectively. In this problem, we will adhere to the convention that the 0-tile represents the empty space.

tasks:

In the TilePuzzle class, write a method perform_move(self, direction) that attempts to swap the empty tile with its neighbor in the indicated direction, where valid inputs are limited to the strings "up" , "down" , "left" , and "right" . If the given direction is invalid, or if the move cannot be performed, then no changes to the puzzle should be made. The method should return a Boolean value indicating whether the move was successful.

>>> p = create_tile_puzzle(3, 3)
>>> p.perform_move("up")
True
>>> p.get_board()
[[1, 2, 3], [4, 5, 0], [7, 8, 6]]

>>> p = create_tile_puzzle(3, 3)
>>> p.perform_move("down")
False
>>> p.get_board()
[[1, 2, 3], [4, 5, 6], [7, 8, 0]]

In the TilePuzzle class, write a method scramble(self, num_moves) which scrambles the puzzle by calling perform_move(self, direction) the indicated number of times, each time with a random direction. This method of scrambling guarantees that the resulting configuration will be solvable, which may not be true if the tiles are randomly permuted. Hint: The random module contains a function random.choice(seq) which returns a random element from its input sequence.

In the TilePuzzle class, write a method is_solved(self) that returns whether the board is in its starting configuration.

>>> p = TilePuzzle([[1, 2], [3, 0]])
>>> p.is_solved()
True

>>> p = TilePuzzle([[0, 1], [3, 2]])
>>> p.is_solved()
False

In the TilePuzzle class, write a method copy(self) that returns a new TilePuzzle object initialized with a deep copy of the current board. Changes made to the original puzzle should not be reflected in the copy, and vice versa.

>>> p = create_tile_puzzle(3, 3)
>>> p2 = p.copy()
>>> p.get_board() == p2.get_board()
True

>>> p = create_tile_puzzle(3, 3)
>>> p2 = p.copy()
>>> p.perform_move("left")
>>> p.get_board() == p2.get_board()
False

this needs to be in the code:

def create_tile_puzzle(rows, cols):
pass


class TilePuzzle(object):

# Required
def __init__(self, board):
pass

def get_board(self):
pass

def perform_move(self, direction):
pass

def scramble(self, num_moves):
pass

def is_solved(self):
pass

def copy(self):
pass

def successors(self):
pass

# Required
def find_solutions_iddfs(self):
pass

# Required
def find_solution_a_star(self):
pass
import copy
2 usages
class TilePuzzle(object):
def __init__(self, board):
self.board=board # Store the input board
self.rows = len(board) # Calculate the number of rows
self.cols= Len (board [0]) # Calculate the number of columns
self.empty_row, self.empty_col= self.find_empty_tile () # Find the initial position of the empty tile
10 usages (8 dynamic)
def get_board (self):
return self.board # Return the internal representation of the board
1 usage
def find empty_tile(self):
for row in range(self.rows):
for col in range(self.cols):
if self.board [row][col] == 0:
return row, col # Return the row and column indices of the empty tile
1
p= TilePuzzle([[1, 2] [3, 011)
print (p.get_board()) # Output: [[1, 2], [3, 0]]
p = TilePuzzle ([[0, 1], [3, 2]])
print (p.get_board()) # Output: [[0, 1], [3, 2]]
p= create tile puzzle (3, 3)
print (p.get_board()) # Output: [[1, 2, 3], [4, 5, 6], [7, 8, 0]]
A6 A 29
P = create tile puzzle (24)
print (p.get_board()) # Output: [[1, 2, 3, 4], [5, 6, 7, 0]]
Transcribed Image Text:import copy 2 usages class TilePuzzle(object): def __init__(self, board): self.board=board # Store the input board self.rows = len(board) # Calculate the number of rows self.cols= Len (board [0]) # Calculate the number of columns self.empty_row, self.empty_col= self.find_empty_tile () # Find the initial position of the empty tile 10 usages (8 dynamic) def get_board (self): return self.board # Return the internal representation of the board 1 usage def find empty_tile(self): for row in range(self.rows): for col in range(self.cols): if self.board [row][col] == 0: return row, col # Return the row and column indices of the empty tile 1 p= TilePuzzle([[1, 2] [3, 011) print (p.get_board()) # Output: [[1, 2], [3, 0]] p = TilePuzzle ([[0, 1], [3, 2]]) print (p.get_board()) # Output: [[0, 1], [3, 2]] p= create tile puzzle (3, 3) print (p.get_board()) # Output: [[1, 2, 3], [4, 5, 6], [7, 8, 0]] A6 A 29 P = create tile puzzle (24) print (p.get_board()) # Output: [[1, 2, 3, 4], [5, 6, 7, 0]]
Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Computational Systems
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education