Polar tanks (2500 points)

Game flow

In this game each team controls a tank on the surface of a two dimensional planet to destroy other tanks. There are different weapons available for different price on a free market where players can sell and buy weapons for the next battle. Players earn money by causing damage to other players and by winning battles. Most weapons are ballistics with different effect on the area where they land. Weapons range from simple explosives through nukes to cluster bombs (with multiple explosives).

Throughout the 24 hours, the game is divided into six 4 hours long campaigns. Each campaign is a series of trade-battle pairs. During the trade phase, players can buy and sell weapons and tools that they can use in the next battles or sell in the next trade phases. Money and inventory are persistent along battles and trade phases, but are reset before a new campaign. Number of trade-battle pairs may vary from campaign to campaign, depending on how fast players finish with trades and battles.

When a phase is over, a new phase starts exactly when the server broadcasts a phase command.

Scoring

At the end of each campaign, teams are ordered by how much cash they have (having a lot of weapons does not matter!). Each team gets a final score depending on its place on this list (base score), multiplied by the campaign factor. This means at the end of the 24 hours, the final score of a team for this problem is calculated as: 5.555*(B1 * F1 + B2 * F2 + B3 * F3 + B4 * F4 + B5 * F5 + B6 * F6), where Bn is the base score the team made during campaign n and Fn is the factor of campaign n (see the tables below).

In case of a tie, the points for the first shared rank are used (e.g. if the 2nd, 3rd, 4th places are tied, all three teams get points for being the 2nd; the 5th placed team gets points for being the 5th).

If a team ends up with less money in a campaign than they initially received, they get 0 points for the campaign, regardless of their placement.
rank at the end of the campaign base score
1st 100
2nd 80
3rd 66
4th..30th 52-(rank-4)*2
campaign number starts at campaign factor
1 9:00, Sat 0.2
2 13:00, Sat 0.4
3 17:00, Sat 0.6
4 21:00, Sat 0.8
5 01:00, Sun 1
6 05:00, Sun 1.5

Trade phase

Trade phases last for a campaign specific predefined time period. Teams can place offers to sell and buy certain amount of weapon for a certain price in a central database. If a sell and buy offer exactly meets, the transaction is made between the two players and both offers are removed from the database. Offers can be deleted any time from the database by the team that placed it and new offers can be placed any time.

A transaction is established if:

Besides the teams, there may be merchants and manufacturers trading - although they won't participate in battles. Team IDs for these players start with an underscore character.

Before a new trade phase, the offer database is purged and the phase starts with no offer. The number of offers a player may place is limited, but the player may cancel older offers to free up slots. The player may offer to sell something that is not in the player's inventory or may place an offer for buy goods for cash the player doesn't currently have - these offers can be placed and are broadcasted but transactions based on these offers are not established until the player happens to have the required goods or cash.

Battle

At the beginning of a new battle, a new planet is generated and the tank of each team is randomly placed on the surface in a random order specific to the given battle (battle-specific order). Each battle is divided into turns. In a turn, each player is queried for commands, one by one, in the battle-specific order. A player needs to react to the query and send a single command within a predefined command timeout, else the tank stays idle for the turn. The command is executed immediately. If the command was successful, the effect is calculated and broadcasted to all players, otherwise the active client gets an error message. In either case, the turn is over (in other words, an invalid command results in an idle turn for the player). Note: there may be a delay up to 1 second after processing the command before switching to the next player (during this delay, nothing will happen as the active player can not issue a second command).

Most often the command is to fire a ballistic missile in a given angle with a given initial velocity. Angle, velocity, the trace of the missile and the effect of the missile are all reported to all players. Different missiles act differently, but there is a common feature: after a predefined timeout, the missile initiates a self-destruct procedure (explodes wherever it is, even mid-air). NOTE: teams should carefully evaluate these information, since the value of gravity and wind speed is not reported to the teams.

