Melden

abloomsFolgen

21. Mar 2023•0 gefällt mir## 0 gefällt mir

•3 Aufrufe## Aufrufe

Sei der Erste, dem dies gefällt

Mehr anzeigen

Aufrufe insgesamt

0

Auf Slideshare

0

Aus Einbettungen

0

Anzahl der Einbettungen

0

Nächste SlideShare

need the answer in 30 mins thank you Topics Covered 1 Gra.pdf

Wird geladen in ... 3

21. Mar 2023•0 gefällt mir## 0 gefällt mir

•3 Aufrufe## Aufrufe

Sei der Erste, dem dies gefällt

Mehr anzeigen

Aufrufe insgesamt

0

Auf Slideshare

0

Aus Einbettungen

0

Anzahl der Einbettungen

0

Downloaden Sie, um offline zu lesen

Melden

Bildung

thank you PA 5. Fifteen Puzzle Topics Covered 1. Graphs 2. Graph Traversals and Search Algorithms (DFS, BFS; IDS, etc) 3. Numpy ndarrays. Permutations, Transpositions, and Linear Algebra 4. Optimiation and Game Al 5. Event-Driven Programining Instructions Fifteen Puzzle Objectives practicing with classes, modules, gaph ADT, graph traversals, optimization techniques, game A, and event.diviven programining : supplementary Material 15 puzale-Wikipedia. B. Taxicabseonctrv- Whipedia. B. IkDocs Tutorial-Basic tvideets: Description In this assigment you will wite a program that emulates a game Fifteen, a sliding pura made of 15 tilos. The tiles are arranged in the 44 toweut made of 4 tow and 4 columns, Since there ate fo spaces coositions and ondy 15 tilos one space is engty. Your program should generate a GUi window with the game tayout that f controfitble by tha mouse batton clichs. The user can plav the earne for solve the curzaleBy default, the solution to the Fifteen puzzle is positioning of all tiles in order from left to right and tog to the bottom as shown in the picture above. Optionally, the user miy change the default final solution to any possible arrangements, for exarnple, the arrangement in the reverse order from 15 to 1. It is worth to mention that there ate 16! possible permutations of 15 tiles and an empty space; however; only a half of them is solvable given the constrains of the tile movements. This property is known as an invariant of the puzzle that is unchanged after purzle transformations and is due to the parity of the nermutation E, and the parity of the Manhattan (taxicabl distance. BSo. a half of 16 . petmutations is unsolvable for given in itial conditions! Your progan should generate only correct (allowed) permutations that preserve the invariant, it can be achitved if only correct transiormations are applied to the tiles such as only an empty space can be exchanged with its neighbors. However, the problem arises if the user enters the final solution of the puzzle that cannot be teachable fthis property of the game is optional. You can find the purale invalant by calculating the parity of a permutations if the empty square is in the lower right corner as shown on the picture above, then the purzle is solvable if and only if the permutation is even. Ever nermutations have a sign +1. and odd pernutations have a sign - 1 that are calculated by the following formula: sin(1)2= where N(s) is a mamber of inversions in s. An imversion is a pair of elements that are out of their natural order, You can read about a permutation parity here Parity of a permutation - Wikiocta th. For example, the following permutatiors are even: 12345678910111213141516N=0 where 16 is an empty space 16151413121110987654321N=B However, the following permutations are odd. 16123456789101112131415 15141312111098765432116N=7N=15 A. Fifteen Puzzle Solver (Extra Credit 10 points)A Fifteen Puzzle Solver (Extra Credit 10 points) The Fifteen puzzle can be solv.

abloomsFolgen

- thank you PA 5. Fifteen Puzzle Topics Covered 1. Graphs 2. Graph Traversals and Search Algorithms (DFS, BFS; IDS, etc) 3. Numpy ndarrays. Permutations, Transpositions, and Linear Algebra 4. Optimiation and Game Al 5. Event-Driven Programining Instructions Fifteen Puzzle Objectives practicing with classes, modules, gaph ADT, graph traversals, optimization techniques, game A, and event.diviven programining : supplementary Material 15 puzale-Wikipedia. B. Taxicabseonctrv- Whipedia. B. IkDocs Tutorial-Basic tvideets: Description In this assigment you will wite a program that emulates a game Fifteen, a sliding pura made of 15 tilos. The tiles are arranged in the 44 toweut made of 4 tow and 4 columns, Since there ate fo spaces coositions and ondy 15 tilos one space is engty. Your program should generate a GUi window with the game tayout that f controfitble by tha mouse batton clichs. The user can plav the earne for solve the curzaleBy default, the solution to the Fifteen puzzle is positioning of all tiles in order from left to right and tog to the bottom as shown in the picture above. Optionally, the user miy change the default final solution to any possible arrangements, for exarnple, the arrangement in the reverse order from 15 to 1. It is worth to mention that there ate 16! possible permutations of 15 tiles and an empty space; however; only a half of them is solvable given the constrains of the tile movements. This property is known as an invariant of the puzzle that is unchanged after purzle transformations and is due to the parity of the nermutation E, and the parity of the Manhattan (taxicabl distance. BSo. a half of 16 . petmutations is unsolvable for given in itial conditions! Your progan should generate only correct (allowed) permutations that preserve the invariant, it can be achitved if only correct transiormations are applied to the tiles such as only an empty space can be exchanged with its neighbors. However, the problem arises if the user enters the final solution of the puzzle that cannot be teachable fthis property of the game is optional. You can find the purale invalant by calculating the parity of a permutations if the empty square is in the lower right corner as shown on the picture above, then the purzle is solvable if and only if the permutation is even. Ever nermutations have a sign +1. and odd pernutations have a sign - 1 that are calculated by the following formula: sin(1)2= where N(s) is a mamber of inversions in s. An imversion is a pair of elements that are out of their natural order, You can read about a permutation parity here Parity of a permutation - Wikiocta th. For example, the following permutatiors are even: 12345678910111213141516N=0 where 16 is an empty space 16151413121110987654321N=B However, the following permutations are odd. 16123456789101112131415 15141312111098765432116N=7N=15 A. Fifteen Puzzle Solver (Extra Credit 10 points)A Fifteen Puzzle Solver (Extra Credit 10 points) The Fifteen puzzle can be solved in different ways using the following algorithms: 1. A* (prongunced as A-star) B 2. Iferative Deepening Breadth-First Search (DDS) ES 3. Iterntive Deepening A((DA) E. You can implement any of these methods to solve the purzle automatically. It has been proved that at most 80 single-tile moves are required to solve the Fifteen puzzle. However, fanding optimal solutions is NP-hard, so it may require much more than 80 single-tile moves to find the solutions. Programming Approaches In this assignment you need to create three modules: game.py, fifteen.py, and graph.py. You need to create objects that can help you to manipulate the puzzle pieces. First. you need to make a model of the puzzle that has movable files and empty space and a fixed 4x4 layout. You can use an array that has indexes (fixed layout) and values (numbered tiles) such as [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,0) where 0
- is an empty space. You also need to add restrictions on how tiles can be exchanged: only o should be exchanged with its neighbors, You can use a 2d array (or a nested list) to keep the adjacency list for this purpose. This is almost enough to model an ordinory game. However, if you want to solve the puzale using gaph search algorithms then it is better to model a puzze layout. using a graph ADT where vertices are positions with values equal to tile numbers You should put your models in the module fifteen.py that should contain the class fitteen and the following methods: I create vectop (edarrayl of tiles and the laroet of tiles positinns (a copos) - tiles are niececed 118, the last tile 11 a (as empty inace) * araw the 1erout vite. tileriA return a strine rrpereientation of the vector of tilies as e 20 array. I eichange I+tile with 3 -tile E thies are ounbered 1. 15, the 1ast tile is a (expty spece) the exchanee can be done using a dot product (eot reeulired) a can return the dat peoduct (eat rtidired) def trossosefinelf, i, jhe pass F checes if the nove ls valide the of the tlles is a and another tile is its nelehbor def is valld meve(self, move)t pasi upeote the vector of thles if the move is valid assien the vector to the return af trandaose() ar coll transpole atef updote(irif, move)t pais Thitrie tilos def thuffie(setf, mones - 1ea) Bust * ver lfy if the purize is solved def isiductivelf)t averify if the purale it solvabie (ootionat) def losulvele(telis): pais: asolvethepuzate(ootional)aefsolveise1f)gass The class Fifteen can depend on the ADT Graph that should be implemented in the module graph.py. The module graph.py should have two classes Vertex afd Graph. Their detailed implementation is up to you, here is an example of their interfaces and some inplemented imethods: cast vertesi defiest(seitikiv)iariria=inyAeic.cancictrere= i)aricaier-Jatite?The class Fitteen can depend on the ADT Gaph that should be implemented in the module graph.py. The module graph py should have two classes Vertex and Graph. Their detailed implementation is up to you, here is an example of their interfaces and some implemented methods: ctass Vertex: seif, contectedto[nbr] = veight det istr_(seit) det cetconnections(1edf)t return self, coenectedio,keys() def getids(selt)t. retum iplf,iat def crtaleight (veli, ntir) I return self- ronnecteoto[nte] chats Graphs aer retvertices(1e19)i return safivertistaterid) retuen iter(Mativeri Liviveliseid) ninThe module game.py is the main module that runs the game. It should instantiate class Fifteen and GUl window in Tkinter or Pygame fyou can use only Pygame or Tkinter libraries!) The main task is to create buttons or draw rectangles with labels that can be changed when the user clicks on them. You may need to create methods that create the puzze layout and handle events such as mouse clicks. For example, you may adopt the following code (you need to modify it. so it can work for your application): frsis tkinter lisport : Import tikinterifont st toet def changeiteat (event): clepst messief ensiageiset('Click me detain!') elitit artwateset ( Voo clicked etis) a mate a buI windias cui =1k(3) anesset + Sterinnvar () neasece iset'click ne') But tinipeck(?) mistoos (3 Testing You can test your main program by running gamepy. Make sure that buttons (or other objects) behave correctly according to mouse events. Then you canWhat to turn in Submit your programs game.py, fifteen.py. graph.py to the assignment PAS on Canvas before the due date. As always start early and ask questions in lab sessions, office hours, and on Ed and Canvas.