Sunday, June 5, 2016

Path Finder part 1

Welcome to the Path Finder tutorial. While there are a lot of algorithms for solving mazes, those are well documented and countless examples can be found on the internet. Here we will attempt path finding by brute force mega searching/roaming. I just made that term up. Below is a picture of the maze. The white blank squares are walls. The green tiles are open spaces (think of them as grass you can move about on.) The blue square is the "player" which will roam around and try to get to the "goal" by learning about the maze. In part 2, we will begin the roaming process.

The maze

I will explain the numbers in later sections. For now, think of it as wandering around a maze a lot and eventually finding the best path. Hopefully that is what will happen by the time we are done.

Please note that this program uses libgdx for graphics. The game loop was taken from http://www.kilobolt.com/ which has an EXCELLENT tutorial on making a Flappy Bird clone. Even if you don't want to make a Flappy Bird clone, you should check it out. I would strongly recommend completing their tutorial before checking out this path finding program. That being said, all of the graphics are taken care of and we will only be dealing with one java class. This is the class that has the logic in it. If you do their tutorial you should be able to understand most of the graphics stuff in this tutorial. However, if you are like me, you can just ignore it and be content that it has already been done. Feel free to modify it if you begin to understand it. Just know that that part of the program will not be explained. Setting up Eclipse so that it can run is also covered in the kilobolt.com tutorial. Basically what I am saying is go do the Flappy Bird clone and understand it, or at least do the parts that you need to get Eclipse working. If you are having problems, check the comments on that site for help. Or comment here. Anyways, big thanks to that site for opening the doors to libgdx. You'll notice that I borrowed heavily from their setup for the game loop. The rest is mine though!

The project so far can be downloaded right here (Click download on the top right) Right click it after downloading and click "Extract to PathFinder". Open up Eclipse and go to File -> Import. Select Gradle -> Gradle Project. Select the folder you just extracted. *Make sure you have the right root folder selected or the import won't work*

Once imported, you should have a list on the side that looks like this:



If you see that, you are good to go. As you can see, I didn't even change the name from their game. Libgdx can be a pain to set up so it was easier to just delete the game and start from there. The set up actually makes this an iPhone/Android application, so theoretically at some point this could go on your phone. Ignore that there are errors in the bottom two directories. The only two that we need to work with are "core" and "desktop."

If you expand out "desktop" you will see a folder called "src" and if you keep expanding you will find "DesktopLauncher.java" The name describes what it does. Double clicking it won't run it, but will open it up. The code inside is pretty self-explanatory. Right clicking it however will give you a menu. Right click and select "Run As" and select "Java Application." If this doesn't show up, go to "Run As" and click "Run Configurations." Then find "Java Application" and run it.

All the program should do now is open up a window as shown above. In the next part, we will take a look at "ArenaManager.java"

This will be the only class that we will be dealing with since this tutorial is simply about path finding and not libgdx or java. ArenaManager.java is located in "core/src/zbHelpers" Double click it to open it. Then join me in part 2 where we will start to search this path.


One again, a very special thanks to kilobolt.com for their excellent tutorial. I've made several games using their tutorial as a template. I strongly urge you to complete it and then come back. Or don't and let's solve mazes!

No comments:

Post a Comment