...

Package anarchy

import "joueur/games/anarchy"
Overview
Index

Overview ▾

Package anarchy contains all the interfaces and AI that are required to represent and play Anarchy.

Anarchy Game Info ▾

Two player grid based game where each player tries to burn down the other player's buildings. Let it burn.

More Info

The full game rules for Anarchy can be found on GitHub.

Additional materials, such as the story and game template can be found on GitHub as well.

func PlayerName

func PlayerName() string

PlayerName should return the string name of your Player in games it plays.

type AI

AI is your personal AI implimentation.

type AI struct {
    base.AIImpl
}

func (*AI) Ended

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) Game

func (ai *AI) Game() Game

Game returns the instance of the Game this AI is currently playing.

func (*AI) GameUpdated

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) Player

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) RunTurn

func (ai *AI) RunTurn() bool

RunTurn this is called every time it is this AI.player's turn.

func (*AI) Start

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.

type Building

Building is a basic building. It does nothing besides burn down. Other Buildings inherit from this class.

type Building interface {
    // Parent interfaces
    GameObject

    // Bribed is when true this building has already been bribed this
    // turn and cannot be bribed again this turn.
    Bribed() bool

    // BuildingEast is the Building directly to the east of this
    // building, or nil if not present.
    //
    // Value can be returned as a nil pointer.
    BuildingEast() Building

    // BuildingNorth is the Building directly to the north of this
    // building, or nil if not present.
    //
    // Value can be returned as a nil pointer.
    BuildingNorth() Building

    // BuildingSouth is the Building directly to the south of this
    // building, or nil if not present.
    //
    // Value can be returned as a nil pointer.
    BuildingSouth() Building

    // BuildingWest is the Building directly to the west of this
    // building, or nil if not present.
    //
    // Value can be returned as a nil pointer.
    BuildingWest() Building

    // Fire is how much fire is currently burning the building, and
    // thus how much damage it will take at the end of its owner's
    // turn. 0 means no fire.
    Fire() int64

    // Health is how much health this building currently has. When
    // this reaches 0 the Building has been burned down.
    Health() int64

    // IsHeadquarters is true if this is the Headquarters of the
    // owning player, false otherwise. Burning this down wins the game
    // for the other Player.
    IsHeadquarters() bool

    // Owner is the player that owns this building. If it burns down
    // (health reaches 0) that player gets an additional bribe(s).
    Owner() Player

    // X is the location of the Building along the x-axis.
    X() int64

    // Y is the location of the Building along the y-axis.
    Y() int64
}

type FireDepartment

FireDepartment is can put out fires completely.

type FireDepartment interface {
    // Parent interfaces
    Building

    // FireExtinguished is the amount of fire removed from a building
    // when bribed to extinguish a building.
    FireExtinguished() int64

    // Extinguish bribes this FireDepartment to extinguish the some of
    // the fire in a building.
    Extinguish(Building) bool
}

type Forecast

Forecast is the weather effect that will be applied at the end of a turn, which causes fires to spread.

type Forecast interface {
    // Parent interfaces
    GameObject

    // ControllingPlayer is the Player that can use WeatherStations to
    // control this Forecast when its the nextForecast.
    ControllingPlayer() Player

    // Direction is the direction the wind will blow fires in. Can be
    // 'north', 'east', 'south', or 'west'.
    //
    // Literal Values: "North", "East", "South", or "West"
    Direction() string

    // Intensity is how much of a Building's fire that can be blown in
    // the direction of this Forecast. Fire is duplicated (copied),
    // not moved (transferred).
    Intensity() int64
}

type Game

Game is two player grid based game where each player tries to burn down the other player's buildings. Let it burn.

