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 pure

Package brawl is the free-movement arena: two fighters run around a 15x15 floor for one minute grabbing gold and robb...

Overview

Package brawl is the free-movement arena: two fighters run around a 15x15 floor for one minute grabbing gold and robbing each other. It is written for the chain, so it uses whole numbers only and runs at 10 ticks a second. The browser runs an exact copy, so a match played there gives the same result when the chain replays the inputs.

Units: 1000 = one square. x grows right, y grows down. Fighter A starts near (1,1), fighter B near the far corner.

It is built to be cheap to replay on chain:

  • coins and power-ups sit in the middle of a square, and you grab one by standing on its square, so a tick needs one lookup instead of a loop;
  • timers hold the tick they run out on, so nothing counts down;
  • wall checks only run next to walls.

Constants 12

const U, Size, SizeU, Cells, Mid, TPS, Ticks, RushTicks, Speed, Rad, Melee, Long, Magnet, StartCoins, MaxCoins, CoinEvery, RushEvery, PowerEvery, FirstPower, AttackCD, BlockCD, BlockT, FeintT, DodgeCD, ComboGap, ComboHits, ComboStun, Bounty, Decay, KnockMul, SubStep

 1const (
 2	U     = 1000
 3	Size  = 15
 4	SizeU = Size * U
 5	Cells = Size * Size
 6	Mid   = Size / 2 // middle square
 7
 8	TPS       = 10
 9	Ticks     = 60 * TPS // match length
10	RushTicks = 10 * TPS // last 10 s are a gold rush
11
12	Speed  = 420 // per tick
13	Rad    = 380 // fighter radius
14	Melee  = 1450
15	Long   = 5000
16	Magnet = 4 // squares
17
18	StartCoins = 15
19	MaxCoins   = 22
20	CoinEvery  = 30
21	RushEvery  = 9
22	PowerEvery = 120
23	FirstPower = 80
24
25	AttackCD = 8
26	BlockCD  = 9
27	BlockT   = 5
28	FeintT   = 6
29	DodgeCD  = 13
30
31	ComboGap  = 20 // a combo's hits land within this many ticks of each other
32	ComboHits = 3  // the hit that makes a combo stuns
33	ComboStun = 6
34	Bounty    = 15 // a lead this big doubles what hits knock out of the leader
35
36	Decay    = 500 // knockback kept per tick, per mille
37	KnockMul = 66  // knockback per point of power, per tick
38	SubStep  = 400 // longest move between wall checks
39)
source

const ProfileLen

1const ProfileLen = 22
source

ProfileLen is the length of an encoded profile.

const Still

1const Still = 16
source

Still means no movement this tick; 0..15 are directions.

Variables 2

var BotClass

1var BotClass = [3][3]int{
2	{Coward, Trickster, Reader},
3	{Hunter, Brawler, Reader},
4	{Brawler, Hunter, Trickster},
5}
source

BotClass is the class each level plays on each arena.

Functions 24

func ArenaName

1func ArenaName(seed uint32) string
source

ArenaName names the arena a seed plays on.

func Decode

1func Decode(c byte) (move, act int, ok bool)
source

Decode reads one input character: the move (a direction 0..15 or Still) and the action. ok is false for a character that isn't an input.

func Duel

1func Duel(seed uint32, classA, classB int, inA, inB string) (int, int)
source

Duel is Play for a ghost: every run is recorded from A's corner, so B's inputs (an earlier run) are turned round to play from the far corner. The floor is mirrored through the middle, so the ghost sees the same arena.

func DuelMoves

1func DuelMoves(seed uint32, classA, classB int, inA, inB, moveA, moveB string) (int, int)
source

DuelMoves is Duel with a recipe for each side ("" for the class special).

func Encode

1func Encode(move, act int) byte
source

Encode writes one tick's input as a character.

func Play

1func Play(seed uint32, classA, classB int, inA, inB string) (int, int)
source

Play replays a whole match from both fighters' inputs and returns the gold each one ended with. Short inputs mean standing still for the rest; a bad character panics.

func PlayMoves

1func PlayMoves(seed uint32, classA, classB int, inA, inB, moveA, moveB string) (int, int)
source

PlayMoves is Play with a recipe for each side ("" for the class special).

func Valid

1func Valid(s string) bool
source

Valid reports whether s is a well-formed set of inputs for one fighter.

func Versus

1func Versus(seed uint32, classA, level int, inA string) (int, int)
source

