IJ. Air hockey

Bertie's gang often meets other motorcycle gangs. Although the members are all mostly peaceful human beings, from time to time there are confrontations. To spare motorcycles and human lives, gangs have worked out a less costly method for settling their disputes: they all visit a local pub that runs a special air hockey game built for 30 players enabling at most 30 gangs to play the same game. Bertie quickly figures a simple rule - who rules air hockey rules the land. After several years of training at the game, he realizes this is something better done by computers (the Gang Code doesn't prohibit that).    air hockey

Your task is to develop the best air hockey AI (to be used by Bertie in the future) that beats any other player - allowing Bertie to rule all other gangs with an iron fist. All other teams at Challenge24 got the same task. Bertie wants to pick the best AI by the end of the day. To compare AIs at Challenge24, there will be tournaments where all 30 teams shall participate. Tournaments are scheduled at regular, preset times.

To be able to test your AI, you'll get your own 30-player table (this is what we call the "practice server"). You can play this game alone any time during the contest. The practice table comes with a few automated puck-guns and there are some for-score practice setups to prove your AI can handle some simple situations.

Game rules and physics

To avoid corner cases (literally) the table is mostly a round shape. Each player controls a small circular mallet by accelerating it within a given zone. There is a handful of pucks, which are also circular, that can freely move on the desk (or rather, slightly above the desk as they are hovering on high pressure air, providing essentially friction-free movement).

Players also have a short goal line in the middle of the backside of their zone. Any time a puck crosses the goal line, the team gets negative score and the puck is returned on the table (after a certain delay).

A player of this game should control their mallet to kick incoming pucks away from their goal line and shoot them in other teams' goal lines.

There is a way teams can receive positive scores. Ideally the team who "scored" the goal should receive a positive score - but deciding which team scored the goal is slightly complicated (because there are many pucks and many teams in the game at the same time). Every puck carries a sorted, timestamped list of which team's mallet touched it and when. When pucks collide, the lists of the two pucks are merged, and both pucks leave with the same merged list. If a team touched both pucks, only the more recent touch is recorded in the merged list. If there's a goal, the puck's carried list is checked. The team with the most recent touch will receive a positive score, except if it's the same team who receives the goal; in that case, the team with the second most recent touch will receive the positive score.

Specific sizes, velocity and acceleration limits and scores are transmitted as part of the communication protocol.

The physics should mostly work as expected, but you can always make measurements to determine the precise dynamics.

Networking, protocol

The standard game table features an Ethernet connector for control and monitoring. The firmware detects the position of all moving objects precisely and reports them in a series of UDP broadcast status update packages periodically. Furthermore each player (at most 30) shall connect to a specific TCP port where the firmware sends all game constants and then accepts mallet control commands from the player. Both protocols are simple, line based text protocols. Fields written in italic are numbers.

Status updates

UDP status messages
format description
t K P status at time tick K; there are multiple UDP packets per tick and this is Pth one (starting from 0)
g A B team A scored a goal against team B (A can be -1 to indicate "no team"); both are integers
m T X Y XV YV team T's mallet is at (X, Y) and has velocity (XV, YV)
ID T1 T2 X Y XV YV ANG ANGV puck ID is at (X, Y) with velocity (XV, YV), turning angle ANG, angular velocity ANGV. T1 and T2 are the teams who last touched the puck (most recent and second most recent, respectively).
e marks the last packet of a status update

Each message is terminated by a newline character.

Each UDP packet starts with a t message and contains zero or more g, m and p messages. The last packet of a tick ends with an e message.

Team id, tick and packet numbers are integers; velocities and other physical properties are floating point numbers. Velocities are measured in unit/seconds.

Angles are radians, positive is counterclockwise.

Constants and mallet control

TCP initial constants (server -> player)
format description
playernum N number of players (int)
scorestart S starting score for each team (int)
scoremin S minimum score a team can achieve (int)
scoremax S maximum score a team can achieve (int)
scoregoalsend S score awarded for shooting a goal (int)
scoregoalrecv S score awarded for receiving a goal (negative int)
puckr R radius of puck (float)
malletr R radius of mallet (float)
maxaccel A max acceleration of mallet (float)
maxvel V max velocity of mallet (float)
ticktime N time between two status updates in milliseconds (int)
wall T X0 Y0 X1 Y1line segment (X0,Y0)-(X1,Y1) is a wall or a goal line of team T if T >= 0
zone T X Y R team T's zone is a circle centered at (X,Y) with radius R
score T S team T has score S
done sent after sending the above commands, to terminate the list of constants
These constants are sent by the server immediately after the connection is established. Team ID and scores are always int, coordinates, sizes and other physical properties are floats.
TCP mallet control (player -> server)
format description
XA YA acceleration vector for player's mallet (float)
Can be sent any time. Last sent value is used in each tick (it doesn't make sense to send more than one control message in a single tick).


We are using a packet switched network that may cause at least the following errors (listed in order of expected frequency, most common ones first):


I. Air hockey practice (1000 points)

Each team gets their own practice game table. A simple protocol is provided to control the behavior of the automated part of the table.
TCP mallet control (player -> server)
format description
start starts game with current settings (resets scores first)
stop stops game
length L set length of game in seconds (int)
autopucknum N how many pucks the generator will try to generate (int)
autopuckavgtime T expected delay of respawning a single puck after a goal (or after start); float
autopuckangvar V angle variance of speed of new pucks in [0,1] (0 means shoot at the center of your zone, 1 means shoot at your whole zone); float
autopuckfrom F1 F2 F3 ... list of generators, possible values are 0..N-1 (a value Fn means there is a generator next to team Fn, to their right); Fn is always integer
genpuck X Y VX VY ANG ANGV create new puck manually; floats
level L load level L; issue a "start" command to start playing it
Can be sent any time.

The server answers a command with a single line prefixed with ack, except for the level command, for which the server answers multiple lines prefixed with task. Task lines specify the task to be done for the given level. There are 10 levels numbered from 0 to 9.


You may try to solve a level any time without penalty; completing it is worth 100 points.

J. Air hockey tournament (2500 points)

There will be three tournaments where the AIs of all 30 teams compete against each other.

A tournament consists of several rounds. Rounds starts periodically every 15 minutes during a tournament. In each round you should connect to the tcp control server to get initial constants for the round and to be able to control your mallet. At the end of the round the server will close the tcp connection.


Each playing team has an in-game score based on the number of received and scored goals. At the end of a round the team gets real scores based on its in-game ranking compared to other teams in that round.

The maximum score a team can get for a round is different in each tournament.
Tournament # Rounds Max score for one round