CS344M: Autonomous Multiagent Systems -- Fall 2012: Programming Assignment 2 (2D Version)
Programming Assignment 2 - 2D Simulator Version
for Autonomous Multiagent Systems (cs344M)
This assignment assumes the knowledge gained from assignment 1.
For the first assignment you used the "rcssclient" to allow you to
communicate with the simulator by hand. You will now alter a similar
client to perform some tasks automatically. 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 what makes it non-reactive in your email).
This assignment (and this entire 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.
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
right goal.) Remember that if the sequence you are looking for is not
present in the string you are searching, a null pointer is returned.
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/2d/sampleclient.
Instructions:
- Copy over the files in the sampleclient directory to any directory in your account:
% cp -r /projects/cs344M.pstone/2d/sampleclient/ .
- Go into your version of the sampleclient and compile by typing "make".
- In a new terminal window, start the soccer server (as you did in the previous assignment).
% rcsoccersim server::drop_ball_time=0 server::free_kick_faults=false
- Back in the other window, run the client:
% ./client
You will see the same behavior as last week. The agent is waiting for
you to type a command; if you send the init command "(init teamname (version
15))", the agent will display all of the percepts that it receives to
the screen.
Looking into the code (client.c), you will see that it uses select()
to read from multiple input streams: one for receiving input from the
server and one for receiving input from the shell.
Your task is to alter the client.c code so that the player does the following
without any input from the shell:
- Connect to the server with version 15 protocol.
- Immediately after connecting, it should move to a random place on
its side of the field "(move x y)". You can not assume that your player will
always be on the left side of the field - see the hints section for comments on how the server
provides you with your player's side. Be sure that your x and y are within
the field boundaries (see page 37 of the manual) - for example, for a player guarding
the left goal, -52.5 < x < 0, -34 < y < 34.
- It should find the ball, go to the ball, find the opponent's
goal - "(g r)" for the left team or "(g l)" for the right team - and
kick the ball towards that goal. The player should decide what to
do based only on its latest sight. It should send at most one command after
every sight it receives.
Hints:
- The player should send "(init <teamname> (version 15))" as
the first thing that it does. This message is
important, because the simulator won't send you anything
until you send it an "init" message.
- The response from the server to the "(init)" command tells which
side the player is on: (init [l/r]...) where "l" means left side and "r"
means right side.
- Parse responses from the server to find the distance
and angle (refered to as Direction in the manual) to the ball and/or the relevant goal (if they're in the
player's view). Page 33 of the manual (page 43 of the pdf) will be very helpful, as will looking at the console output.
- The format of visual information of sensation is:
(see Time Object*)
where "Time" is the current simulator time step (it will only increase
after you've told it to kick off) and "Object*" means that there will
be zero or more "Object"s. Each Object has one of the following forms:
(ObjName Distance Direction DistChng DirChng BodyDir HeadDir)
(ObjName Distance Direction DistChng DirChng)
(ObjName Distance Direction)
(ObjName Direction)
The ObjName variable can be many things, including:
(b) for the ball
(g r) for right goal
(g l) for left goal
For more information on the format of the sensation, look at page 33
(page 43 of the actual pdf) of the manual.
Note that sometimes if objects are close but outside of the viewcone,
they can still be "seen" in a rough manner (see page 37 of the manual for details).
- Decide on a single action (kick/dash/turn) with appropriate
parameters and send them to the server using the "send" (or
"send_message") command as is done in the current routine that accepts
keyboard input.
- Remember that you must click kickoff in the monitor window before your agent can dash.
Do this after you start your agent. Note that this means that you will have to restart rcsoccersim
each time you want to kick-off. Actually kicking off each time when you are testing and debugging is
not important - but you should start fresh when creating your logs to turnin.
- Beware of altering the socket protocol in the client. The
protocol implemented by the sampleclient is as follows: the init
message is sent to the server on port 6000. The server replies on a
different port, and all subsequent messages are to be sent to that
port.
- By default, a player is not allowed to kick the ball twice in a
row on a kick_off. That's why we turned that flag off when setting up the server (the server::free_kick_faults=false argument, in addition to the
server::drop_ball_time=0 argument which removes the time limitation for touching the ball). Other ways to deal with this issue (or several others, in the future) is starting the game with a drop ball (right-click in the simulator window). Or, you can turn
off this rule in the simulator by editing the ~/.rcssserver/server.conf file
(not the ~/.rcssserver-server.conf) - just remember to set it back to true once you are done.
What to turn in:
Run the same code, but this time start two players (one on each team).
Turn in a logfile that runs until at least one player scores or 1000
cycles (whichever comes first). If the players get stuck, you can
create drop-balls.
What to turn in:
A logfile called [yourlogin]-1on1.rcg
Create two players on the same team 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.
- 3.5 points if it doesn't work so well but still scores twice.
- 3 points if it scores just once
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 atleast 1 pass is completed. Having two players in a cluster with the ball in between them does not constitute a pass.
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, turn everything (three .rcg log files and two .c files) in to turnin (use assignment
label "prog2" and grader "eladlieb" ) and 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
Elad Liebman
Questions? Send me
mail