Versus replays a run (side A's inputs) against a house bot on side B.

func VersusMove

1func VersusMove(seed uint32, classA, level int, inA, moveA string) (int, int)
source

VersusMove is Versus with a recipe for side A ("" for the class special). The house bot keeps its class special.

func VersusProfile

1func VersusProfile(seed uint32, classA int, profile, inA string) (int, int)
source

VersusProfile replays a run (side A's inputs) against a profile bot on side B, which plays the profile's class.

func RestoreActor

1func RestoreActor(snap string) Actor
source

RestoreActor rebuilds either kind of bot from its Snapshot.

func NewBot

1func NewBot(level int, seed uint32) *Bot
source

func RestoreBot

1func RestoreBot(snap string) *Bot
source

RestoreBot rebuilds a bot from its Snapshot.

func New

1func New(seed uint32, classA, classB int) *Game
source

New sets up a match. The seed picks the arena and lays out terrain and coins.

func NewLength

1func NewLength(seed uint32, classA, classB, ticks int) *Game
source

NewLength is New for a longer or shorter match (rooms use it); the jackpot still drops at half time and the gold rush fills the last 10 seconds.

func Restore

1func Restore(snap string) *Game
source

Restore rebuilds a match from a Snapshot.

func ParsePlan

1func ParsePlan(text string) (*Plan, string)
source

ParsePlan reads a plan; on a bad step it returns nil and a short error naming the step.

func MustProfile

1func MustProfile(s string) *Profile
source

MustProfile is ParseProfile that panics on a bad profile.

func ParseProfile

1func ParseProfile(s string) (*Profile, error)
source

ParseProfile reads an encoded profile, refusing anything out of range.

func RestoreProfileBot

1func RestoreProfileBot(snap string) *ProfileBot
source

RestoreProfileBot rebuilds a profile bot from its Snapshot.

func MustRecipe

1func MustRecipe(s string) *Recipe
source

MustRecipe is ParseRecipe that panics on a bad recipe. "" gives nil: the class's own special.

func ParseRecipe

1func ParseRecipe(s string) (*Recipe, error)
source

ParseRecipe reads and checks a recipe string. A valid recipe always writes back to the same string, so each move has exactly one spelling.

Types 9

type Actor

interface
1type Actor interface {
2	Act(g *Game, s int) (int, int)
3	Snapshot() string
4}
source

An Actor is a bot a realm can keep between rounds: a house Bot or a ProfileBot.

type Bot

struct
 1type Bot struct {
 2	Level  int
 3	rng    uint32
 4	wait   int
 5	dir    int
 6	target int // square it is heading for, -1 for none
 7	rescan int // decisions left before it looks for a better coin
 8	stuck  int
 9	lastX  int
10	lastY  int
11	turn   int
12}
source

A Bot plays one side of a match.

Methods on Bot

func Act

method on Bot
1func (b *Bot) Act(g *Game, s int) (int, int)
source

Act decides the bot's move and button for this tick, as side s.

func Snapshot

method on Bot
1func (b *Bot) Snapshot() string
source

Snapshot packs a bot's memory the same way.

type Effect

struct
1type Effect struct {
2	Kind byte
3	A, B int
4}
source

Methods on Effect

func Cost

method on Effect
1func (e Effect) Cost() int
source

Cost is what one effect adds to the cooldown a recipe needs, in ticks.

func Describe

method on Effect
1func (e Effect) Describe() string
source

Describe says what one effect does, in words.

type Fighter

struct
 1type Fighter struct {
 2	Class        int
 3	X, Y, VX, VY int
 4	Gold         int
 5	Shield       bool
 6	Double       bool
 7	CD           int // special
 8	AtkCD        int
 9	BlockCD      int
10	BlockT       int
11	FeintT       int
12	InvT         int
13	DashT        int
14	DashX, DashY int
15	StunT        int
16	TrapT        int
17	BoostT       int
18	PadT         int
19	SwingT       int
20	DodgeCD      int
21	Face         int
22	Cell         int // square it stands on; things on a square happen when you step onto it
23	Combo        int // hits landed on the rival in a row
24	ComboT       int // the combo is lost if the next hit doesn't land before this tick
25}
source

Fighter timers (CD .. DodgeCD) hold the tick they run out on.

type Game

struct
 1type Game struct {
 2	Seed      uint32
 3	Arena     int
 4	T         int // ticks played
 5	End       int // match length in ticks (Ticks unless set with NewLength)
 6	F         [2]Fighter
 7	Move      [2]*Recipe  // a recipe used in place of the class special, or nil
 8	Floor     [Cells]byte // Empty, Wall, Pad, Trap
 9	Coin      [Cells]byte // gold on each square: 0, 1, or 3 for the jackpot
10	Power     [Cells]byte // power-up on each square: 0, or kind+1
11	NCoins    int
12	NPower    int
13	nearWall  [Cells]bool
14	nextCoin  int // tick of the next coin drop
15	nextPower int
16	powerKind int
17	jackpot   bool
18	rushOn    bool
19	rng       uint32
20}
source

Methods on Game

func Equip

method on Game
1func (g *Game) Equip(s int, r *Recipe)
source

Equip gives side s a recipe in place of its class special; nil takes it away.

func Over

method on Game
1func (g *Game) Over() bool
source

func Snapshot

method on Game
1func (g *Game) Snapshot() string
source

Snapshot packs everything that changes during a match into a short string, so a realm can store a live match cheaply and carry on later with Restore. The floor isn't stored: it comes back from the seed.

func Step

method on Game
1func (g *Game) Step(move0, act0, move1, act1 int)
source

Step runs one tick. move is a direction 0..15 or Still; act is an action.

func Winner

method on Game
1func (g *Game) Winner() int
source

Winner is 0 or 1, or -1 for a draw.

type Plan

struct
 1type Plan struct {
 2	steps  []planStep
 3	i      int  // current step
 4	on     bool // the current step has started
 5	left   int  // its ticks left
 6	dir    int  // the last move, kept by buttons
 7	target int  // collect: the coin it heads for, -1 for none
 8	look   int  // collect: no looking again before this tick
 9	stuck  int
10	lastX  int
11	lastY  int
12	turn   int // which way it slides round walls
13	hold   int // ticks left of a slide
14	slide  int
15	bot    *Bot // auto
16}
source

Plan is a parsed plain-text plan for one side, run tick by tick.

Methods on Plan

func Done

method on Plan
1func (p *Plan) Done() bool
source

Done reports whether the plan has run out.

func Next

method on Plan
1func (p *Plan) Next(g *Game, s int) (move, act int)
source

Next returns this tick's move and action for side s, reacting to the live game. Once the plan runs out it returns Still, None. Call it once per tick.

type Profile

struct
 1type Profile struct {
 2	Class   int
 3	Think   int
 4	Idle    int
 5	Chase   int
 6	Jackpot int
 7	Reach   int
 8	Attack  int
 9	Block   int
10	Special int
11	Dodge   int
12	Keep    int
13}
source

Methods on Profile

func String

method on Profile
1func (p *Profile) String() string
source

String writes the profile back in its encoded form.

type ProfileBot

struct
 1type ProfileBot struct {
 2	P      Profile
 3	rng    uint32
 4	wait   int
 5	dir    int
 6	target int
 7	rescan int
 8	stuck  int
 9	lastX  int
10	lastY  int
11	turn   int
12	gold   int
13}
source

A ProfileBot plays one side of a match with a profile's traits. It moves like the house bot (plan, head for gold or the rival, slide round walls) and rolls its own dice for every choice, so a replay is exact.

Methods on ProfileBot

func Act

method on ProfileBot
1func (b *ProfileBot) Act(g *Game, s int) (int, int)
source

Act decides the bot's move and button for this tick, as side s.

func Snapshot

method on ProfileBot
1func (b *ProfileBot) Snapshot() string
source

Snapshot packs a profile bot's memory: its profile, then its counters.

type Recipe

struct
1type Recipe struct {
2	Name string
3	CD   int
4	Fx   []Effect
5}
source

Methods on Recipe

func Cost

method on Recipe
1func (r *Recipe) Cost() int
source

Cost is the shortest cooldown the recipe's effects allow: the sum of the effects' costs, plus half of all but the dearest one, since moves that do several things at once are worth more than their parts. Never below MinCD.

func Describe

method on Recipe
1func (r *Recipe) Describe() string
source

Describe says what the recipe does, in words.

func String

method on Recipe
1func (r *Recipe) String() string
source

String writes the recipe back in its one spelling.

Dependencies

Imports 3

/p/g1ftppd2jpfx0p8cy08th4u9whwvqcpychhlad28/brawl/v2

Imported by indexer

Source Files 15