CIG 2007 Car Racing Competition

TCP Communications protocol


The protocol for client-server communication was designed to be as simple as possible. In fact, it is so simple it's hardly even a protocol...

First of all, the client connects via TCP to the server, locally or remotely. The port number depends on how the server was started. The class TCPControllerOne listens on port 6524, and TCPControllerTwo on 6525. (Other than that, there is no difference at all between the two classes, and you can use whichever you want to control a single car. There are two of them just to make it easier to control two cars with different controllers over TCP.)

What happens then is that each time step (there are 500 time steps to a trial) the server sends the current state of the car and its environment, and the client responds with the action to take. The one exception is at the beginning of each trial (episode), when the server sends a message consisting only of the word "reset"; the client is not supposed to answer to this, but is supposed to clear its internal state if it has any, as the way points are re-randomized and the car(s) re-positioned.

The state information consists of an ascii string terminated with a line break, beginning with the word "data" followed by a space, and then followed by 22 space-separated fields. The first of these fields has the value "true" if there is another car on the arena, and the value "false" otherwise. The other 21 fields are all double-precision ascii-encoded real numbers, e.g. "0.25657235" and "2.5644562". Their ordering and approximate ranges are as follows:

speed0..5
angle to current waypoint -pi..pi
distance to current waypoint 0..400
angle to next waypoint -pi..pi
distance to next waypoint 0..400
angle to other car -pi..pi
distance to other car 0..400
own position (x) 0..400
own position (y) 0..400
own velocity (x) 0..5
own velocity (y) 0..5
own orientation -pi..pi
other car's position (x)0..400
other car's position (y) 0..400
other car's velocity (x) 0..5
other car's velocity (y) 0..5
other car's orientation -pi..pi
current waypoint's position (x) 0..400
current waypoint's position (y) 0..400
next waypoint's position (x) 0..400
next waypoint's position (y) 0..400


Of these fields, the first seven can be classified as first-person, or local frame of reference, information. Conversely, the last fourteen are better seen as third-person, or global frame of reference, information. Experience has shown that using first-person data is usually strongly advisable when constructing your controller; however, the third-person data is more complete and is included here for those that want to do their own coordinate transformations and/or construct complicated models (e.g. of the dynamics of the own car and behaviour of the other car).

Once the state information has been received it's up to the controller to respond with what action to take. Fast. If the server has not had a response within 50 milliseconds, the program is aborted and the controller disqualified; in fact, you should subtract a few milliseconds from this value to allow for the idiosyncracies of the TCP/IP stack. Such haste is necessary for the game to be able to run real-time.

The message the server expects is simply an integer, in ascii representation, followed by a line break. There are nine possible actions:

backward left 0
backward 1
backward right 2
left 3
neutral 4
right 5
forward left 6
forward 7
forward right 8


And that is all of the protocol. Creating a very simple controller is doable in just a few lines of code: parse out the speed and angle to the next way point from the data, drive forward if the speed is below some low threshold and keep neutral otherwise, steer left if the next way point is to the left and right otherwise. Return the action.

Of course, that will not be enough to win the competition, or even the supplied example controllers. To start with, the car has momentum and the steering problem becomes considerably more difficult at higher speeds. And then there's the issue of the other car, and deciding when to leave the current waypoint to the other car and go for the next one instead. Just to mention two complications.

Once again: good luck with creating a controller using your technique and language of choice!