Instruction:

For this assignment, you need to implement two different search algorithms to solve a puzzle problem. For this puzzle game, the GUI (graphical user interface) framework is provided that is developed by Python and pygame library. Below is a highlight of the provided framework.

Two folders are given:

- game folder - This folder deals with all the graphical or visual stuff, including pattern generation from an image, user mouse/keyboard interface, ext (You do not need to modify any files in this class).
- sol folder - This folder has the file that provides a solution for a given puzzle. Three functions you can find from this file “bfs()”, “dfs()” and “astar()”. (For this project, you are required to implement the first two functions). These three functions are triggered by the three buttons in the GUI accordingly.

What you need to do is to create Python project (suggested using the Interpreters 3.0 or higher) and copy these two folders directly to the created project. Then you need to install the pygame library, e.g. pip tools. Open the “puzzle.py” file in the game folder and run the code from there.

Requirements:

You need to implement the two functions in the “solution.py” file in the “sol” folder:

- bfs(puzzle)(50%) 2. dfs(puzzle)(50%).

The input argument “puzzle” is just a list of 9 numbers, e.g. [4, 3, 5, 2, 0, 1, 8, 6, 7], where the number “8” represents the empty space. You can use a print() function to see this input data. Both functions expect you to return a list of a path for the number “8” to move to make the sequence into a sequential order. Each element of the path represents a new position of the number “8” to move. The details are explaned in the section below.

What should be submitted:

Explanation of the returned “path” list:

The path stores the moving steps of the empty space “8" to move though when you play the game you move the tiles rather than the empty space. Below shows an example of the moving path of “8”

For example:

Input: data={0,4,1,3,8,2,6,7,5};

Goal: make it into the correct order {0, 1, 2, 3, 4, 5, 6, 7, 8}

You need to make the following changes on the number 8, since the number 8 represents the empty space, moving 8 to its neighboringnumbers equals to moving the corresponding number to the empty space. Below it shows a demo of the steps:

041 swapwith4 081 swapwith1 018 swapwith2 012 swapwith5 012

3 8 2 -----------------> 3 4 2 -----------------> 3 4 2 -----------------> 3 4 8 ------------------> 3 4 5 -... 675 675 675 675 678

So from this example, the right path should be {1, 2, 5, 8}.

WHY? You may thought it was {4, 1, 2, 5}, since the number 8 has swapped with them in this order. That is true. However, we do not care which number it swapped with, but which position the number 8 has gone through. As the numbers can be in any positions during different time, which give no hint about where the number 8 is. In contrast, the positions are fixed. So we assume the positions are in the same order as an increasing sequence:

[0] [1] [2] Fixed Position = [3] [4] [5] [6] [7] [8]

Here, I use "[]" to distinguish the positions from the numbers. So now you can see, the number 8 starts from position [4], then swapped with number 4, which goes to the position [1]; then swapped with number 1, which goes to the position [2]; then swapped with number 2, which goes to the position [5]; finally, swapped with number 5, which goes to the position [8]. So the path you should assign to the parameter "&solution" with the path sequence {1, 2, 5, 8}.

Python Programming

60 Answers

Python Programming

67 Answers

DescriptionIn this final assignment, the students will demonstrate their ability to apply two majorconstructs of the C programming language – Functions and Arrays – to solve computationalproblems.Arrays provide a convenient way to store &

The standard path finding involves finding the (shortest) path from an origin to a destination, typically on a map. This is anPath finding involves finding a path from A to B. Typically we want the path to have certain properties,such as being the shortest or to avoid going through certain obstacles. As the main aim is to thinkabout path finding, we focus on the common task

Develop a program to emulate a purchase transaction at a retail store. This program will have two classes, a LineItem class and a Transaction class. The LineItem class will represent an individualDevelop a program to emulate a purchase transaction at a retail store. Thisprogram will have two classes, a LineItem class and a Transaction class. TheLineItem class will represent an individual line item of merchandise that acustomer is purchasing.

SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:1 Project 1 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define: SeaPortProgram e

Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:1 Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define: SeaPortProgram e

The first programming project involves writing a program that parses, using recursive descent, a GUI definition language defined in an input file and generates the GUI that it defines. The grammar for this language is defined below:1Project 1The first programming project involves writing a program that parses, using recursive descent, a GUIdefinition language defined in an input file and generates the GUI that it defines. The grammar for thislanguage is defined below:gui ::= Wi

CMSC 335 Project SeaPort Solved Project 3 Introduction the SeaPort Project series For this set of projects for the course we wish to simulate some of the aspects of a number of Sea PortsCMSC 335 Project SolvedProject 3 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

CMSC 335 Project 4 Solved SeaPort Introduction the SeaPort Project series For this set of projects for the course we wish to simulate some of the aspects of a number of Sea Ports Here are the classes and their instance variables we wish to defineProject 4 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define: SeaPortProgram ext

CMSC 451 Project 2 Solved The second project involves completing and extending the C++ program that evaluates statements of an expression language contained in the module 3 case studyProject 2 The second project involves completing and extending the C++ program that evaluates statements of an expression language contained in the module 3 case study. The statements of that expression language consist of an arithmetic expression f

CMSC 451 Project 1 Solved The first project involves benchmarking the behavior of Java implementations of one of the following sorting algorithms bubble sort selection sort insertion sort Shell sort, merge sort quick sort or heap sortCMSC 451 Project 1The first project involves benchmarking the behavior of Java implementations of one of thefollowing sorting algorithms, bubble sort, selection sort, insertion sort, Shell sort, merge sort,quick sort or heap sort. You must post your

The ready solutions purchased from Library are already used solutions. Please do not submit them directly as it may lead to plagiarism. Once paid, the solution file download link will be sent to your provided email. Please either use them for learning purpose or re-write them in your own language. In case if you haven't get the email, do let us know via chat support.

Get Free Quote!

259 Experts Online