AiGameDev CTF Lua Bindings
The Lua starter kit for the Capture the Flag SDK allows you to write your commander in Lua. It uses a network interface (JSON) to give orders to your bots.
Prerequisites
In order to use it you need the aisandbox AND the Capture the Flag SDK. If you have not installed these yet get to http://aisandbox.com/download/.
Developing on Windows
Modify the simulate.py file so that the defaults variable is set with the game.NetworkCommander and the commander that you want to test your commander against. eg defaults = ['examples.Defender', 'game.NetworkCommander'] Run simulate.bat to start the game server.
Write your commander into the functions provided in MyCommander.lua.
Run client.lua.
client.bat [HOST PORT] [CommanderFile]
You can launch the examples with the following commands:
client.bat examples.RandomCommanderclient.bat examples.DefenderCommanderclient.bat examples.GreedyCommanderclient.bat examples.BalancedCommander
Developing on Linux
Run the game server using simulate.py with game.NetworkCommander as one of the provided commanders. eg simulate.py example.GreedyCommander game.NetworkCommander
Write your commander into the functions provided in MyCommander.lua.
Run client.lua.
lua client.lua [HOST PORT] [CommanderFile]
You can launch the examples with the following commands:
lua client.lua examples.RandomCommanderlua client.lua examples.DefenderCommanderlua client.lua examples.GreedyCommanderlua client.lua examples.BalancedCommander
API
The API described here is just the differences with the network protocol. For more information about available data, see source code and/or network protocol.
Commander
commander.level:LevelInfocommander.game:GameInfocommander:issue(command)
Commands
DefendCommand( bot.name [ , description ] )DefendCommand( bot.name , { facingDirection = { x, y } } [ , description ] )DefendCommand( bot.name, { facingDirection_list = { [ DefendCommand.FacingDirection( { x1, y1 } [ , time ] ) ]* } } [ , description ] )MoveCommand( bot.name , { target = { x, y } } [ , description ] )MoveCommand( bot.name, { target_list = { [ { x, y } ]* } } [ , description ] )AttackCommand( bot.name , { target = { x, y } [ , lookAt = { x, y } ] } [ , description ] )AttackCommand( bot.name, { target_list = { [ { x, y } ]* } [ , lookAt = { x, y } ] } [ , description ] )ChargeCommand( bot.name , { target = { x, y } } [ , description ] )ChargeCommand( bot.name, { target_list = { [ { x, y } ]* } } [ , description ] )
LevelInfo
level.*: data given by the server (cf. network protocol)level.blockHeights( x, y )orlevel.blockHeights( position )->blockHeightx: x coordinate in range [ 0, level.width - 1 ]y: y coordinate in range [ 0, level.height - 1 ]position: Vector2 coordinateblockHeight: number ( -1 : out of range ; 0 : walkable ; > 0 : not walkable )
level:findRandomFreePositionInBox( minPosition, maxPosition )->freePositionornillevel:findNearestFreePosition( position )->nearestFreePositionornil
GameInfo
game.*: data given by the server (cf. network protocol) ; ids are replaced by references to objectsgame.bots_alive->{ [ BotInfo ]* }: list of bots in the commander's team that are alivegame.bots_available->{ [ BotInfo ]* }: list of bots in the commander's team that are alive and idle
TeamInfo
team.*: data given by the server (cf. network protocol) ; ids are replaced by references to objectsteam.botSpawnArea.minandteam.botSpawnArea.max: extent of team's bot spawn area
ToDo
- The GreedyCommander behaves strangely
Please report bugs or suggestions ...
History
Version 0.4 (2012-12-07)
- Merge received GameInfo at each tick instead of replacing it (to allow the user to extend it)
- Update to protocol version 1.2.1
- Crashfix in the GreedyCommander
Version 0.3 (2012-12-03)
- Fix function LevelInfo.findRandomFreePositionInBox
- Fix commander examples.DefenderCommander
- Convert examples.GreedyCommander and examples.BalancedComander to Lua
- Improve API documentation
- Add Vector2 metatable and convert all existing Vector2
Version 0.2 (2012-11-29)
- Update to protocol version 1.2
- Add a short API documentation
- Lot of bugfixes
- Add Vector2 utilities
- Convert examples.RandomCommander and examples.DefenderComander to Lua
Version 0.1 (2012-11-21)
- Early version release (alpha)
- Handle protocol version 1.1
License
This project is released under the MIT License.
See the LICENSE.md file.