Each tank has a given amount of health points (HP. A nearby explosion or falling down after the landscape changed below a tank decreases the HP of the tank. When HP is less then or equal to zero, the tank is considered dead - it is removed from the battle and is not queried anymore. Teams with dead tanks still can monitor the battle (they still get all information from the server). However, from the next trade phase the team can play again. The HP of tanks is set to 100 before each battle.

To avoid infinite long battles due to idling tanks, at the end of each turn, a battle specific predefined amount of points are subtracted from each player's HP, or in other words tanks are aging.

The world

The world is a 2 dimensional planet with a non-uniform surface that roughly ressambles a circle. All coordinates are given in a polar coordinate system with it's origin matching the center of the planet. Gravity affects any object with a constant acceleration towards the center of the planet. Because of the explosions and other effects caused by the weapons, the landscape of the planet may change during the battle: landmass may evaporate into the atmosphere or new hills can be built using dirt bombs.

There is a lower layer of the surface that is so hard that available weapons can not damage it. This layer is always at least R meters above the center.

Above the current surface of the planet there is non-stationer air. Wind blows in different directions with different speed on different altitudes. Wind may change between turns, but not during a turn. Wind affects different weapons in different ways and the effect can be modified by tools.

There is a single game server run by the organizers and client programs run by the teams.

Protocol

The protocol is text based, the game is played trough a TCP socket. The protocol consists of independent messages. A message is terminated by a newline character (\n, ASCII 0xA) and may contain letters, numbers, spaces, semicolons, colons, commas and underscore. The message is split into words by spaces. A continuous series of spaces counts as a single space. The first word is called the command. NOTE: messages sent by the server may be of any length.

To simplify protocol description, from now on, the following notations will be used:

A message from the server to the client can be of any length. A message from the client to the server shall never be longer than 512 bytes.

Setting up the connection

When a team joins the game, the client software needs to issue a login command first (typically after receiving an IIAM command from the server). There may be an amount of connections from a team, but there is only one connection that may send commands, and that client is called the controlling client. After connecting, the client must explicitly request control. Always the last client from a team that requested control will be in charge, all other clients become read-only. Commands from read-only clients are generally ignored but an error message is sent as a response.

Clients may join and leave (by closing the connection) any time. Any attempt for overloading the server by excess traffic may result in disqualification. If a team does not have a controlling client at the time the server sends the query for the team in a battle or during the trade phase, the tank/team keeps idling (in trade phase until the end of the phase, in battle until command timeout).

When a client connects, the following information are sent:

Campaign constant (server -> client)

The server sends the following commands to inform the player about campaign constants.
message description
cmdtimeout I I is the command timeout in seconds
tradetime I I describes how long a trade phase lasts in seconds
offers I a player may have no more than I active offers simultaneously
slices I I describes how many slices a planet has, angular coordinates will be given in terms of slices
flood I if the client sends more than I messages in a second, the client is disconnected with EFLOOD.
phase S if S is "B", a battle is going on, if S is "T", a trading phase is going on. Hint: phase command should reset all offers, landscape and player position information stored on client side. The server will update the client with the necessary information after a phase command.
Betweeen the flood and phase commands, the server also sends cash commands about players and for those items the player has in his/her inventory, a series of inv command as well.

NOTE: as a general rule, any information that is not sent by the server in messages should be measured or guessed from evaluating all available information by other messages.

cash (server -> client)

The server may send the following command multiple times to inform the player about cash states.
message description
cash S I S is the name of the team, I is the amount of cash the team has

inventory (server -> client)

The server may send the following command multiple times to inform the player about his/her own inventory.
message description
inv S I S is the name of the weapon or tool, I is the amount currently owned

battle setup (server -> client)

The server sends: For more information on the format of these commands, refer to later sections. Planet command is:
message description
planet indicates a new planet is being described

trade setup (server -> client)

The server first sends the remaining amount of time for the trade phase:
message description
trade I I is the remaining time of trade phase in seconds
All currently active offers are sent to the client (format is described in a later section.

battle information (server -> client)

message description
activate S player of team S is the active player - when this command is received, the active player has command timeout seconds to issue a command (see later). There is no "deactivate" or "end of activity" command, a new "activate" command cancels the previous.
trajectory S S I;I ... arguments are: player ID (who shot), weapon name and a series of slice;height information. Note: the server may send multiple trajectory messages for a single shot (for example in case of using cluster bombs).
height I;I slice I (first number) currently has height I (second number)
plpos S I;I player S is on slice I (first number) at height I (second argument)
HP S I player S has HP I
When a new battle starts, after the phase command the server broadcasts a series of height and plpos and HP commands. Each turn starts with an activate command broadcasted and may result in multiple trajectory, height, plpos and HP messages received from the server. The turn ends with the next activate command or with a "phase T" message.

trade information (server -> client)

message description
sell I S S I I sell offer, unique offer ID I (first argument) by player S (second argument) for weapon S (third argument), I for amount and I (last word) for price
buy I S S I I Buy offer, unique offer ID I (first argument) by player S (second argument) for weapon S (third argument), I for amount and I (last word) for price
trans I I transaction between the two orders (sell first) is established; both orders are deleted. (NOTE: cash command is also sent about both players, inv commands are sent to the two affected players)
cancel I cancel offer ID I
Trade phase ends when the server broadcasts a "phase B" message to indicate a new battle is starting.

trade commands (client -> server)

message description
sell S I I place a sell offer for weapon S (first argument), I for amount and I (last word) for price
buy S I I place a buy offer for weapon S (first argument), I for amount and I (last word) for price
cancel I cancel offer ID I (only if the offer is from the player)
NOTE: properly issuing any of the above commands will result in a broadcast message from the server. This means the client that initiated the action and all other clients as well will receive the command describing the effect.

battle commands (client -> server)

message description
shoot S I I shoot weapon S in direction I (in degrees) with velocity I.

misc commands (client -> server)

message description
control take over control of the player; if another client is already having control, control is taken from that client and ENOCONTROL is sent to that client immediately.
login T log in with password T.

Error messages (server -> client)

These messages are sent only when a client sends unsuitable command to the server. A properly implemented client should never receive any of these messages from a properly implemented server. The only exception is ETOOMANY which may happen if the team runs too many properly implemented clients in parallel.
message description
EPHASE client tried to issue trade command in battle phase or battle command in trade phase
EFLOOD excess flood (too many messages from the client in too short time) - disconnecting client
ENOCONTROL client does not control the player (client is read-only)
ETOOMANYCONN too many client connected for the team
ETOOMANYOFFER too many offers are placed by the player
EINTERNAL T internal server error (also reported on server console, the organizers should already know about it)
ECANTCANCEL I the client can not cancel offer I (most probably the client does not own it)
ECANTSHOOT the client could not shoot the weapon (most probably the weapon is not in inventory)
ENOTURN last client command is ignored as this is not the team's turn
ESYNTAX T syntax error - usually missing or bogus arguments for valid commands
ELOGIN need to log in before issuing command or already logged in when a new login command is received

Announcement messages (server -> client)

These messages safely can be ignored and are implemented only to aid debugging client software.
message description
ILEFT I time left is i seconds (for trade in trade phase or for the active player to give a command in battle phase)
IYOUARE S your current team ID is s
IIAM T information about the game server (arguments include arbitrary number of words); first command sent by the server to the client
IEXPL I;I I explosion at slice;height with radius I
IEND campaign has ended
IGAMESTATE S inform the player about new game state S; states are:
  • lastturn: campaign will end after end of current phase, thus this is the last phase
  • paused: game is paused; during pause sell, buy, cancel and shoot commands are ignored
  • resumed: game is resumed after a pause