SlideShare uma empresa Scribd logo
1 de 2
Baixar para ler offline
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.

Mais conteúdo relacionado

Semelhante a thank you PA 5 Fifteen Puzzle Topics Covered 1 Graphs 2 .pdf

Exercise 1 (10 Points) Define a FixdLenStringList class that encaps.pdf
Exercise 1 (10 Points) Define a FixdLenStringList class that encaps.pdfExercise 1 (10 Points) Define a FixdLenStringList class that encaps.pdf
Exercise 1 (10 Points) Define a FixdLenStringList class that encaps.pdf
fms12345
 
computer notes - Data Structures - 9
computer notes - Data Structures - 9computer notes - Data Structures - 9
computer notes - Data Structures - 9
ecomputernotes
 

Semelhante a thank you PA 5 Fifteen Puzzle Topics Covered 1 Graphs 2 .pdf (20)

Network Design Assignment Help
Network Design Assignment HelpNetwork Design Assignment Help
Network Design Assignment Help
 
Mit6 006 f11_quiz1
Mit6 006 f11_quiz1Mit6 006 f11_quiz1
Mit6 006 f11_quiz1
 
Loops_in_Rv1.2b
Loops_in_Rv1.2bLoops_in_Rv1.2b
Loops_in_Rv1.2b
 
Ee693 sept2014quiz1
Ee693 sept2014quiz1Ee693 sept2014quiz1
Ee693 sept2014quiz1
 
Computer Graphics in Java and Scala - Part 1b
Computer Graphics in Java and Scala - Part 1bComputer Graphics in Java and Scala - Part 1b
Computer Graphics in Java and Scala - Part 1b
 
Stochastic Process Assignment Help
Stochastic Process Assignment HelpStochastic Process Assignment Help
Stochastic Process Assignment Help
 
The Day You Finally Use Algebra: A 3D Math Primer
The Day You Finally Use Algebra: A 3D Math PrimerThe Day You Finally Use Algebra: A 3D Math Primer
The Day You Finally Use Algebra: A 3D Math Primer
 
DSA (Data Structure and Algorithm) Questions
DSA (Data Structure and Algorithm) QuestionsDSA (Data Structure and Algorithm) Questions
DSA (Data Structure and Algorithm) Questions
 
Exercise 1 (10 Points) Define a FixdLenStringList class that encaps.pdf
Exercise 1 (10 Points) Define a FixdLenStringList class that encaps.pdfExercise 1 (10 Points) Define a FixdLenStringList class that encaps.pdf
Exercise 1 (10 Points) Define a FixdLenStringList class that encaps.pdf
 
Computer Graphics in Java and Scala - Part 1
Computer Graphics in Java and Scala - Part 1Computer Graphics in Java and Scala - Part 1
Computer Graphics in Java and Scala - Part 1
 
Genetic operators
Genetic operatorsGenetic operators
Genetic operators
 
Q
QQ
Q
 
C Programming Interview Questions
C Programming Interview QuestionsC Programming Interview Questions
C Programming Interview Questions
 
Online Signal Processing Assignment Help
Online Signal Processing Assignment HelpOnline Signal Processing Assignment Help
Online Signal Processing Assignment Help
 
Computer Network Homework Help
Computer Network Homework HelpComputer Network Homework Help
Computer Network Homework Help
 
Exhaustive Combinatorial Enumeration
Exhaustive Combinatorial EnumerationExhaustive Combinatorial Enumeration
Exhaustive Combinatorial Enumeration
 
Cs6660 compiler design november december 2016 Answer key
Cs6660 compiler design november december 2016 Answer keyCs6660 compiler design november december 2016 Answer key
Cs6660 compiler design november december 2016 Answer key
 
computer notes - Data Structures - 9
computer notes - Data Structures - 9computer notes - Data Structures - 9
computer notes - Data Structures - 9
 
Recursion - Computer Algorithms
Recursion - Computer AlgorithmsRecursion - Computer Algorithms
Recursion - Computer Algorithms
 
Signal Processing Homework Help
Signal Processing Homework HelpSignal Processing Homework Help
Signal Processing Homework Help
 

Mais de ablooms

TF 2 points each Total 20 points 1 A disadvantage of the .pdf
TF 2 points each Total 20 points 1 A disadvantage of the .pdfTF 2 points each Total 20 points 1 A disadvantage of the .pdf
TF 2 points each Total 20 points 1 A disadvantage of the .pdf
ablooms
 
tgat is everything b Draw a Punnett square to illustrate a.pdf
tgat is everything  b Draw a Punnett square to illustrate a.pdftgat is everything  b Draw a Punnett square to illustrate a.pdf
tgat is everything b Draw a Punnett square to illustrate a.pdf
ablooms
 

Mais de ablooms (20)

The arrows can only be dragged to z scores that are accurate.pdf
The arrows can only be dragged to z scores that are accurate.pdfThe arrows can only be dragged to z scores that are accurate.pdf
The arrows can only be dragged to z scores that are accurate.pdf
 
The Arctic is an example of a harsh environment Plants livi.pdf
The Arctic is an example of a harsh environment Plants livi.pdfThe Arctic is an example of a harsh environment Plants livi.pdf
The Arctic is an example of a harsh environment Plants livi.pdf
 
