Skip to content Search Apps Documentation Source Content Run Reset Eval Playground File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

Community realm. Read the code first. Community realm, deployed by its author. Read the code before you interact or send coins.

arena source realm

Package arena runs matches between bots that other people deploy as their own realms. Every turn the arena calls each...

Overview

Package arena runs matches between bots that other people deploy as their own realms. Every turn the arena calls each bot's code, so the chain is the referee and every bot's source is public.

Matches have two speeds:

  • Fast: Play (or Fight) runs a whole match in one transaction.
  • Step: if a match can't finish in one transaction (a bot crashes or runs out of gas), StartStepMode switches it to one move per SubmitMove transaction. The bot whose move can't be made misses its deadline and ClaimForfeit records the loss. Crashing can't save a bot from a loss.

Constants 2

const MoveTimeout, RatedCooldown

1const (
2	// MoveTimeout is how many blocks a bot has to make its move in step mode
3	// before anyone can claim a forfeit.
4	MoveTimeout = 100
5	// RatedCooldown is how many blocks must pass between two rated matches of
6	// the same pair of bots. Rematches in between are friendlies, so nobody
7	// can pump a rating by replaying the same opponent.
8	RatedCooldown = 1000
9)
source

Functions 13

func Challenge

crossing Action
1func Challenge(cur realm, a, b string) int
source

Challenge records a new match between two registered bots and returns its id. It runs no bot code, so it always succeeds; play it with Play or, if that fails, with step mode.

func ClaimForfeit

crossing Action
1func ClaimForfeit(cur realm, id int) string
source

ClaimForfeit ends a step-mode match whose waiting bot missed its deadline. Anyone may call it.

func Fight

crossing Action
1func Fight(cur realm, a, b string) string
source

Fight challenges and plays in one transaction, saving the match once. If it fails, nothing is recorded: use Challenge, then Play or step mode.

func MatchSummary

Action
1func MatchSummary(id int) string
source

MatchSummary returns the summary of a match, for other realms and tools.

func Play

crossing Action
1func Play(cur realm, id int) string
source

Play runs the rest of a match in this transaction. If a bot written in realm code crashes or runs out of gas, the whole transaction fails and the match stays as it was: switch it to step mode with StartStepMode.

func RegisterBot

crossing Action
1func RegisterBot(cur realm, name string, b bot.Bot)
source

RegisterBot enters a bot with a Move method. Call it from your bot realm, usually in init:

Example
1func init(cur realm) { arena.RegisterBot(cross(cur), "my-bot", &myBot{}) }

func RegisterStrategy

crossing Action
1func RegisterStrategy(cur realm, name string, s bot.Strategy)
source

RegisterStrategy enters a bot written as a plain function. A function declared in a /p/ package has one extra guarantee: if it crashes, the arena can catch it straight away and score a forfeit without step mode.

func Render

1func Render(path string) string
source

Render draws the arena pages in gnoweb:

Example
1""                   leaderboard, recent matches, rules
2"bot/<name>"         a bot's record, source link and a challenge button
3"match/<id>"         the final board, key moments and actions
4"match/<id>/<turn>"  the board after one turn

func StartStepMode

crossing Action
1func StartStepMode(cur realm, id int)
source

StartStepMode switches a pending match to one move per transaction. Anyone may call it.

func SubmitMove

crossing Action
1func SubmitMove(cur realm, id int) string
source

SubmitMove asks the bot whose turn it is for its move and records it. The move comes from the bot's own code, so nobody can submit a fake one. Anyone may call it.

func GetBot

Action
1func GetBot(name string) (BotInfo, bool)
source

GetBot returns public information about a bot.

Types 4

type Bot

struct
 1type Bot struct {
 2	Name       string
 3	Realm      string  // realm that registered it; its source is public
 4	Owner      address // account that sent the registering transaction
 5	Registered int64   // block height
 6	Rating     int
 7	Wins       int
 8	Losses     int
 9	Draws      int
10	Forfeits   int // losses by forfeit, also counted in Losses
11
12	impl        bot.Bot
13	fn          bot.Strategy
14	recentRated string // "opponent@block," for recent rated matches, see claimRatedSlot
15}
source

Bot is a registered bot.

Methods on Bot

func Played

method on Bot
1func (b *Bot) Played() int
source

Played is the number of finished matches.

type BotInfo

struct
1type BotInfo struct {
2	Name, Realm                                   string
3	Owner                                         address
4	Rating, Wins, Losses, Draws, Forfeits, Played int
5}
source

BotInfo describes a bot for other realms and off-chain tools.

type Match

struct
 1type Match struct {
 2	ID         int
 3	BotA, BotB string
 4	Status     Status
 5	Game       game.Game
 6	Challenger address
 7	Created    int64
 8	Rated      bool // decided when the match is created, see RatedCooldown
 9
10	// step mode
11	Waiting  int        // side whose move is due
12	Held     bot.Action // side 0's move for the current turn, once made
13	Deadline int64      // block height by which Waiting must move
14
15	// result
16	Winner  int    // 0, 1, or -1 for a draw
17	Forfeit bool   // the loser forfeited
18	Reason  string // why, for forfeits
19	Delta   int    // rating change for A (B gets the opposite)
20	Settled int64  // block height
21}
source

Match is one game between two bots. Side 0 is A, side 1 is B.

Methods on Match

func Bot

method on Match
1func (m *Match) Bot(side int) string
source

Bot returns the name of the bot playing side.

func Summary

method on Match
1func (m *Match) Summary() string
source

Summary is a one-line description of the match.

type Status

ident
1type Status int
source

Status of a match.

Methods on Status

func String

method on Status
1func (s Status) String() string
source

Dependencies

Source Files 15

Directories 1