All agents should assume that they are defending the east goal and attacking the west goal. All directions will be "magically" swapped by the simulator if the team is actually defending the west goal. ----------------------------------------------------------------------------- Technical notes for writing Tcl Soccer agents in C: When writing agents in C rather than Tcl, the main thing we need to worry about is collisions between function names and global variable names for two teams playing against each other. In Tcl, each team gets its own interpreter with its own name space, so there are no problems. However, all the shared libraries compiled from C share the same name space, so we need to do some special things to make sure the east code and the west code don't collide with each other. Put your main body of code in the file main.c and use the Makefile provided with the example C agents (cexample and crollers) to compile your code. This will create two shared libraries, called east.so and west.so. One or the other will get loaded depending on which side your team plays on. You should still write all of your code as if your team members are defending the east goal. However, at the top of your main.c file, you should include a macro for EVERY function name and EVERY global variable name that you use. The macro should look like these: #define Function1 UN(Function1) #define Function2 UN(Function2) #define globalVar1 UN(globalVar1) #define globalVar2 UN(globalVar2) This macro will cause each instance of Function1 to be changed into EASTFunction1 in east.so and WESTFunction1 in west.so. This should ensure that any two teams playing each other will not have any collisions in the global name space. You don't have to define these macros for local variables (although it shouldn't hurt if you do). However, you must do this for all global variables and functions or you risk having your team (or the opposing team) accessing the wrong information. ----------------------------------------------------------------------------- Tcl Soccer agents written in the C language should include at least the following functions: void InitializeGame() Special code to execute before a game starts. void InitializePoint() Special code to execute before each point starts. void WonPoint() Special code to execute after the team wins a point. void LostPoint() Special code to execute after the team loses a point. void GameOver() Special code to execute after the game ends. char *Player1() char *Player2() char *Player3() char *Player4() The code to determine the next move for each player. A compass direction attempts to move the player one square in that direction (possibly moving the ball if it's in the way). "PLAYER" means the player will stay in its current spot. "KICK" means the player will attempt to KICK the ball, if possible. The player will also move into the square that the ball was in, if the ball moves. Valid return values are: "N", "NE", "E", "SE", "S", "SW", "W", "NW", "PLAYER", "KICK" ----------------------------------------------------------------------------- Tcl Soccer agents written in the C language have access to the following functions: int XSize() Returns the size of the field from east to west, in number of grid squares int YSize() Returns the size of the field from north to south, in number of grid squares char *View(char *dir) Returns the contents of the square one step away from the player in the direction of dir. Valid values for dir are "N", "NE", "E", "SE", "S", "SW", "W", "NW", or "PLAYER". Possible return values are: "EMPTY", "BALL", "TEAMMATE", "OPPONENT", or "OUT". A return value of "OUT" indicates that the square is beyond the edges of the field. int Content(char *dir, char *item) Checks the contents of the square one step away from the player in the direction of dir, and compares those contents to item. If the contents match the item, then return 1, else return 0. Valid values for dir are "N", "NE", "E", "SE", "S", "SW", "W", "NW", or "PLAYER". Valid values for item are "EMPTY", "BALL", "TEAMMATE", "OPPONENT", or "OUT". Possible return values are: 0 or 1. int Sideline(char *dir) Checks whether the square one step away from the player in the direction of dir is a sideline square (along the north or south edge of the field). Returns 1 if it is a sideline square or 0 otherwise. Valid values for dir are "N", "NE", "E", "SE", "S", "SW", "W", "NW", or "PLAYER". Possible return values are: 0 or 1. int Goal(char *dir) Checks whether the square one step away from the player in the direction of dir is a goal square (along the west or east edge of the field). Returns 1 if it is a goal square or 0 otherwise. Valid values for dir are "N", "NE", "E", "SE", "S", "SW", "W", "NW", or "PLAYER". Possible return values are: 0 or 1. char *BallDir() Returns the direction to the ball (rounded to one of the eight valid directions). Possible return values are: "N", "NE", "E", "SE", "S", "SW", "W", or "NW" int BallDist() Returns the minimum number of steps from the player square to the ball square (assuming nothing gets in the way). Possible return values are: Any integer between 1 and the longest dimension of the field (usually YSize()) char *OpponentDir(int n) Returns the direction to the nth closest opposing player (rounded to one of the eight valid directions). Valid values for n are 1, 2, 3, or 4 Possible return values are: int OpponentDist(int n) Returns the minimum number of steps from the player square to the nth closest opposing player's square (assuming nothing gets in the way). Valid values for n are 1, 2, 3, or 4 "N", "NE", "E", "SE", "S", "SW", "W", or "NW" Possible return values are: Any integer between 1 and the longest dimension of the field (usually YSize()) int MyX() Returns the player's X coordinate on the field. 1 is the westernmost "column" of the field, and XSize() is the easternmost column of the field. Possible return values are: Any integer between 1 and XSize() int MyY() Returns the player's Y coordinate on the field. 1 is the northernmost "row" of the field, and YSize() is the southernmost row of the field. Possible return values are: Any integer between 1 and YSize() void Debug(char *msg) Logs the msg string into the debug window for the team. The argument msg can be any string of characters. No return value.