Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Develop a program that can read in a maze from a text file and solve it using the JGraphT library. Extra credit: Display an animated

Develop a program that can read in a maze from a text file and solve it using the JGraphT library. Extra credit: Display an animated graphical solution to the maze. 1. Use this web site to generate a maze and save it to a text file: http://www.delorie.com/game-room/mazes/genmaze.cgi 2. Created an undirected graph: UndirectedGraph g = new SimpleGraph(DefaultEdge.class); 3. Read the text file and convert it to an undirected graph using the JGraphT library. Begin by reading a line, and adding every character as a vertex: while (infile.hasNext()) { PreviousLine = ThisLine; ThisLine = infile.nextLine(); // step through each character of ThisLine in a for loop // if the character is a space, add it as a vertex: g.addVertex(x+":"+y); // Add edge if the character to the left is a space: g.addEdge((x-1)+":"+y,x+":"+y); // Add edge if the character above is a space: g.addEdge(x+":"+(y-1),x+":"+y); y++; } 4. Print the vertex set and edge set: g.vertexSet() g.edgeSet() 5. Use DijkstraShortestPath algorithm to solve the maze: DijkstraShortestPath Path = new DijkstraShortestPath(g, BeginVertex, EndVertex); 6. Print the Path and Length: Path.getPath() Path.getPathLength() Example Output Maze line 0: ************* line 1: * line 2: * ******* * line 3: * * * * line 4: * * * **** line 5: * * line 6: ************* Vertex Set [0:1, 1:1, 2:1, 3:1, 4:1, 5:1, 6:1, 7:1, 8:1, 9:1, 10:1, 11:1, 1:2, 2:2, 10:2, 11:2, 1:3, 2:3, 4:3, 5:3, 6:3, 7:3, 8:3, 10:3, 11:3, 1:4, 2:4, 4:4, 5:4, 7:4, 8:4, 1:5, 2:5, 3:5, 4:5, 5:5, 7:5, 8:5, 9:5, 10:5, 11:5, 12:5] Edge Set [(0:1 : 1:1), (1:1 : 2:1), (2:1 : 3:1), (3:1 : 4:1), (4:1 : 5:1), (5:1 : 6:1), (6:1 : 7:1), (7:1 : 8:1), (8:1 : 9:1), (9:1 : 10:1), (10:1 : 11:1), (1:1 : 1:2), (1:2 : 2:2), (2:1 : 2:2), (10:1 : 10:2), (10:2 : 11:2), (11:1 : 11:2), (1:2 : 1:3), (1:3 : 2:3), (2:2 : 2:3), (4:3 : 5:3), (5:3 : 6:3), (6:3 : 7:3), (7:3 : 8:3), (10:2 : 10:3), (10:3 : 11:3), (11:2 : 11:3), (1:3 : 1:4), (1:4 : 2:4), (2:3 : 2:4), (4:3 : 4:4), (4:4 : 5:4), (5:3 : 5:4), (7:3 : 7:4), (7:4 : 8:4), (8:3 : 8:4), (1:4 : 1:5), (1:5 : 2:5), (2:4 : 2:5), (2:5 : 3:5), (3:5 : 4:5), (4:4 : 4:5), (4:5 : 5:5), (5:4 : 5:5), (7:4 : 7:5), (7:5 : 8:5), (8:4 : 8:5), (8:5 : 9:5), (9:5 : 10:5), (10:5 : 11:5), (11:5 : 12:5)] Solution Path [(0:1 : 1:1), (1:1 : 1:2), (1:2 : 1:3), (1:3 : 1:4), (1:4 : 1:5), (1:5 : 2:5), (2:5 : 3:5), (3:5 : 4:5), (4:4 : 4:5), (4:3 : 4:4), (4:3 : 5:3), (5:3 : 6:3), (6:3 : 7:3), (7:3 : 8:3), (8:3 : 8:4), (8:4 : 8:5), (8:5 : 9:5), (9:5 : 10:5), (10:5 : 11:5), (11:5 : 12:5)] Length of Solution Path = 20.0image text in transcribed

Uaalopa program that can raad in amaza tomaox ia and soa t uing a Jraphl Ibrary Eac Lpay an animatad graphical solution to tha maz4. 3 Raad tha t t Mia and an er t tn an undrar d crach "sina tha lGra hl i ray Hagin hy rAA ng a lna and adding er, charar era" wrte ie intiie.haoet O) // th. rha r".r 1x p.cp, "da tt. qre rtex: sterr-xlx+" : " +v, ; AX .a // add "dge if the ther83ter store 1 . Brace ; .5ddTdge Ix+":"+/y1; , x-' :"4y| ; 4 Frintthavanax salan:1 "ins" m.ve-T.x?^) .e..neSerI: H Frint tha Path and 1 00th.-"h.qet.Panh 11 p,ch-7--P.th".m7rh : 1in2 1: Edre Set 2:412:3 : 2: 12:55:12: Uaalopa program that can raad in amaza tomaox ia and soa t uing a Jraphl Ibrary Eac Lpay an animatad graphical solution to tha maz4. 3 Raad tha t t Mia and an er t tn an undrar d crach "sina tha lGra hl i ray Hagin hy rAA ng a lna and adding er, charar era" wrte ie intiie.haoet O) // th. rha r".r 1x p.cp, "da tt. qre rtex: sterr-xlx+" : " +v, ; AX .a // add "dge if the ther83ter store 1 . Brace ; .5ddTdge Ix+":"+/y1; , x-' :"4y| ; 4 Frintthavanax salan:1 "ins" m.ve-T.x?^) .e..neSerI: H Frint tha Path and 1 00th.-"h.qet.Panh 11 p,ch-7--P.th".m7rh : 1in2 1: Edre Set 2:412:3 : 2: 12:55:12

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Programming The Perl DBI Database Programming With Perl

Authors: Tim Bunce, Alligator Descartes

1st Edition

1565926994, 978-1565926998

More Books

Students also viewed these Databases questions

Question

3. What is the mean world syndrome?

Answered: 1 week ago