botutil

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 1, 2020 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Code generated by gen_ids. DO NOT EDIT.

Index

Constants

View Source
const (
	GameVersion = "4.11.4.78285"
	DataVersion = "69493AFAB5C7B45DDB2F3442FD60F0CF"
	DataBuild   = 78285
	BaseBuild   = 78285
)

Variables

View Source
var IsGasBuilding = isUnitTypeInMap(map[api.UnitTypeID]struct{}{
	unit.Protoss_Assimilator: {},
	unit.Terran_Refinery:     {},
	unit.Zerg_Extractor:      {},
})

IsGasBuilding ...

IsStructure ...

IsTownHall ...

View Source
var IsWorker = isUnitTypeInMap(map[api.UnitTypeID]struct{}{
	unit.Protoss_Probe:      {},
	unit.Terran_SCV:         {},
	unit.Terran_MULE:        {},
	unit.Zerg_Drone:         {},
	unit.Zerg_DroneBurrowed: {},
})

IsWorker ...

Functions

func HasAttribute

func HasAttribute(attribute api.Attribute) func(u Unit) bool

HasAttribute ...

func IsGeyser

func IsGeyser(u Unit) bool

IsGeyser ...

func IsMineral

func IsMineral(u Unit) bool

IsMineral ...

func IsSelfType

func IsSelfType(t api.UnitTypeID) func(Unit) bool

IsSelfType ...

func IsType

func IsType(t api.UnitTypeID) func(Unit) bool

IsType ...

func SetGameVersion added in v0.2.0

func SetGameVersion()

SetGameVersion sets the default base build and data version to the values last used to generate IDs.

Types

type ActionErrorHandler

type ActionErrorHandler func(action *api.Action, result api.ActionResult)

ActionErrorHandler is the handler function type for action errors.

type Actions

type Actions struct {
	// contains filtered or unexported fields
}

Actions provides convenience methods for queueing actions to be sent in a batch.

func NewActions

func NewActions(info client.AgentInfo) *Actions

NewActions creates a new Actions manager. It's Send() method is registered to be automatcially called before each client Step().

func (*Actions) Chat

func (a *Actions) Chat(msg string)

Chat sends a message that all players can see.

func (*Actions) ChatTeam

func (a *Actions) ChatTeam(msg string)

ChatTeam sends a message that only teammates (and observers) can see.

func (*Actions) LogActionErrors

func (a *Actions) LogActionErrors()

LogActionErrors registers an error handler that will log the error.

func (*Actions) MoveCamera

func (a *Actions) MoveCamera(pt api.Point2D)

MoveCamera repositions the camera to center on the target point.

func (*Actions) OnActionError

func (a *Actions) OnActionError(handler ActionErrorHandler)

OnActionError sets a handler function that will be called whenever an action errors.

func (*Actions) PrevActions

func (a *Actions) PrevActions() []*api.Action

PrevActions returns the actions that were sent on the last call to Send.

func (*Actions) Send

func (a *Actions) Send()

Send is called automatically to submit queued actions before each Step(). It may also be called manually at any point to send all queued actions immediately.

func (*Actions) UnitOrder

func (a *Actions) UnitOrder(u Unit, ability api.AbilityID)

UnitOrder orders a unit to use an ability.

func (*Actions) UnitOrderPos

func (a *Actions) UnitOrderPos(u Unit, ability api.AbilityID, target api.Point2D)

UnitOrderPos orders a unit to use an ability at a target location.

func (*Actions) UnitOrderTarget

func (a *Actions) UnitOrderTarget(u Unit, abil api.AbilityID, target Unit)

UnitOrderTarget orders a unit to use an ability on a target unit.

func (*Actions) UnitsOrder

func (a *Actions) UnitsOrder(units Units, ability api.AbilityID)

UnitsOrder orders units to all use an ability.

func (*Actions) UnitsOrderPos

func (a *Actions) UnitsOrderPos(units Units, ability api.AbilityID, target api.Point2D)

UnitsOrderPos orders units to all use an ability at a target location.

func (*Actions) UnitsOrderTarget

func (a *Actions) UnitsOrderTarget(units Units, ability api.AbilityID, target Unit)

UnitsOrderTarget orders units to all use an ability on a target unit.

type Bot

type Bot struct {
	client.AgentInfo
	GameLoop uint32

	*Player
	*UnitContext
	*Actions
	*Builder
}

Bot ...

func NewBot

func NewBot(info client.AgentInfo) *Bot

NewBot ...

func (*Bot) UpgradeCost

func (b *Bot) UpgradeCost(upgrade api.UpgradeID) Cost

UpgradeCost returns the cost to research the given upgrade.

type Builder

type Builder struct {
	// contains filtered or unexported fields
}

Builder provides operations to make building/morphing/training/warping units easier.

func NewBuilder

