CS378: Autonomous Multiagent Systems -- Fall 2003: Programming Assignment 2


Programming Assignment 2 for Autonomous Multiagent Systems (cs378)


 

This assignments 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. If you create an agent that is non-reactive in some way, please note it in your email to us.

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. 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.)

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/cs378.pstone/sampleclient.

Instructions:

  1. Copy over the files in the sampleclient directory to any directory in your account:
      % cp -r /projects/cs378.pstone/sampleclient/ .
    
  2. Go into your version of the sampleclient and compile by typing "make".
  3. In a new terminal window, start the soccer server (as you did in the previous assignment).
      % rcsoccersim
    
  4. 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 (version 9.3))", 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 code so that the player does the following without any input from the shell:

Hints:

What to turn in:

  • A logfile of your player scoring 2 goals. After the first goal, right-click somewhere on the field to create a "drop-ball" so that the player can go score again. Name the logfile "[yourlogin]-score.log"
  • Your modified source code called [yourlogin]-score.c with your changes commented prominently with "CHANGE."

  • 1 on 1

    Run the same code, but this time start 2 players: 1 on each team. Turn in a logfile that runs at least until 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.log


    Passing

    Create 2 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:

  • You may need to make the player back up or go back to a point after getting the ball so that they don't keep running into each other.
  • You may find it helpful to turn off the offsides rule in the simulator for this part of the assignment. To do so, change the use_offside line in your lcoal copy of .rcssserver-server.conf (as described above): change the line
    use_offside: on
    
    to
    use_offside: off
    
  • What to turn in:

  • A logfile called [yourlogin]-pass.log
  • Commented source code called [yourlogin]-pass.c.

  • Grading

    This assignment will be graded as follows:

    Part 1:

    Part 2: 1 point if it works.

    Part 3:

    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.

    [Back to Department Homepage]

    Page maintained by Peter Stone
    Questions? Send me mail