CS344M: Autonomous Multiagent Systems -- Fall 2008: 3D Programming Assignment 2
This assignments assumes the knowledge gained from assignment 1.
In this assignment, you
will implement some simple soccer-playing agents. All parts of this
assignment can be done with purely reactive behaviors. Please
describe in your email to us the extent to which your behaviors are
reactive. (It's OK if they're not, just make sure that if you create
an agent that is non-reactive in some way, you describe clearly why
not in your email).
This assignment (and all for this course) is about creating agents.
It's not about programming. If you have programming
questions/problems, etc. (e.g. "How do I generate a random number in
C?") ask the class list early and often.
A good debugging tool is to print stuff out, in C you can do it with printf or in C++ you can do it with cout.
Here is a simple example which should help (for more info check the printf reference):
#include <stdio.h> // This should be at the top of the file
...
char str[10] = "agents";
int num = 1;
double dbl = 2.0;
// It prints out the value of variables str,num and dbl.
// Notice the difference between %s, %d and %f.
printf("string: %s, int:%d, double:%f\n", str, num, dbl);
The output would be: "string: agents, int:1, double:2.000000"
A good method for parsing strings, is sscanf. Here is an example:
#include <stdio.h> // This should be at the top of the file
...
char str[20] = "((b) 23 1.5)";
int i = 0;
double dbl = 0;
// The integer value appeared at the place of the %d would go to the i variable,
// and the the double value would go to the dbl variable.
sscanf(str, "((b) %d %lf)", &i, &dbl);
printf("i:%d dbl:%f\n", i, dbl);
The output would be: "i:23 dbl:1.50000"
The
strstr()
function may also be useful. (Here is code that
parses a sample server message and find the distance and angle to the
ball.)
Also, the sprintf()
function is useful for creating strings with variable content. For
example, you can use sprintf() to create a
(dash N)
string for any number N.
C/C++ Reference
Score a goal
The code you will be modifying is in /projects/cs344M.pstone/3d/nao-agent.
Instructions:
- Copy over the files in the nao-agent directory to any directory in your account:
% cp -r /projects/cs344M.pstone/3d/nao-agent .
- Go into your version of the nao-agent and compile by typing "make".
- In a new terminal window, start the soccer server (as you did in the previous assignment).
% rcsoccersim3d
- Back in the other window, run the agent:
% ./agentspark --host=localhost --team myteam --unum 2 --paramsfile paramfiles/defaultParams.txt&
You will see the same behavior as last week.
Your task is to alter the code in strategy.cc that the player does the following :
- Immediately after connecting, it should move to a random place on
its side of the field (set values in the
beam()
method) where -9 < x < 0, -6 < y < 6.
- It should find the ball "(B", go the the ball, find the opponent's
goal posts, "(G1R" and "(G2R" for the left team or "(G1L" and "(G2L" for the right team,
and kick the ball towards that goal. The player should decide what to
do based only on its latest sight.
Hints:
- To determine which side a player is on use the
worldModel->getSide()
method which returns an enumerated value of either SIDE_LEFT
or SIDE_RIGHT
.
- Parse the string returned by the
worldModel->getLastVisionInput()
method to find the distance
and angle to the ball and/or the relevant goal posts (if they're in the player's view).
- The format of visual information for seeing an object is:
(ObjName (pol <radius> <theta> <phi>))
These values are in a spherical
coordinate system but you don't really need to understand this as
the VecPosition class makes it easy to convert from spherical to
cartesian coordinate values. Also it is a good idea to transform these
measurements from the robot's camera to be relative to its body origin
for better accuracy. Look at the code again in tst.cc to see an example of how to do this.
The ObjName
variable can be many things, including:
B for the ball
G1R and G2R for the top (left) and bottom (right) right
side of the field goal posts respectively
G1L and G2L for top (right) and bottom (left) left side
of the field goal posts
repectively
Look at page 35 of the 3d simulator manual
for a diagram of where the goal posts are.
Note that objects can only be seen in a 120 degree view cone.
- To determine if the agent is close enough to the ball to kick it call the
canKick()
method and see if it returns true
.
- When the agent is close enough to kick the ball you can then call the
kickBall(kickTypeToUse, direction, distance)
method. This will put the agent in an auto pilot mode to kick the ball in the specified direction. Parameters for kickBall
are the following:
kickTypeToUse: enumerated int value of KICK_LONG, KICK_MED, or KICK_DRIBBLE (any of these are fine)
direction: angle in degrees relative to agent's current orientation to kick the ball toward
distance: distance away from the agent that its desired target to kick the ball toward is
- If you want to cancel kicking the ball for whatever reason you can
call the
stopKickBall()
method.
- You can use
getTurn(angularOffset)
which returns the
best SkillType
for an agent to have it turn the amount of
degress specified by the angularOffset
parameter. A
negative offset causes the robot to turn clockwise while a positive
one causes it to turn counter-clockwise.
- Sometimes the robot will thrash or "dance" around for a bit while
trying to position to kick the ball. Also the robot will lose its
balance and fall over from time to time as well as miskick the ball.
These behaviors are OK and something we're working on to try and
improve (later on in the class you can look into improving
these behaviors if you like).
- Occasionally a goal is scored but the simulator records it as a
goal kick...this will not be counted against you.
- A good goal scoring agent can sometimes score 3 or more goals in
a half with a little luck.
What to turn in:
Run the same code, but this time start 2 players: 1 on each team. To do this just start two agents running but with different values for the --team
command line option.
Turn in a logfile that runs at least until one player scores or 120 seconds (whichever comes first).
What to turn in:
A logfile called [yourlogin]-1on13d.log
Create 2 players that pass the ball back and forth.
Try to do this reactively (i.e. without saving any state). If you do
something non-reactive, just point that out in the email describing
your approach and no credit will be deducted.
Hints:
What to turn in:
Grading
This assignment will be graded as follows:
Part 1:
- 4 points if it works smoothly and scores twice in a half.
- 3 points if it doesn't work so well but still scores
Part 2: 1 point if it works.
Part 3:
- 4 points if it works smoothly. (it's OK if the ball doesn't
go straight to the teammate, as long as the teammate can
go retrieve the ball and keep playing)
- 3.5 points if a couple of passes are completed, but it
doesn't seem like it could keep working (players get
bunched up, etc.)
- 3 points if 1 pass is completed.
Description:
- 1 point if you indicate an understanding of "reactive"
- .5 if you provide a poor description
- 0 if you don't provide a description
When you're done with all parts of the assignment, send us an
email to that effect with a brief description of your approaches and the extent to which the behaviors are reactive.
[Back to Department Homepage]
Page maintained by
Patrick MacAlpine
Questions? Send me
mail