type Game interface {
    // Parent interfaces
    base.Game

    // BaseBribesPerTurn is how many bribes players get at the
    // beginning of their turn, not counting their burned down
    // Buildings.
    BaseBribesPerTurn() int64

    // Buildings is all the buildings in the game.
    Buildings() []Building

    // CurrentForecast is the current Forecast, which will be applied
    // at the end of the turn.
    CurrentForecast() Forecast

    // 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

    // Forecasts is all the forecasts in the game, indexed by turn
    // number.
    Forecasts() []Forecast

    // 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

    // MapHeight is the width of the entire map along the vertical (y)
    // axis.
    MapHeight() int64

    // MapWidth is the width of the entire map along the horizontal
    // (x) axis.
    MapWidth() int64

    // MaxFire is the maximum amount of fire value for any Building.
    MaxFire() int64

    // MaxForecastIntensity is the maximum amount of intensity value
    // for any Forecast.
    MaxForecastIntensity() int64

    // MaxTurns is the maximum number of turns before the game will
    // automatically end.
    MaxTurns() int64

    // NextForecast is the next Forecast, which will be applied at the
    // end of your opponent's turn. This is also the Forecast
    // WeatherStations can control this turn.
    //
    // Value can be returned as a nil pointer.
    NextForecast() Forecast

    // Players is array of all the players in the game.
    Players() []Player

    // Session is a unique identifier for the game instance that is
    // being played.
    Session() string

    // TimeAddedPerTurn is the amount of time (in nano-seconds) added
    // after each player performs a turn.
    TimeAddedPerTurn() float64
}

type GameObject

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)
}

type Player

Player is a player in this game. Every AI controls one player.

type Player interface {
    // Parent interfaces
    GameObject

    // BribesRemaining is how many bribes this player has remaining to
    // use during their turn. Each action a Building does costs 1
    // bribe. Any unused bribes are lost at the end of the player's
    // turn.
    BribesRemaining() int64

    // Buildings is all the buildings owned by this player.
    Buildings() []Building

    // ClientType is what type of client this is, e.g. 'Python',
    // 'JavaScript', or some other language. For potential data mining
    // purposes.
    ClientType() string

    // FireDepartments is all the FireDepartments owned by this
    // player.
    FireDepartments() []FireDepartment

    // Headquarters is the Warehouse that serves as this player's
    // headquarters and has extra health. If this gets destroyed they
    // lose.
    Headquarters() Warehouse

    // 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

    // PoliceDepartments is all the PoliceDepartments owned by this
    // player.
    PoliceDepartments() []PoliceDepartment

    // 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

    // Warehouses is all the warehouses owned by this player. Includes
    // the Headquarters.
    Warehouses() []Warehouse

    // WeatherStations is all the WeatherStations owned by this
    // player.
    WeatherStations() []WeatherStation

    // Won is if the player won the game or not.
    Won() bool
}

type PoliceDepartment

PoliceDepartment is used to keep cities under control and raid Warehouses.

type PoliceDepartment interface {
    // Parent interfaces
    Building

    // Raid bribe the police to raid a Warehouse, dealing damage equal
    // based on the Warehouse's current exposure, and then resetting
    // it to 0.
    Raid(Warehouse) int64
}

type Warehouse

Warehouse is a typical abandoned warehouse that anarchists hang out in and can be bribed to burn down Buildings.

type Warehouse interface {
    // Parent interfaces
    Building

    // Exposure is how exposed the anarchists in this warehouse are to
    // PoliceDepartments. Raises when bribed to ignite buildings, and
    // drops each turn if not bribed.
    Exposure() int64

    // FireAdded is the amount of fire added to buildings when bribed
    // to ignite a building. Headquarters add more fire than normal
    // Warehouses.
    FireAdded() int64

    // Ignite bribes the Warehouse to light a Building on fire. This
    // adds this building's fireAdded to their fire, and then this
    // building's exposure is increased based on the Manhattan
    // distance between the two buildings.
    Ignite(Building) int64
}

type WeatherStation

WeatherStation is can be bribed to change the next Forecast in some way.

type WeatherStation interface {
    // Parent interfaces
    Building

    // Intensify bribe the weathermen to intensity the next Forecast
    // by 1 or -1.
    Intensify(bool) bool

    // Rotate bribe the weathermen to change the direction of the next
    // Forecast by rotating it clockwise or counterclockwise.
    Rotate(bool) bool
}