The purpose of this lab is to give you experience with various kinds of search. You will code up several of them and see a graphical representation of how they work in the bzrflag world. Specifically, you will do the following:
<!–
You should also be able to explain your code to the TA.
If you have cloned the BZRFlag repository, be sure that you pull before starting work on this lab! I have made several updates that you need in order for this lab to work (as of May 6, commit 7f7a45c…, it should work).
As before, you will use bzrflag as a framework for your searches. However, bzrflag models a continuous world. Before we can use any of the search techniques which we discussed in class, we need to “discretize” the world. You will use the occgrid command in the BZRC Protocol to make a grid of spaces.
You will need to create a structure to represent this search space. Since the whole point of searching is to find a valid path to the goal, you will need to mark the search states that are occupied by obstacles (occgrid tells you this). Your search must not visit these nodes.
Your code must work on any map (see the maze1.bzw in the maps directory of bzrflag, for example). Your code should also work for any level of discretization. The occgrid in bzrflag uses a fixed level of discretization, one square for every meter in the world (if the world size is 800 by 800, for example, we have 640000 nodes in the graph). When you ask the server for the occgrid, it will give you back a matrix. Use that matrix as your graph for your search.
Because 640000 nodes is a lot of nodes in the graph, we will be using a smaller world size for this lab (and this lab only). This is the command you need to run when you pass off (though you can play around with other maps and world sizes if you feel like it):
bin/bzrflag --world-size=400 --world=maps/small_maze1.bzw --occgrid-width=800 --seed=1 --red-tanks=1 --green-tanks=1
The seed is so that the tanks are initialized in exactly the same spot, so that your code and my code should get exactly the same results, assuming we both coded the algorithms correctly. With a smaller world size you will only have 160000 nodes to deal with, which takes much less time. The occgrid width of 800 means that no matter where your tank is, you will get a graph of the entire world.
My Python code that wasn't meant to be particularly fast took about 15 seconds from startup to showing the path according to A* search. I didn't do gnuplot or graphs, I just printed it out, so yours may be slower than that, but mine was Python - it shouldn't be much slower for one search. Most of the time was building the graph, anyway, so doing multiple searches shouldn't take too much longer, either.
Also, when you do searches in future labs (and you definitely should), you almost certainly should not discretize the world this way; it's way more granular than you need and takes way too long to be reasonable during an actual game (plus you probably won't have access to such a nice occgrid command). This is just to get some practice with searching. That also probably means you want to keep your search code separate from your build-the-graph code, so you can reuse your search code with a different graph for future labs.
You will implement several different searches to find a path from your current position (the search state you are currently in) to the enemy flag (the search state that contains the flag). You will implement the search algorithms listed above.
For each search, you will draw lines when you expand a node (showing which children will be considered). You will also draw lines in the world indicating which path is ultimately chosen. You will draw these using gnuplot as you did to draw your fields in Lab 1.
You do not have to move your tank along the search path yet (that will be in the next lab). You only have to display the progress of your search and the final path.
From any state you may go to a neighboring state or a diagonally neighboring state. Please consider these states in the following order: left (x-1,y), right (x+1,y), up (x,y+1), down (x,y-1), diagonal up-left, up-right, down-left, down-right. Remember also that your search space is a graph. Use the graph search code (see section 3.5 of the book) so that you do not repeat states. Since you will generally have come from one of your 8 neighbors, there will generally be 7 or fewer places you can go next.
For the Greedy and A* searches, you should use the distance as the cost (diagonal moves will cost more (<math>\sqrt{2}</math>) than non-diagonal moves).
There are areas that you do not want to get close to. You must also have an option that allows you to increase the costs of space you travel through that is close to obstacles (“penalized mode”). You will run your code both with and without “penalized mode” set.
“Penalized mode” should work as follows:
Note that the occgrid command will only give you information about obstacles, not about enemy tanks. The “occupied cells” mentioned above should include not only obstacles but also enemy tanks. Use the othertanks command to get that information and incorporate it into your edge costs. You should be able to move an enemy tank to a point along what used to be the optimal path and see that the path changes.
Experiment with these values to see if you can get desirable behavior (obstacle avoidance), report on these values during the pass off. Try changing the penalty in other ways, like slightly penalizing cells 2 cells from an obstacle.
Grading will be done on the basis of the path costs (optimal search algorithms should find the optimal path for a given discretization), memory and CPU usage (just make sure it is not out of control), and the correctness of the visited nodes (number of nodes in the visited/closed list). You will also be graded on your creativity and efforts to find a penalty function that behaves well in the presence of walls, obstacles, and enemy tanks.
A discussion of gnuplot (a tool for drawing the lines in the search) and animation is available here. If you want to use something else to make these drawings, you are welcome to do so, but drawing packages can be a big distraction. Don't spend too much time making your own solution to the drawing problem.
You will need to pass off your lab to the TA. You will do so by demonstrating the following:
It would be appreciated if you could create scripts to easily start these things in order so you can do this quickly. If someone makes a handy bash script, you are welcome to post it here
This lab is again out of 100 points. There is no write up, so your grade will just be based on demonstrating to the TA that your code works. You will get points according to the following scale:
I realize also that a 400×400 grid is very hard to visualize all at once - each line for an edge followed would be very small. So, I think it reasonable to demonstrate the behavior of the searches on a small part of the grid next to the starting tank (where it can be larger and more visible), then show the overall result separately. Showing the overall result (a line from the tank to the flag) is important because that's the only way to really tell that the penalization code works properly - the line should change if I move a tank.
You don't need to turn in a lab report for this lab, but please send the TA email with a declaration of how much time was spent by each person in your group on the lab.
<!–To pass off this lab, you will:
This report should be thorough. Go through all of your experiments in such a way that they could be replicated by someone reading your paper. If you have had experience writing conference papers before, make your paper look like one of those, including an abstract, lab context, and details about what you tried. Make sure that your report includes information like what heuristics you used. Try searches with inadmissible heuristics as well and report on the optimality of the resulting searches.
Specifically, you will need to include information about the following:
Perhaps most importantly, put your results into a format that is easy to understand at a glance. Some- times that means that you want to put things into a graph, and sometimes it doesn’t. Be creative, and consider that your audience wants to get maximum understanding with a minimum of effort.–!>
Thanks to Chris Monson, Andrew McNabb, David Wingate and Kirt Lillywhite