Pathfinder: A path finding game.

Friday, October 30, 2009 17:56

Pathfinder is all about finding a path between point A and point B.  The GUI portion, provided for us, is sectioned off into a grid of ‘tiny’ squares where two are colored turquoise (set by programmer), in my case one on the mid left and the other on the mid right side of the grid.  You start by clicking on squares filling them in to create lines/walls to make obstacles between the start and finish point.  Then once you are done with that you click ‘Find Path’ and the program searches for a path, if one is not found then you see nothing, otherwise if the algorithm was able to find a path the GUI is updated to display the path using green squares.

The following are screen shots of the program:

Squares filled in before clicking find path.

Squares filled in before clicking find path.Clicked 'Find Path' and the shortest path is shown in green.

Clicked 'Find Path' and the shortest path is shown in green.

Clicked 'Find Path' and the shortest path is shown in green.

When I started this project I first read through all the code provided to us and then once I figured I had a grasp of the code I decided to just dive in and start coding and within three hours I had a semi-working program.  I started with implementing the equals method and hashCode method in the Location class, which thankfully never had to be changed throughout my journey of re-implementations.

My first implementation was using vectors, which ”worked” but was very slow do to the seek times in finding the proper way points while performing certain functions.  I left it running over night just to see if the one case would ever solve, and it just seemed to sit there.  The program never crashed and when I checked my CPU usage it had sky rocketed.  I then decided that a 2D array would provide a constant seek time.  At first glance this appeared to work flawlessly; that is, until you try to find a path where none exists, then you get a lovely null pointer exception and the program crashes as it tries to find a path outside of its bounds.  I figured now would be a good time to give a thorough read of the assignment and I was more formally introduced to classes HashMap and HashSet which made my life a dream.  When applying this concept to storing way points as open or closed the program worked flawlessly.  The variable declarations are as follows:


/** Stores open way points **/
private HashMap<Location,Waypoint> openHashMap;
/** Stores closed way points **/
private HashMap<Location,Waypoint> closedHashMap;

Note that since this is a school project nothing beyond the requirements was added (hence no About section or anything like that).

Windows (all): Pathfinder (exe)
Linux (right click and open with Java): Pathfinder (jar)
Mac users should be able to use the same as Linux.

Windows users can use the jar version too if they prefer.  When downloading the jar version, make sure it has the extension .jar (ie: in windows may try to download as .zip, replace zip with jar).

You can leave a response, or trackback from your own site.

One Response to “Pathfinder: A path finding game.”

  1. Niketan says:

    November 11th, 2009 at 8:22 AM

    please, send me source code of this project

Leave a Reply