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.

engine source pure

Package engine is the deterministic battle core of Cage Match. Two fighters trade actions on a small grid; the same t...

Overview

Package engine is the deterministic battle core of Cage Match. Two fighters trade actions on a small grid; the same two fighters always produce the same recap, so any recorded fight can be replayed and verified by anyone, on or off chain.

Constants 3

Functions 1

func Run

1func Run(a, b Fighter) Recap
source

Run resolves a whole fight and returns its recap.

Types 9

type Action

struct
1type Action struct {
2	Kind ActionKind
3	Dir  Dir
4}
source

Action is one round's decision. Dir is used by Move and Attack.

type ActionKind

ident
1type ActionKind int
source

ActionKind is what a fighter does in a round.

type Dir

ident
1type Dir int
source

Dir is a cardinal direction.

type Fighter

interface
1type Fighter interface {
2	Name() string
3	Step(View) Action
4}
source

Fighter is a battle program. Step must be deterministic.

type FighterState

struct
1type FighterState struct {
2	P         Pos
3	HP        int
4	Charged   bool // next Attack deals ChargeDamage, then clears
5	Defending bool // incoming damage halved this round
6}
source

FighterState is the public state of one fighter.

type Frame

struct
1type Frame struct {
2	Round      int
3	APos, BPos Pos
4	AHP, BHP   int
5	AAct, BAct Action
6	ADmg, BDmg int // damage dealt to the enemy this round
7}
source

Frame is one resolved round of a fight.

type Pos

struct
1type Pos struct {
2	X, Y int
3}
source

Pos is a tile on the grid. (0,0) is the top-left corner.

Methods on Pos

func Delta

method on Pos
1func (p Pos) Delta(d Dir) Pos
source

Delta returns the tile one step in direction d from p.

type Recap

struct
1type Recap struct {
2	A, B   string
3	Winner int
4	Rounds int
5	Frames []Frame
6}
source

Recap is the full record of a fight. Winner is 0 for A, 1 for B, -1 draw.

type View

struct
1type View struct {
2	Round int
3	Self  FighterState
4	Enemy FighterState
5}
source

View is what a fighter sees at the start of a round.

Dependencies

Imports 0

Imports nothing.

/p/g1ejwp09wwnu6psem2sdwrh7l7xcldqm6zz3vu2v/cagematch/engine

Imported by indexer

Source Files 2