const Easy, Normal, Hard
Bot levels.
Community realm. Read the code first. Community realm, deployed by its author. Read the code before you interact or send coins.
Package brawl is the free-movement arena: two fighters run around a 15x15 floor for one minute grabbing gold and robb...
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:
Bot levels.
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)Classes.
Actions.
Square kinds.
Power-up kinds, stored as kind+1 in Game.Power.
Effect letters.
Dash modes.
ProfileLen is the length of an encoded profile.
Still means no movement this tick; 0..15 are directions.
ArenaName names the arena a seed plays on.
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.
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.
DuelMoves is Duel with a recipe for each side ("" for the class special).
Encode writes one tick's input as a character.
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.
PlayMoves is Play with a recipe for each side ("" for the class special).
Valid reports whether s is a well-formed set of inputs for one fighter.
Versus replays a run (side A's inputs) against a house bot on side B.
VersusMove is Versus with a recipe for side A ("" for the class special). The house bot keeps its class special.
VersusProfile replays a run (side A's inputs) against a profile bot on side B, which plays the profile's class.
RestoreActor rebuilds either kind of bot from its Snapshot.
RestoreBot rebuilds a bot from its Snapshot.
New sets up a match. The seed picks the arena and lays out terrain and coins.
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.
Restore rebuilds a match from a Snapshot.
ParsePlan reads a plan; on a bad step it returns nil and a short error naming the step.
MustProfile is ParseProfile that panics on a bad profile.
ParseProfile reads an encoded profile, refusing anything out of range.
RestoreProfileBot rebuilds a profile bot from its Snapshot.
MustRecipe is ParseRecipe that panics on a bad recipe. "" gives nil: the class's own special.
ParseRecipe reads and checks a recipe string. A valid recipe always writes back to the same string, so each move has exactly one spelling.
An Actor is a bot a realm can keep between rounds: a house Bot or a ProfileBot.
A Bot plays one side of a match.
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}Fighter timers (CD .. DodgeCD) hold the tick they run out on.
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}Equip gives side s a recipe in place of its class special; nil takes it away.
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.
Step runs one tick. move is a direction 0..15 or Still; act is an action.
Winner is 0 or 1, or -1 for a draw.
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 guard bool // guard on
17}Plan is a parsed plain-text plan for one side, run tick by tick.
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.
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.
Describe says what the recipe does, in words.
String writes the recipe back in its one spelling.