the answer selected is incorrect from C language What is a.pdf
the answer selected is incorrect  from C language What is a.pdfthe answer selected is incorrect  from C language What is a.pdf
the answer selected is incorrect from C language What is a.pdf
 
the answers are in the picture i typed the question out p.pdf
the answers are in the picture i typed the question out  p.pdfthe answers are in the picture i typed the question out  p.pdf
the answers are in the picture i typed the question out p.pdf
 
The answer is the picture is wrong Can you please tell me t.pdf
The answer is the picture is wrong Can you please tell me t.pdfThe answer is the picture is wrong Can you please tell me t.pdf
The answer is the picture is wrong Can you please tell me t.pdf
 
The ALD allele is recessive and responsible for Lorenzo.pdf
The ALD allele is recessive  and responsible for Lorenzo.pdfThe ALD allele is recessive  and responsible for Lorenzo.pdf
The ALD allele is recessive and responsible for Lorenzo.pdf
 
The adjacent figure shows increase in nitrate concentration .pdf
The adjacent figure shows increase in nitrate concentration .pdfThe adjacent figure shows increase in nitrate concentration .pdf
The adjacent figure shows increase in nitrate concentration .pdf
 
The accompanying table includes only countries in the top te.pdf
The accompanying table includes only countries in the top te.pdfThe accompanying table includes only countries in the top te.pdf
The accompanying table includes only countries in the top te.pdf
 
TF 2 points each Total 20 points 1 A disadvantage of the .pdf
TF 2 points each Total 20 points 1 A disadvantage of the .pdfTF 2 points each Total 20 points 1 A disadvantage of the .pdf
TF 2 points each Total 20 points 1 A disadvantage of the .pdf
 
Textures in rocks can be used to identify and interpret the .pdf
Textures in rocks can be used to identify and interpret the .pdfTextures in rocks can be used to identify and interpret the .pdf
Textures in rocks can be used to identify and interpret the .pdf
 
The 600 AM CT surface temperature at Davenport on 25 Februa.pdf
The 600 AM CT surface temperature at Davenport on 25 Februa.pdfThe 600 AM CT surface temperature at Davenport on 25 Februa.pdf
The 600 AM CT surface temperature at Davenport on 25 Februa.pdf
 
thanks a lot for your help 126 Let X denote a realvalued.pdf
thanks a lot for your help 126 Let X denote a realvalued.pdfthanks a lot for your help 126 Let X denote a realvalued.pdf
thanks a lot for your help 126 Let X denote a realvalued.pdf
 
thanks will like answer 2615 Se presenta a continuaci.pdf
thanks  will like answer   2615 Se presenta a continuaci.pdfthanks  will like answer   2615 Se presenta a continuaci.pdf
thanks will like answer 2615 Se presenta a continuaci.pdf
 
Th productaon froor Dele sarepiois gomaned in the txere belo.pdf
Th productaon froor Dele sarepiois gomaned in the txere belo.pdfTh productaon froor Dele sarepiois gomaned in the txere belo.pdf
Th productaon froor Dele sarepiois gomaned in the txere belo.pdf
 
TH act probability 1pp Icp What do you notice about the pro.pdf
TH act probability  1pp Icp What do you notice about the pro.pdfTH act probability  1pp Icp What do you notice about the pro.pdf
TH act probability 1pp Icp What do you notice about the pro.pdf
 
The 2007 Nobel Prize in Physiology and Medicine was awarded .pdf
The 2007 Nobel Prize in Physiology and Medicine was awarded .pdfThe 2007 Nobel Prize in Physiology and Medicine was awarded .pdf
The 2007 Nobel Prize in Physiology and Medicine was awarded .pdf
 
thank you Letvon UIUAIUE aHo temytibiole This interactive g.pdf
thank you Letvon UIUAIUE aHo temytibiole This interactive g.pdfthank you Letvon UIUAIUE aHo temytibiole This interactive g.pdf
thank you Letvon UIUAIUE aHo temytibiole This interactive g.pdf
 
The 1986 Computer Fraud and Abuse Act a was never used to .pdf
The 1986 Computer Fraud and Abuse Act a was never used to .pdfThe 1986 Computer Fraud and Abuse Act a was never used to .pdf
The 1986 Computer Fraud and Abuse Act a was never used to .pdf
 
tgat is everything b Draw a Punnett square to illustrate a.pdf
tgat is everything  b Draw a Punnett square to illustrate a.pdftgat is everything  b Draw a Punnett square to illustrate a.pdf
tgat is everything b Draw a Punnett square to illustrate a.pdf
 
The 1000 accounts receivable of Gamco Company have a total .pdf
The 1000 accounts receivable of Gamco Company have a total .pdfThe 1000 accounts receivable of Gamco Company have a total .pdf
The 1000 accounts receivable of Gamco Company have a total .pdf
 

Último

Último (20)

21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Basic Intentional Injuries Health Education
Basic Intentional Injuries Health EducationBasic Intentional Injuries Health Education
Basic Intentional Injuries Health Education
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
latest AZ-104 Exam Questions and Answers
latest AZ-104 Exam Questions and Answerslatest AZ-104 Exam Questions and Answers
latest AZ-104 Exam Questions and Answers
 
Tatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsTatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf arts
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 

thank you PA 5 Fifteen Puzzle Topics Covered 1 Graphs 2 .pdf

  • 1. 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
  • 2. 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.