TileDirections are all the direction strings that Tile's neighbors can be in.
var TileDirections = [...]string{"North", "South", "East", "West"}
func PlayerName() string
PlayerName should return the string name of your Player in games it plays.
AI is your personal AI implimentation.
type AI struct { base.AIImpl }
func (ai *AI) Ended(won bool, reason string)
Ended is called when the game ends, you can clean up your data and dump files here if need be.
func (ai *AI) Game() Game
Game returns the instance of the Game this AI is currently playing.
func (ai *AI) GameUpdated()
GameUpdated is called every time the game's state updates, so if you are tracking anything you can update it here.
func (ai *AI) Player() Player
Player returns the instance of the Player this AI is represented by in the game this AI is playing.
func (ai *AI) RunTurn() bool
RunTurn this is called every time it is this AI.player's turn.
func (ai *AI) Start()
Start is called once the game starts and your AI has a Player and Game. You can initialize your AI struct here.
Game is steal from merchants and become the most infamous pirate.
type Game interface { // Parent interfaces base.Game // BuryInterestRate is the rate buried gold increases each turn. BuryInterestRate() float64 // CrewCost is how much gold it costs to construct a single crew. CrewCost() int64 // CrewDamage is how much damage crew deal to each other. CrewDamage() int64 // CrewHealth is the maximum amount of health a crew member can // have. CrewHealth() int64 // CrewMoves is the number of moves Units with only crew are given // each turn. CrewMoves() int64 // CrewRange is a crew's attack range. Range is circular. CrewRange() float64 // CurrentPlayer is the player whose turn it is currently. That // player can send commands. Other players cannot. CurrentPlayer() Player // CurrentTurn is the current turn number, starting at 0 for the // first player's turn. CurrentTurn() int64 // GameObjects is a mapping of every game object's ID to the // actual game object. Primarily used by the server and client to // easily refer to the game objects via ID. GameObjects() map[string]GameObject // HealFactor is how much health a Unit recovers when they rest. HealFactor() float64 // MapHeight is the number of Tiles in the map along the y // (vertical) axis. MapHeight() int64 // MapWidth is the number of Tiles in the map along the x // (horizontal) axis. MapWidth() int64 // MaxTurns is the maximum number of turns before the game will // automatically end. MaxTurns() int64 // MerchantGoldRate is how much gold merchant Ports get each turn. MerchantGoldRate() float64 // MerchantInterestRate is when a merchant ship spawns, the amount // of additional gold it has relative to the Port's investment. MerchantInterestRate() float64 // MinInterestDistance is the Euclidean distance buried gold must // be from the Player's Port to accumulate interest. MinInterestDistance() float64 // Players is array of all the players in the game. Players() []Player // Ports is every Port in the game. Merchant ports have owner set // to nil. Ports() []Port // RestRange is how far a Unit can be from a Port to rest. Range // is circular. RestRange() float64 // Session is a unique identifier for the game instance that is // being played. Session() string // ShipCost is how much gold it costs to construct a ship. ShipCost() int64 // ShipDamage is how much damage ships deal to ships and ports. ShipDamage() int64 // ShipHealth is the maximum amount of health a ship can have. ShipHealth() int64 // ShipMoves is the number of moves Units with ships are given // each turn. ShipMoves() int64 // ShipRange is a ship's attack range. Range is circular. ShipRange() float64 // Tiles is all the tiles in the map, stored in Row-major order. // Use `x + y * mapWidth` to access the correct index. Tiles() []Tile // TimeAddedPerTurn is the amount of time (in nano-seconds) added // after each player performs a turn. TimeAddedPerTurn() float64 // Units is every Unit in the game. Merchant units have targetPort // set to a port. Units() []Unit // GetTileAt returns the Tile at a give position (x, y). GetTileAt(int64, int64) Tile }
GameObject is an object in the game. The most basic class that all game classes should inherit from automatically.
type GameObject interface { // Parent interfaces base.GameObject // Logs is any strings logged will be stored here. Intended for // debugging. Logs() []string // Log adds a message to this GameObject's logs. Intended for your // own debugging purposes, as strings stored here are saved in the // gamelog. Log(string) }
Player is a player in this game. Every AI controls one player.
type Player interface { // Parent interfaces GameObject // ClientType is what type of client this is, e.g. 'Python', // 'JavaScript', or some other language. For potential data mining // purposes. ClientType() string // Gold is the amount of gold this Player has in reserve. Gold() int64 // Infamy is the amount of infamy this Player has. Infamy() int64 // Lost is if the player lost the game or not. Lost() bool // Name is the name of the player. Name() string // Opponent is this player's opponent in the game. Opponent() Player // Port is the Port owned by this Player. Port() Port // ReasonLost is the reason why the player lost the game. ReasonLost() string // ReasonWon is the reason why the player won the game. ReasonWon() string // TimeRemaining is the amount of time (in ns) remaining for this // AI to send commands. TimeRemaining() float64 // Units is every Unit owned by this Player. Units() []Unit // Won is if the player won the game or not. Won() bool }
Port is a port on a Tile.
type Port interface { // Parent interfaces GameObject // Gold is for players, how much more gold this Port can spend // this turn. For merchants, how much gold this Port has // accumulated (it will spawn a ship when the Port can afford // one). Gold() int64 // Investment is (Merchants only) How much gold was invested into // this Port. Investment determines the strength and value of the // next ship. Investment() int64 // Owner is the owner of this Port, or nil if owned by merchants. // // Value can be returned as a nil pointer. Owner() Player // Tile is the Tile this Port is on. Tile() Tile // Spawn spawn a Unit on this port. Spawn(string) bool }
Tile is a Tile in the game that makes up the 2D map grid.
type Tile interface { // Parent interfaces GameObject // Decoration is (Visualizer only) Whether this tile is deep sea // or grassy. This has no effect on gameplay, but feel free to use // it if you want. Decoration() bool // Gold is the amount of gold buried on this tile. Gold() int64 // Port is the Port on this Tile if present, otherwise nil. // // Value can be returned as a nil pointer. Port() Port // TileEast is the Tile to the 'East' of this one (x+1, y). Nil if // out of bounds of the map. // // Value can be returned as a nil pointer. TileEast() Tile // TileNorth is the Tile to the 'North' of this one (x, y-1). Nil // if out of bounds of the map. // // Value can be returned as a nil pointer. TileNorth() Tile // TileSouth is the Tile to the 'South' of this one (x, y+1). Nil // if out of bounds of the map. // // Value can be returned as a nil pointer. TileSouth() Tile // TileWest is the Tile to the 'West' of this one (x-1, y). Nil if // out of bounds of the map. // // Value can be returned as a nil pointer. TileWest() Tile // Type is the type of Tile this is ('water' or 'land'). // // Literal Values: "water" or "land" Type() string // Unit is the Unit on this Tile if present, otherwise nil. // // Value can be returned as a nil pointer. Unit() Unit // X is the x (horizontal) position of this Tile. X() int64 // Y is the y (vertical) position of this Tile. Y() int64 // GetNeighbors returns an array of the neighbors of this Tile. GetNeighbors() []Tile // IsPathable returns if the Tile is pathable for FindPath IsPathable() bool // HasNeighbor checks if this Tile has a specific neighboring Tile. HasNeighbor(Tile) bool }
Unit is a unit group in the game. This may consist of a ship and any number of crew.
type Unit interface { // Parent interfaces GameObject // Acted is whether this Unit has performed its action this turn. Acted() bool // Crew is how many crew are on this Tile. This number will always // be <= crewHealth. Crew() int64 // CrewHealth is how much total health the crew on this Tile have. CrewHealth() int64 // Gold is how much gold this Unit is carrying. Gold() int64 // Moves is how many more times this Unit may move this turn. Moves() int64 // Owner is the Player that owns and can control this Unit, or nil // if the Unit is neutral. // // Value can be returned as a nil pointer. Owner() Player // Path is (Merchants only) The path this Unit will follow. The // first element is the Tile this Unit will move to next. Path() []Tile // ShipHealth is if a ship is on this Tile, how much health it has // remaining. 0 for no ship. ShipHealth() int64 // StunTurns is (Merchants only) The number of turns this merchant // ship won't be able to move. They will still attack. Merchant // ships are stunned when they're attacked. StunTurns() int64 // TargetPort is (Merchants only) The Port this Unit is moving to. // // Value can be returned as a nil pointer. TargetPort() Port // Tile is the Tile this Unit is on. // // Value can be returned as a nil pointer. Tile() Tile // Attack attacks either the 'crew' or 'ship' on a Tile in range. Attack(Tile, string) bool // Bury buries gold on this Unit's Tile. Gold must be a certain // distance away for it to get interest // (Game.minInterestDistance). Bury(int64) bool // Deposit puts gold into an adjacent Port. If that Port is the // Player's port, the gold is added to that Player. If that Port // is owned by merchants, it adds to that Port's investment. Deposit(int64) bool // Dig digs up gold on this Unit's Tile. Dig(int64) bool // Move moves this Unit from its current Tile to an adjacent Tile. // If this Unit merges with another one, the other Unit will be // destroyed and its tile will be set to nil. Make sure to check // that your Unit's tile is not nil before doing things with it. Move(Tile) bool // Rest regenerates this Unit's health. Must be used in range of a // port. Rest() bool // Split moves a number of crew from this Unit to the given Tile. // This will consume a move from those crew. Split(Tile, int64, int64) bool // Withdraw takes gold from the Player. You can only withdraw from // your own Port. Withdraw(int64) bool }