func NewBuilder(info client.AgentInfo, player *Player, units *UnitContext) *Builder

NewBuilder creates a new Builder and registers it to fix FoodUsed rounding for zerg.

func (*Builder) BuildUnit

func (b *Builder) BuildUnit(producer api.UnitTypeID, train api.AbilityID) bool

BuildUnit commands an available producer to use the train ability to build/morph/train/warp a unit. If the food, mineral, and vespene requirements are not met or no producer was found it does nothing and returns false.

func (*Builder) BuildUnitAt

func (b *Builder) BuildUnitAt(producer api.UnitTypeID, train api.AbilityID, pos api.Point2D) bool

BuildUnitAt commands an available producer to use the train ability to build/morph/train/warp a unit at the given location. If the food, mineral, and vespene requirements are not met or no producer was found it does nothing and returns false.

func (*Builder) BuildUnitOn

func (b *Builder) BuildUnitOn(producer api.UnitTypeID, train api.AbilityID, target Unit) bool

BuildUnitOn commands an available producer to use the train ability to build/morph/train/warp a unit on the given target. If the food, mineral, and vespene requirements are not met or no producer was found it does nothing and returns false.

func (*Builder) BuildUnits

func (b *Builder) BuildUnits(producer api.UnitTypeID, train api.AbilityID, count int) int

BuildUnits commands available producers to use the train ability to build/morph/train/warp count units. Returns the number of units actually ordered based on producer, food, mineral, and vespene availability.

func (*Builder) ProductionCost

func (b *Builder) ProductionCost(producerType api.UnitTypeID, train api.AbilityID) Cost

ProductionCost computes the Cost for producerType to train once.

type Cost

type Cost struct {
	Minerals, Vespene, Food uint32
}

Cost represents the full cost of an ability.

func (Cost) Mul

func (c Cost) Mul(count uint32) Cost

Mul multiplies the cost by the given count and returns a new Cost.

type Player

type Player struct {
	api.PlayerCommon
	api.PlayerInfo

	OpponentID   api.PlayerID
	OpponentRace api.Race
}

Player ...

func NewPlayer

func NewPlayer(info client.AgentInfo) *Player

NewPlayer ...

func (*Player) CanAfford

func (p *Player) CanAfford(cost Cost) bool

CanAfford determines if the player can currently afford the given cost.

func (*Player) FoodLeft

func (p *Player) FoodLeft() int

FoodLeft returns the amount under (positive) or over (negative) the current food cap.

func (*Player) Spend

func (p *Player) Spend(cost Cost)

Spend tentatively marks the given resources as unavailable.

type Query

type Query struct {
	// contains filtered or unexported fields
}

Query ...

func NewQuery

func NewQuery(info client.AgentInfo) Query

NewQuery ...

func (*Query) Execute

func (q *Query) Execute() QueryResult

Execute runs the query and returns the result

func (*Query) IgnoreResourceRequirements

func (q *Query) IgnoreResourceRequirements()

IgnoreResourceRequirements ...

func (*Query) PathingFrom

func (q *Query) PathingFrom(start, end api.Point2D) int

PathingFrom ...

func (*Query) Placement

func (q *Query) Placement(ability api.AbilityID, pos api.Point2D) int

Placement ...

func (*Query) PlacementWithUnit

func (q *Query) PlacementWithUnit(tag api.UnitTag, ability api.AbilityID, pos api.Point2D) int

PlacementWithUnit ...

func (*Query) UnitAbilities

func (q *Query) UnitAbilities(tag api.UnitTag) int

UnitAbilities ...

func (*Query) UnitPathing

func (q *Query) UnitPathing(tag api.UnitTag, end api.Point2D) int

UnitPathing ...

type QueryResult

type QueryResult struct {
	// contains filtered or unexported fields
}

QueryResult ...

func (QueryResult) Abilities

Abilities ...

func (QueryResult) AbilitiesQuery

func (q QueryResult) AbilitiesQuery(i int) *api.RequestQueryAvailableAbilities

AbilitiesQuery ...

func (QueryResult) Pathing

func (q QueryResult) Pathing() []*api.ResponseQueryPathing

Pathing ...

func (QueryResult) PathingQuery

func (q QueryResult) PathingQuery(i int) *api.RequestQueryPathing

PathingQuery ...

func (QueryResult) PlacementQuery

func (q QueryResult) PlacementQuery(i int) *api.RequestQueryBuildingPlacement

PlacementQuery ...

func (QueryResult) Placements

Placements ...

type Unit

type Unit struct {
	*api.UnitTypeData
	*api.Unit
	// contains filtered or unexported fields
}

Unit combines the api Unit with it's UnitTypeData and adds some additional convenience methods.

func (Unit) AirWeaponDamage

func (u Unit) AirWeaponDamage() float32

AirWeaponDamage returns damage per shot the unit can do to air targets.

