This is the API you need to use to communicate with the space fleet and radar systems.

You may also use the underscore.js supporting library in your program. Underscore.js provides functional programming functionality for your program, enabling you to write concise and elegant code using techniques like higher order functions. To see a complete list of supported functions, visit http://underscorejs.org/.

If your program encounters an error or times out, a message will be logged in the JavaScript console of your browser. You may also log messages to the console by using console.log(). These messages will be visible to anyone watching the match.

IMPORTANT: Only use these methods. Naked access is not illegal but unreliable and strongly discouraged.

Due to the freeze and thaw methods used by the server, the following keywords are strictly reserved. DO NOT USE THESE KEYWORDS IN YOUR PROGRAM:

The presence of these keywords can possibly (but not always) cause the interpretation of your program to fail, making you lose your turn. This is mainly because of corruption of your program’s state, resulting in loss of data.

REMINDER: If you capture results from methods that return Arrays into your program’s state, the array may contain references to objects that do not exist and are no longer valid. It is the responsibility of your program to detect these invalid occurrences.

UNIVERSE OBJECT

universe.getPlayerId()

Returns the integer player_id of the player.

universe.getNumOfPlayers()

Returns the number of players in the match.

universe.getPlanets()

Returns the array of planet objects representing all planets in the universe.

universe.getFleets()

Returns the array of fleet objects representing all groups of ships in the universe.

universe.actions.send(<ships>, <from>, <to>)

Commits a send action of integer ships ships, from planet object from to planet object to. The function returns boolean true if successful and false on error (e.g. not physically possible/not owner of planet).

universe.actions.upgrade(<planet>)

Commits an upgrade at planet object planet. The function returns boolean true if successful and false on error (e.g. insufficient ships/not owner of planet).

universe.actions.clear()

Clear all actions that had been commited up to this point.

PLANET OBJECT

planet.getX()

Returns the x-coordinate (in astronomical units) of the planet.

planet.getY()

Returns the y-coordinate (in astronomical units) of the planet.

planet.getSize()

Returns the capacity of the planet.

planet.getOwner()

Returns an integer player_id.

planet.getShips()

Returns the number of ships on the planet.

planet.getLevel()

Returns the level of the planet.

planet.isHome()

Returns boolean true if it is a home planet and false if it is a ordinary planet.

planet.send(<number>, <to>)

Commits a send action of integer ships ships, from the planet to planet object to. The function returns boolean true if successful and false on error (e.g. not physically possible/not owner of planet).

planet.upgrade()

Commits a upgrade command on the planet if it is valid. The function returns boolean true if successful and false on error (e.g. insufficient ships/not owner of planet).

FLEET OBJECT

IMPORTANT: Fleet objects are the only objects that can be destroyed in the course of the universe. If you retain a fleet object reference, it is your responsibility to check if the reference is still valid by checking it has an owner (i.e. getOwner() is not 0) or if it has any ships (i.e. getShips() is not 0)

fleet.getOwner()

Returns an integer player_id.

fleet.getShips()

Returns the number of ships in the group.

fleet.getFrom()

Returns the planet object the fleet was sent from

fleet.getTo()

Returns the planet object the fleet is going towards

fleet.getDistance()

Returns the distance (in astronomical units) required to travel to reach the destination planet.