Read the Tutorial
The tutorial will give you an overview on all SDK tools. Try to implement and run your first AI.
First Run of your AI
Now it is time to let your AI run against the local opponents. Run the
Run CodeBattleconfiguration to start the game engine.For Eclipse: Right click on
Run CodeBattle.launchand click on
Run CodeBattleto start the game engine.
The results of the battle are saved in the
/temp/directory of the SDK installation path. There you will find a
recoding.jsonfile which you can use to replay the game on our web player.
To debug your AI implementation use the
Configure CodeBattleto run the game engine in configuration mode. Check the debug check box for the client jar file you want to start in debug mode (by default player1 runs with your implementation). When you have started the game you will be prompted to connect with your client. To connect your client you have to run the launch configuration
Debug Clientin debug mode.Before you connect you should set a breakpoint within your implementation so the client does not immediately start processing.Should your AI implementation behave differently when running in debug mode your client probably violates the Java SecurityManager policy (see also the chapter on Constraints), which is deactivated in the debug mode. You will find the errors in the log files in the
/temp/directory of the CodeBattle SDK.
ImplementationYour starting implementation class is
ai.implementation.MyCodeBattleClient. This class already has a rudimentary implementation of the AI to give you an overview of the CodeBattle API. For each game round the method
processRoundof your client is called by the game engine with the current
ClientRoundState roundStateas parameter.
Before you start coding please read the notes at the top of the methodIn the next section the classes of the CodeBattle API are explained. You will also find all details about all methods and class fields integrated in Javadoc.
This is the main class that comes with all the information about the current round. This class provides the information about all fields on the map, your own base, your own units and the current round number.
getMap()returns all fields of the map. If you want information about a field at position x and y you get the field by calling roundState.getMap()[x][y].
getWidth()returns the width of the map. All x coordinates are strictly less than this value.
getHeight()returns the height of the map. All y coordinates are strictly less than this value.
getBase()returns your base. The base contains your collected resources, coins and your newly created units.
getRoundNumber()returns the current round number.
getOwnUnits()returns a list of your own units.
hasLineOfSight(Position p, Position q)returns true when a unit standing on one position could see a unit standing on the other position and vice versa.
This class contains all the information about a map field.
getType()returns the type of the field. Can be LAND, WATER, WALL or BASE. You can only move units onto fields of type LAND or onto your own BASE.
getUnitOnField()returns the unit on this field or null when there is no unit on the field.
getOwner()If the field is of type BASE then it returns the player name of the owner of the BASE.
getResourceCount()returns the amount of resources on this field.
getRemainingResourceLifetime()returns the remaining resource lifetime (in rounds) before the remaining resources disappear.
isCrossable(Unit unit)returns true if the unit can walk onto this field.
This class contains all the information about a unit. A unit can be a WARRIOR, a COLLECTOR or an ARCHER.
getUnitId()The id of the unit is unique and won't change during a game battle.
getOwner()returns the owner of the unit (the player who created the unit).
getUnitType()returns the type of the unit. Can be WARRIOR, COLLECTOR or ARCHER.
getPosition()returns the position of the unit on the map.
getResourceCount()return the number of resources the unit is currently carrying.
getHealth()return the remaining health points of the unit.
move(Direction direction)Use this method to move in a specific direction. The unit won't move if the field is not crossable. The unit will automatically collect resources from a field if there are any, and it will automatically drop its resources if you move the unit onto your own base.
attack(Position attackPosition)Use this method to attack an enemy that you can see and who is in range. If you win, the enemy unit is killed and will drop all its resources on the field it was standing on.
moveAggressively(Direction direction)Like the
move()-method, but starts an
attack()if the unit moves to a field where an enemy is. The units will fight, and in the next round you'll see the result of this fight.
heal()will try to heal the unit. This will only work when it is inside your base and you have at least half the resources required to build it (the cost is fixed independently from the actual health).
Contains x and y position on the field map.
getX()returns the x position on the map (first dimension of the field map array)
getY()returns the y position on the map (second dimension of the field map array)
addDirection(Direction direction, int mapWidth, int mapHeight)returns to which new Position a certain direction would take you. The map size is necessary to prevent going outside of the map.
getDistance(Position to)returns the Manhattan distance to another position
- If you want to create a Position, use the static
Position.get(int x, int y)method.
Contains x and y position on the field map.
getStoredResources()returns the number of resources
getPosition()returns the position of the base on the map
createUnit(UnitType unitType)creates a new unit with the handed type of the unit if enough resources exists.
upgradeCoinFactory()upgrades the coin factory if enough resources exists.
getCoins()returns the number of produced coins.
getUpgradeCosts()returns the cost for the next upgrade.
getCoinProductionPerRound()returns the coins which are produced per round.
This class contains some static information about the current game battle: your own player name, unit costs and the damage warrior, collector and archer can do, the maximum number of resources a unit can carry, the initial amount of health of each unit type and the number of rounds that will be played for this battle. You can retrieve the instance of the class GameConfiguration by calling
this.getGameConfiguration()in your MyCodeBattleClient class.
You do not have to consider that these values will change during the CodeBattle. The GameConfiguration will remain constant for all battles played this year.
getOwnPlayerName()returns name of your player
getMaxNumberOfRounds()returns the number of rounds that will be played.
getUnitCost(UnitType unitType)returns the cost (in resources) to create a unit of a specific type.
getUnitDamage(UnitType unitType, int distance)returns the damage a specific unit type can do over a distance.
getUnitAttackDistance(UnitType unitType)returns the maximum distance from which a unit is able to attack.
getUnitMaxResources(UnitType unitType)returns the amount of resources a unit of a specific type is able to carry.
getUnitInitialHealth(UnitType unitType)returns the initial amount of health a unit has when it is built or healed.
ConstraintsSystem Constraints: Your client is executed in a separate process that has the following constraints:
- 128 MB heap memory. The other settings are set to the default values.
- One round has to be processed by your client in 500 milliseconds. On the CodeBattle server your client has 500 milliseconds CPU user time to process one round.
- You can ask the server about the remaining milliseconds CPU time with a call to
requestRemainingTime()in the main client class. However due to execution and message delay it is not possible to guarantee that the returned value is entirely accurate at that point.
If your client exceeds the 500 ms round time limit, it will be restarted with force. If the client keeps violating the round time limit for 5 rounds in one single game, it will be disabled for the rest of the game.
Note that it is forbidden to waste time in an exaggerated manner. Clients which purposely perform useless operations (e.g.
sleep()) during their computation time may be disqualified.
The binary size of your client (including third-party libraries that you use) must not exceed 10.240 kB. If your client exceeds 10.240 kB the upload of the client will fail.Java Security Constraints: The Security Manager prevents your client from:
- starting threads
- access the file system
- open sockets
Don't forget to consider these constraints when using third-party libraries.
- You will start with no resources and three collectors.
- Each unit can only either walk, attack or heal during one round.
- Only one unit can be on a map field (except on a player's base and during a fight) at a time.
- Your units cannot walk onto wall or water fields or onto bases of other players.
- Your units cannot walk diagonally.
- You collect resources by moving onto a resource field.
- Killed units will drop their collected resources onto the field they were standing on.
- You drop your collected resources when you walk onto your base field.
Configuration of the Battle EngineWhen you start the configuration with
Configure CodeBattleyou can do the following configuration:
- You can choose a map the battle should run on by clicking on the "..."-button next to the map selection field.
- Choose the clients you want to join the battle. You can define a player by clicking the "..."-button next to the player selection field and selecting the jar file that implements the client. Per default your implementation is selected as player 1. You can find your implementation in the target directory of the CodeBattle SDK.
- When you check the debug check box your are able to debug your implementation when launching the "Debug Client" run configuration afterwards.