func (Unit) AttackMove

func (u Unit) AttackMove(pos api.Point2D, tollerance float32)

AttackMove issues an attack order if the unit isn't already attacking within tollerance of pos.

func (Unit) AttackTarget

func (u Unit) AttackTarget(target Unit)

AttackTarget issues an attack order if the unit isn't already attacking the target.

func (Unit) BuildUnitAt

func (u Unit) BuildUnitAt(train api.AbilityID, pos api.Point2D) bool

BuildUnitAt ...

func (Unit) BuildUnitOn

func (u Unit) BuildUnitOn(train api.AbilityID, target Unit) bool

BuildUnitOn ...

func (Unit) CanBeTargeted

func (u Unit) CanBeTargeted() bool

CanBeTargeted returns true if the unit type can be targeted for attacks.

func (Unit) CanOrder

func (u Unit) CanOrder(abil api.AbilityID) bool

CanOrder returns true if the unit can be given the given order right now.

func (Unit) GroundWeaponDamage

func (u Unit) GroundWeaponDamage() float32

GroundWeaponDamage returns damage per shot the unit can do to ground targets.

func (Unit) HasAttribute

func (u Unit) HasAttribute(attr api.Attribute) bool

HasAttribute checks if this unit has the specified attribute.

func (Unit) HasBuff

func (u Unit) HasBuff(buffID api.BuffID) bool

HasBuff ...

func (Unit) HasEnergy

func (u Unit) HasEnergy(energy float32) bool

HasEnergy ...

func (Unit) IsBuilt

func (u Unit) IsBuilt() bool

IsBuilt returns true if the unit is done building.

func (Unit) IsCarryingResources

func (u Unit) IsCarryingResources() bool

IsCarryingResources returns true if the unit is carrying minerals or gas.

func (Unit) IsGasBuilding

func (u Unit) IsGasBuilding() bool

IsGasBuilding returns true if the unit is an Assimilator/Refinery/Extractory.

func (Unit) IsGathering

func (u Unit) IsGathering() bool

IsGathering returns true if the unit is currently gathering.

func (Unit) IsHidden

func (u Unit) IsHidden() bool

IsHidden checks if DisplayType is Hidden.

func (Unit) IsIdle

func (u Unit) IsIdle() bool

IsIdle returns true if the unit has no orders.

func (Unit) IsInWeaponsRange

func (u Unit) IsInWeaponsRange(target Unit, gap float32) bool

IsInWeaponsRange returns true if the unit is within weapons range of the target.

func (Unit) IsNil

func (u Unit) IsNil() bool

IsNil checks if the underlying Unit pointer is nil.

func (Unit) IsSnapshot

func (u Unit) IsSnapshot() bool

IsSnapshot checks if DisplayType is Snapshot.

func (Unit) IsStarted

func (u Unit) IsStarted() bool

IsStarted returns true if the unit has started building (is not ghost placement).

func (Unit) IsStructure

func (u Unit) IsStructure() bool

IsStructure checks if the unit is a building (has the Structure attribute).

func (Unit) IsTownHall

func (u Unit) IsTownHall() bool

IsTownHall returns true if the unit is a Nexus/CC/OC/PF/Hatch/Lair/Hive.

func (Unit) IsVisible

func (u Unit) IsVisible() bool

IsVisible checks if DisplayType is Visible.

func (Unit) IsWorker

func (u Unit) IsWorker() bool

IsWorker returns true if the unit is a Probe/SCV/Drone (but not MULE).

func (Unit) Morph

func (u Unit) Morph(train api.AbilityID) bool

Morph ...

func (Unit) MoveTo

func (u Unit) MoveTo(pos api.Point2D, tollerance float32)

MoveTo issues a move order if the unit isn't already moving to or within tollerance of pos.

func (Unit) Order

func (u Unit) Order(ability api.AbilityID)

Order ...

func (Unit) OrderPos

func (u Unit) OrderPos(ability api.AbilityID, target api.Point2D)

OrderPos ...

func (Unit) OrderTarget

func (u Unit) OrderTarget(ability api.AbilityID, target Unit)

OrderTarget ...

func (Unit) Pos2D

func (u Unit) Pos2D() api.Point2D

Pos2D returns the x/y location of the unit.

func (Unit) WeaponDamage

func (u Unit) WeaponDamage(target Unit) float32

WeaponDamage returns damage per shot the unit can do to the given target.

func (Unit) WeaponRange

func (u Unit) WeaponRange(target Unit) float32

WeaponRange returns the maximum range to attack the target from. If the result is negative the target cannot be attacked.

type UnitContext

type UnitContext struct {
	Self    self
	Ally    ally
	Enemy   enemy
	Neutral neutral
	// contains filtered or unexported fields
}

UnitContext stores shared state about units from an observation and provides filtered access to those units.

