Potential Fields Lab

The purpose of this lab is to give you experience with simple reactive agents using potential fields as a form of “intelligence.” You will do the following:

  • Code up attractive fields
  • Code up repulsive fields
  • Code up tangential fields
  • Use all three fields to help a BZRFlag agent capture an enemy flag, return to your base with the flag, and win the game!

No internal states will be allowed for your agent. All actions should be based purely on the current state of the world. With two exceptions 1) when coding the PD controller, you will need to compute the derivative of (change in) the error, so you can keep your previous error, and 2) You can use the fact that you are holding the flag to know that it is time to return to your base.


Assuming you already completed the BZFlag Tutorial Homework, you should have everything you need for this lab. Jonathan Nielsen got BZRFlag to work on Windows and was nice enough to share his accomplishment with everyone else. A tutorial for setting it up is at BZRFlag on Windows.

What you need to do

In contrast to the BZFlag Tutorial Homework where you used telnet and your own intelligence to control the tanks, in this lab you will build a program to control the tanks. You can do this in any language you want and you can even run it on a variety of platforms. HOWEVER, we can only help you on Linux and in Python and C++. You are welcome to try other things but you will be more or less on your own.

You will be responsible for building code to open a socket, sending commands and listening for the responses. You are strongly encouraged to hunt around on the web for resources. If you find something useful please post a link on the discussion tab of this page. The sample code we give you is intended to be one such resource. As you write your networking code, start simple. Just use a synchronous model, you can add threads later, but you can build a successful agent without them. Go on a date instead of adding threads!

A sample agent in Python has been provided in the bzrflag/bots directory, agent0.py. Please appreciate this code for what it is. While bzrc.py is a separate file that looks like a library, it is not intended to be a polished product. Depending on your language and programming environment, this code will serve as either a starting point or a helpful outline. From now on, this is your code.

There are also other pre-compiled bots in the ~cs470s/bzrflag/bzagents/compiled directory (agent1.pyc, agent2.pyc, and agent3.pyc). Throughout the labs, feel free to run these pre-compiled versions to have simple agents to test your code against. runme.sh shows how to use the pre-compiled agents. agent1.py is smarter than agent0.py, and agent2.py is smarter than agent1.py. agent3.py currently is only very slightly better than agent2.py; you probably can't tell the difference between them. None of them are particularly intelligent - by the end of class I imagine you should be able to beat each of them, especially in complicated worlds.

Some sample code has also been written in C++: 470bot.h and Lab1_Main.cpp. Unfortunately, this code is much less cool than the sample Python agent, but again, it is a starting point to help you write your agent.

In addition to the code you will need to communicate with your tank and to determine what it should do (potential fields), you will also need code to visualize your potential fields. Use gnuplot for this visualization. See the Gnuplot hints page for more information.

Really Dumb Agents

Once you have the basic socket communication working build a really dumb agent. This agent should repeat the following forever:

  • Move forward for 3-8 seconds
  • Turn left about 60 degrees and then start going straight again

In addition to this movement your really dumb agent should also shoot every 2 seconds (random between 1.5 and 2.5 seconds) or so.

Once you have one tank doing this, create a team that has two such agents.

Hey, you can do better than that!

Now create a simple reactive agent. You will do this using potential fields. Refer to the potential field tutorial on the schedule. You must build a potential fields based reactive agent (the “pf” agent) which implements the following fields:

  • Attractive fields
  • Repulsive fields
  • Tangential fields

Use all three fields to help a BZRFlag agent capture an enemy flag and return it to your base. N

Use the visualization code described above so that you can see your fields. You will also need visualization for your lab report.

That is, I THINK you can do better than that

You will need to test your pf agent as follows:

  1. Run your pf agent against your “Really Dumb Agent”. Your pf agent should win, although you will have to do some tuning to win
  2. Run against two dumb agents, you should win
  3. Run your pf agent against another copy of itself
  4. Find another group, run your pf against their “Really Dumb Agent”, you should win again
  5. Run against two dumb agents from the other group, you should be able to win
  6. Run your pf agent against their pf agent. Note that your grade does NOT depend upon which team wins, but it does depend upon what conclusions you can draw from the experience.

Do each of these tests in the four l's world and in the rotated box world (both of these are already in bzrflag/maps).

How To Pass Off

To pass off this lab, you will need to do the following:

  • Email the following to the TA
    • All of your agent code
    • A declaration of time spent by each lab partner
    • A writeup of your experience with the lab

It is NOT required that the you demonstrate in person to the TA that your agent (using potential fields) can capture the enemy flag (guarded by two “Really Dumb Agents”).

The writeup should describe in detail what all of the fields do and why you coded them in the manner that you did. Do not just say, “I used an attractive field,” Go into detail. Plot graphs of what the field looks like and put those into the paper. Plot them individually (attractive, repulsive, tangential, and any others that you came up with) and together. Explain your tuning process and what alternative you considered.

You must also comment on your results for each of the test scenarios listed above. Do not just say “we won”. What cool behaviors have you been able to create in your implementation? How did you do against someone else's dumb agent?

You must report (briefly) on the results the “other group” had against you. Include their names to so that we can verify that everyone “passed off” against someone. Also give the names of the people you passed off against, again, make sure you say how you did.

Though the paper need not be very long, do a nice job and make it look professional. I sort of expect to see a couple of pages of text and many graphs of your fields. One of the best ways to get a professional looking paper nearly for free is to use LaTeX, so that is what I recommend. PDF files are always appreciated, Postscript, Word, and Open Office are fine as well.


The lab will be graded out of 100 points, with break downs in the following way:

  • 10 points for coding the Dumb Agent and getting it working (i.e., if you get nothing else done except for the Dumb Agent, you get 10 points)
  • 50 points for the potential fields implementation and description
    • 30 points for the writeup and implementation of each of the three types of fields (why you picked what you did, and how you did it)
    • 15 points for graphs of the potential fields
    • 5 points for a description of the tuning process for your potential fields
  • 40 points for testing your agents
    • 15 points for the three tests that are done on your own
    • 25 points for the three tests against another team and your description of them (which is a longer description than the previous three tests)

Failing to follow directions in other areas (like saying how much time was spent and submitting code) will take away points.


Thanks to Chris Monson, Andrew McNabb, David Wingate and Kirt Lillywhite

cs-470/potential-fields-lab.txt · Last modified: 2015/01/06 14:45 by ryancha
Back to top
CC Attribution-Share Alike 4.0 International
chimeric.de = chi`s home Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0