
I am struggling with this problem because I don't understand how to do this. I don't know how to create this code. This is python.
question that I need help with:
Can you please help me with this code because I am struggling how to solve this code. can you please help me with this but here is the question:
Question and the task 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.
In this section, 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. We have suggested an approach similar to the one used to create a Lights Out solver in Homework 2, and indeed, you may find that this pattern can be abstracted to cover a wide range of puzzles. If you wish to use the provided GUI for testing, described in more detail at the end of the section, then your implementation must adhere to the recommended interface. However, this is not required, and no penalty will imposed for using a different approach.
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.
task:
In the TilePuzzle class, write an initialization method __init__(self, board) that stores an input board of this form described above for future use. You additionally may wish to store the dimensions of the board as separate internal variables, as well as the location of the empty tile.
write a method get_board(self) that returns the internal representation of the board stored during initialization.
>>> p = TilePuzzle([[1, 2], [3, 0]])
>>> p.get_board()
[[1, 2], [3, 0]]
>>> p = TilePuzzle([[0, 1], [3, 2]])
>>> p.get_board()
[[0, 1], [3, 2]]
Write a top-level function create_tile_puzzle(rows, cols) that returns a new TilePuzzle of the specified dimensions, initialized to the starting configuration. Tiles 1 through r · c - 1 should be arranged starting from the top-left corner in row-major order, and tile 0 should be located in the lower-right corner.
>>> p = create_tile_puzzle(3, 3)
>>> p.get_board()
[[1, 2, 3], [4, 5, 6], [7, 8, 0]]
>>> p = create_tile_puzzle(2, 4)
>>> p.get_board()
[[1, 2, 3, 4], [5, 6, 7, 0]]
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]]
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
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

Step by stepSolved in 3 steps

- In Python, Solve the locker riddle which reads as follows:Imagine 100 lockers numbered 1 to 100 with 100 students lined up in front of those 100lockers:The first student opens every locker.The second student closes every 2nd locker.The 3rd student changes every 3rd locker; if it’s closed, she opens it; if it’s open, she closes it.The 4th student changes every fourth locker (e.g., 4th, 8th, etc.).The 5th student changes every 5th locker (e.g., 5th, 10th, etc.).That same pattern continues for all 100 students. Which lockers are left open after all 100 students have walked the rowof lockers?arrow_forwardCoding in python Please!!I need help please help me in the easiest way to do this coding question. Please do not post it's answer from chegg just use your own skills to write code in easyiest way possible. I will really appriciate your help. Coding language PYTHON : The purpose of this assignment is to help you get comfortable creating and using simple classes and objects. In this assignment, we wish to model a 2-D video game character’s movements. In particular, suppose we are creating a tiny game, where the character can occupy one of 25 squares, like so: The first thing we need to keep track of is the character’s name, so we can differentiate this character from other characters or enemies. The other thing we need to keep track of is the character’s position, i.e., which square they are in. In order to do this, we’ll use an X-Y coordinate system with the origin in the top left corner (the 0,0 square in the picture). So, in the picture, the character occupies square 3, 2;…arrow_forwardSo I have this artificial intelligence assignment and I’m struggling with the search methods implementations it would be nice if I can get the code in Java or at least a pseudocode for their implementationsarrow_forward
- Can you help me with this code because this is a little difficult for me:question that i need help with:The Lights Out puzzle consists of an m x n grid of lights, each of which has two states: on and off. The goal of the puzzle is to turn all the lights off, with the caveat that whenever a light is toggled, its neighbors above, below, to the left, and to the right will be toggled as well. If a light along the edge of the board is toggled, then fewer than four other lights will be affected, as the missing neighbors will beignored. In this section, you will investigate the behavior of Lights Out puzzles of various sizes by implementing a LightsOutPuzzle class task: A natural representation for this puzzle is a two-dimensional list of Boolean values, where True corresponds to the on state and False corresponds to the off state. In the LightsOutPuzzle class, write an initialization method __init__(self, board) that stores an input board of this form for future use. Also write a method…arrow_forwardPythonarrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