func NewUnitContext

func NewUnitContext(info client.AgentInfo, bot *Bot) *UnitContext

NewUnitContext creates a new context and registers it to update after each step.

func (*UnitContext) AllUnits

func (ctx *UnitContext) AllUnits() Units

AllUnits returns all units from the most recent observation.

func (*UnitContext) UnitByTag

func (ctx *UnitContext) UnitByTag(tag api.UnitTag) Unit

UnitByTag returns a the unit with the given tag if it was in included in the last observation.

func (*UnitContext) WasObserved

func (ctx *UnitContext) WasObserved(tag api.UnitTag) bool

WasObserved returns true if a unit with the given tag was inlucded in the last observation.

type Units

type Units struct {
	// contains filtered or unexported fields
}

Units ...

func NewUnits

func NewUnits(units []Unit) Units

NewUnits wraps a regular []Unit into a Units struct.

func (Units) AttackMove

func (units Units) AttackMove(pos api.Point2D, tollerance float32)

AttackMove issues an attack order to any unit that isn't already attacking within tollerance of pos.

func (Units) AttackTarget

func (units Units) AttackTarget(target Unit)

AttackTarget issues an attack order to any unit that isn't already attacking the target.

func (Units) Cache

func (units Units) Cache() Units

Cache applies any filtering and returns a struct that owns the underlying Unit slice.

func (Units) CanOrder

func (units Units) CanOrder(ability api.AbilityID) Units

CanOrder ...

func (Units) Center

func (units Units) Center() api.Point2D

Center returns the average location of the units.

func (Units) Choose

func (units Units) Choose(filter func(Unit) bool) Units

Choose returns a new list with only the units for which filter returns true.

func (Units) CloserThan

func (units Units) CloserThan(dist float32, pos api.Point2D) Units

CloserThan returns all units less than or equal to dist from pos.

func (Units) ClosestTo

func (units Units) ClosestTo(pos api.Point2D) Unit

ClosestTo returns the closest unit from the latest observation.

func (Units) Drop

func (units Units) Drop(filter func(Unit) bool) Units

Drop returns a new list without the units for which filter returns true.

func (Units) Each

func (units Units) Each(f func(Unit))

Each calls f on every unit.

func (Units) EachUntil

func (units Units) EachUntil(f func(Unit) bool) bool

EachUntil calls f until it returns true or runs out of elements. Returns the last result of f (true on early return).

func (Units) EachWhile

func (units Units) EachWhile(f func(Unit) bool) bool

EachWhile calls f until it returns false or runs out of elements. Returns the last result of f (false on early return).

func (Units) First

func (units Units) First() Unit

First returns the first unit in the list or a Unit.IsNil() if the list is empty.

func (Units) HasBuff

func (units Units) HasBuff(buffID api.BuffID) Units

HasBuff ...

func (Units) HasEnergy

func (units Units) HasEnergy(energy float32) Units

HasEnergy ...

func (Units) IsBuilt

func (units Units) IsBuilt() Units

IsBuilt ...

func (Units) IsGasBuilding

func (units Units) IsGasBuilding() Units

IsGasBuilding ...

func (Units) IsIdle

func (units Units) IsIdle() Units

IsIdle ...

func (Units) IsStarted

func (units Units) IsStarted() Units

IsStarted ...

func (Units) IsTownHall

func (units Units) IsTownHall() Units

IsTownHall ...

func (Units) IsWorker

func (units Units) IsWorker() Units

IsWorker ...

func (Units) Len

func (units Units) Len() int

Len returns the length of the underlying slice of units.

func (Units) MoveTo

func (units Units) MoveTo(pos api.Point2D, tollerance float32)

MoveTo issues a move order to any unit that isn't already moving to or within tollerance of pos.

func (Units) NoBuff

func (units Units) NoBuff(buffID api.BuffID) Units

NoBuff ...

func (Units) NotTagged

func (units Units) NotTagged(m map[api.UnitTag]bool) Units

NotTagged ...

func (Units) Order

func (units Units) Order(ability api.AbilityID)

Order ...

func (Units) OrderPos

func (units Units) OrderPos(ability api.AbilityID, target api.Point2D)

OrderPos ...

func (Units) OrderTarget

func (units Units) OrderTarget(ability api.AbilityID, target Unit)

OrderTarget ...

func (Units) Partition

func (units Units) Partition(filter func(Unit) bool) (choose Units, drop Units)

Partition splits the units into ones that filter is true for and ones that filter is false for.

func (Units) Slice

func (units Units) Slice() []Unit

Slice copies the units into a regular slice and returns it.

func (Units) Tagged

func (units Units) Tagged(m map[api.UnitTag]bool) Units

Tagged ...

func (Units) Tags

func (units Units) Tags() []api.UnitTag

Tags returns the UnitTags for each unit.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL