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.

v2 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 4

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

const SeasonLength

1const SeasonLength = 720000
source

SeasonLength is about 30 days at Onyx's ~3.6 s blocks.

Functions 36

func ArenaJSON

Action
1func ArenaJSON() string
source

ArenaJSON returns counts, the current season and the block height.

func BotJSON

Action
1func BotJSON(name string) string
source

BotJSON returns one bot, with its earlier versions.

func BotsJSON

Action
1func BotsJSON() string
source

BotsJSON returns every bot, ranked like the leaderboard.

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 CloseTournament

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

CloseTournament marks a tournament finished once all its matches are settled (matches finished through step mode don't do it themselves). Anyone may call it.

func CreateTournament

crossing Action
1func CreateTournament(cur realm, name string, capacity int) int
source

CreateTournament opens a round-robin for up to capacity bots (2 to 8).

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 JoinTournament

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

JoinTournament enters a bot you own into an open tournament.

func MatchJSON

Action
1func MatchJSON(id int) string
source

MatchJSON returns a match with every turn, for replays: positions, gold and coins after each turn, both actions and what happened.

func MatchSummary

Action
1func MatchSummary(id int) string
source

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

func MatchesJSON

Action
1func MatchesJSON(botName string, limit int) string
source

MatchesJSON returns up to limit matches, newest first, optionally only those of one bot (looking at no more than the last 500).

func NextTournamentMatch

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

NextTournamentMatch creates the tournament's next match and returns its id. Play it with Play, or step mode if a bot keeps it from finishing. Anyone may call it.

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 PlayTournament

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

PlayTournament creates the next match and plays it in one transaction. If a bot makes it fail, nothing is recorded: use NextTournamentMatch, then Play or step mode. Anyone may call it.

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
5"tournaments"        all tournaments
6"tournament/<id>"    a tournament's table, schedule and actions
7"seasons"            champions of past seasons

func Retire

crossing Action
1func Retire(cur realm, name string)
source

Retire takes a bot off the leaderboard and stops new challenges against it. Its history stays. Matches already created can still be finished.

func SeasonInfo

Action
1func SeasonInfo() (number int, endsAt int64)
source

SeasonInfo reports the current season number and the block it ends at.

func SeasonsJSON

Action
1func SeasonsJSON() string
source

SeasonsJSON returns the top 10 of every finished season, newest first.

func SetDescription

crossing Action
1func SetDescription(cur realm, name, text string)
source

SetDescription sets the one-line description shown on the bot's page.

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 StartTournament

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

StartTournament closes entries and fixes the schedule. Only the creator can start 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 TournamentNext

Action
1func TournamentNext(id int) (a, b string, ok bool)
source

TournamentNext returns the next pairing still to be created, if any.

func Unretire

crossing Action
1func Unretire(cur realm, name string)
source

Unretire brings a retired bot back.

func UpgradeBot

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

UpgradeBot points an existing bot at new code, keeping its name, rating and record. Call it from the new bot realm's init, sent by the bot's owner:

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

func UpgradeStrategy

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

UpgradeStrategy is UpgradeBot for a bot written as a plain function.

func GetBot

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

GetBot returns public information about a bot.

func PastSeason

Action
1func PastSeason(number int) []SeasonStanding
source

PastSeason returns the top 10 of a finished season.

Types 8

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	// season record, reset when a new season starts (see season.gno)
13	SeasonWins, SeasonLosses, SeasonDraws int
14
15	// owner tools (see owner.gno)
16	Description string
17	Retired     bool
18	Version     int    // 1 at registration, +1 per upgrade
19	History     string // "realm@block," of previous versions
20
21	impl        bot.Bot
22	fn          bot.Strategy
23	recentRated string // "opponent@block," for recent rated matches, see claimRatedSlot
24}
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.

func PreviousVersions

method on Bot
1func (b *Bot) PreviousVersions() []string
source

PreviousVersions lists the realms a bot used before its current one, oldest first.

type BotInfo

struct
1type BotInfo struct {
2	Name, Realm, Description                      string
3	Owner                                         address
4	Rating, Wins, Losses, Draws, Forfeits, Played int
5	Retired                                       bool
6	Version                                       int
7}
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	Season     int  // season the match was created in
10	Tournament int  // tournament id, 0 for a normal challenge
11
12	// step mode
13	Waiting  int        // side whose move is due
14	Held     bot.Action // side 0's move for the current turn, once made
15	Deadline int64      // block height by which Waiting must move
16
17	// result
18	Winner  int    // 0, 1, or -1 for a draw
19	Forfeit bool   // the loser forfeited
20	Reason  string // why, for forfeits
21	Delta   int    // rating change for A (B gets the opposite)
22	Settled int64  // block height
23}
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 SeasonStanding

struct
1type SeasonStanding struct {
2	Bot                 string
3	Rating              int
4	Wins, Losses, Draws int
5}
source

SeasonStanding is one line of a finished season's top 10.

type Standing

struct
1type Standing struct {
2	Bot                         string
3	Played, Wins, Draws, Losses int
4	GoldFor, GoldAgainst        int
5	Points                      int
6}
source

Standing is one bot's line in a tournament table.

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

type Tournament

struct
 1type Tournament struct {
 2	ID       int
 3	Name     string
 4	Creator  address
 5	Created  int64
 6	Capacity int
 7	Status   TournamentStatus
 8	Entrants []string
 9	Pairs    []string // "a|b", in play order, fixed at start
10	MatchIDs []int    // match id for each pair once created
11	Winner   string
12}
source

Tournament is a round-robin between up to maxEntrants bots.

Methods on Tournament

func Standings

method on Tournament
1func (t *Tournament) Standings() []Standing
source

Standings returns the tournament table, best first.

type TournamentStatus

ident
1type TournamentStatus int
source

TournamentStatus of a tournament.

Methods on TournamentStatus

func String

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

Dependencies

Source Files 24