bot source pure
Package bot is everything a bot author needs: what a bot sees each turn, the moves it can make, and helpers for findi...
Package bot is everything a bot author needs: what a bot sees each turn, the moves it can make, and helpers for finding its way around the board.
A bot is either a type with a Move method (it can live in its own realm and keep memory between turns) or a plain Strategy function.
2
6
func Adjacent
Adjacent reports whether a and b are one move apart, which is attack range.
func Dist
Dist is the number of moves between a and b.
func OnBoard
OnBoard reports whether p is inside the board.
func StepAway
StepAway returns a move that takes from one step further from danger, staying on the board. It returns Stay if no move increases the distance.
func StepToward
StepToward returns the move that takes from one step closer to to, moving along X first. It returns Stay when from == to.
func Apply
Apply returns where p ends up after a. Moves off the edge leave p in place.
5
type Action
identAction is what a bot does on one turn.
type Bot
interfaceBot is a bot with a Move method. Implement it on a type in your own realm to keep memory between turns.
type Pos
structPos is a square on the board. X grows to the right, Y grows downwards.
type State
struct 1type State struct {
2 Match int // match id, so bots with memory can tell matches apart
3 EnemyBot string // the opponent's registered name, so bots can keep notes on it
4 Turn int // 0 .. Turns-1
5 Me Pos
6 Enemy Pos
7 MyGold int
8 EnemyGold int
9 Coins []Pos // coins still on the board
10 MyLast Action // what this bot did last turn (Stay on turn 0)
11 EnemyLast Action // what the enemy did last turn (Stay on turn 0)
12}State is what a bot sees on its turn. It is a fresh copy every turn, so changing it has no effect on the real match.
Methods on State
func NearestCoin
method on StateNearestCoin returns the closest coin to the bot, if any are left.
func TurnsLeft
method on StateTurnsLeft is how many turns remain after this one.
func Winning
method on StateWinning reports whether the bot has more gold than the enemy.
type Strategy
funcStrategy is a bot written as a plain function, usually in a /p/ package.
Imports 0
Imports nothing.