Skip to content Search Apps Documentation Source Content 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 holds the duel rules. The same source compiles as Go and as Gno, so it stays inside the Go 1.17 subset...

Overview

Package engine holds the duel rules. The same source compiles as Go and as Gno, so it stays inside the Go 1.17 subset: no generics, no min or max builtins, no range over an integer, no maps and no imports.

Constants 6

const GainBlock, GainCounter, Hit, HitBlock, ApplyVulnerable, GainStrength, VulnerableIfCancelled, MoveVulnerable, GainVulnerable, HitPerVulnerable, BlockPerVulnerable, StripBlock, HitHardest, HitIfNotAttacked

 1const (
 2	GainBlock EffectKind = iota
 3	GainCounter
 4	Hit      // deal N damage
 5	HitBlock // deal damage equal to your Block
 6	ApplyVulnerable
 7	GainStrength
 8	VulnerableIfCancelled // apply N Vulnerable if this card cancelled a card this beat
 9	MoveVulnerable        // Block phase: move all your Vulnerable to the opponent
10	GainVulnerable        // gain N Vulnerable yourself
11	HitPerVulnerable      // deal N damage, and N more for each Vulnerable on you
12	BlockPerVulnerable    // Block phase: gain N Block, and N more for each Vulnerable on you
13	StripBlock            // the opponent loses all Block at the end of the step
14	HitHardest            // deal the HP the hardest opponent hit took from you this round, up to N
15	HitIfNotAttacked      // deal N damage if no opponent attack lands this beat
16)
source

const Cancelled, ParryEnded, BlockGained, CounterGained, HitLanded, CounterHit, VulnerableApplied, StrengthGained, VulnerableMoved, VulnerableGained, BlockStripped

 1const (
 2	Cancelled         EventKind = iota // Card was cancelled by the opponent's Interrupt or Parry
 3	ParryEnded                         // Card made its last Parry cancel; its later beats stay empty
 4	BlockGained                        // Side gained N Block from Card
 5	CounterGained                      // Side gained Counter N from Card
 6	HitLanded                          // Card hit the opponent for N damage to HP, Blocked absorbed
 7	CounterHit                         // the opponent's Counter dealt N to Side's HP after Card hit
 8	VulnerableApplied                  // Card applied N Vulnerable to the opponent
 9	StrengthGained                     // Side gained N Strength from Card
10	VulnerableMoved                    // Card moved Side's N Vulnerable to the opponent, who keeps up to the cap
11	VulnerableGained                   // Side gained N Vulnerable from Card
12	BlockStripped                      // Card took the opponent's N Block
13)
source

Functions 1

func ProofOfConcept

1func ProofOfConcept() *Ruleset
source

ProofOfConcept is the proof-of-concept ruleset: the two basics and the 10-card starter packs of the Pickers, Ironhide and Delvers clans.

Types 17

type Card

struct
 1type Card struct {
 2	Name      string
 3	Cost      int
 4	Tier      Tier
 5	Special   bool // spent once played; basics are not
 6	Rare      bool // the clan's signature card; a deck holds exactly one
 7	Interrupt bool
 8	Parry     int      // Parry N: attacks it cancels while active; 0 for no Parry
 9	Block     []Effect // Block phase
10	Damage    []Effect // Damage phase, in printed order
11	OnCancel  []Effect // Block phase of the beat the card is cancelled on
12	// CancelDamage resolves in the card's tier, in the Damage phase of the beat it is
13	// cancelled on.
14	CancelDamage []Effect
15}
source

Methods on Card

func Attack

method on Card
1func (c *Card) Attack() bool
source

Attack reports whether the card's text deals damage, including when it is cancelled.

type CardID

ident
1type CardID int
source

CardID indexes Ruleset.Cards.

type Clan

struct
1type Clan struct {
2	Name string
3	Pool uint64 // bit i set: Ruleset.Cards[i] is in the pool
4}
source

Clan is a named pool of special cards.

type Effect

struct
1type Effect struct {
2	Kind EffectKind
3	N    int
4}
source

type Event

struct
 1type Event struct {
 2	Beat    int // 1 to 3
 3	Phase   Phase
 4	Tier    Tier
 5	Step    int // from 1 within a beat, phase and tier; equal for effects that resolve together
 6	Kind    EventKind
 7	Side    Side
 8	Card    CardID
 9	N       int
10	Blocked int       // HitLanded and CounterHit: damage absorbed by Block
11	Doubled bool      // HitLanded: the defender's Vulnerable doubled it
12	After   [2]Vitals // both gnomes once the whole step has resolved
13}
source

Event is one effect of a round's resolution. Side owns Card. A HitLanded, a VulnerableApplied or a BlockStripped lands on the other gnome, a VulnerableMoved changes both, and every other kind changes Side's own Vitals. N is the change after caps, the damage that reached HP, or the tokens that left the mover.

type Gnome

struct
1type Gnome struct {
2	HP, Vulnerable, Strength int
3	Spent                    uint64 // special cards played, by CardID bit
4}
source

Gnome is one side's state between rounds; Block and Counter end with each round.

type Outcome

struct
1type Outcome struct {
2	State  State
3	Result Result
4}
source

Outcome is the state after a round, and the match result once it has one.

type Phase

ident
1type Phase int
source

Phase is the part of a beat an event belongs to.

type Plan

slice
1type Plan []CardID
source

Plan is the ordered cards of one round; their costs sum to 3.

type Result

ident
1type Result int
source

Result is how a round left the match.

type Ruleset

struct
 1type Ruleset struct {
 2	Cards         []Card
 3	Clans         []Clan
 4	HP            int // starting HP of both gnomes
 5	BlockCap      int
 6	CounterCap    int
 7	VulnerableCap int
 8	StrengthCap   int
 9	// VulnerableDoublesOneHit: each hit against a Vulnerable gnome deals double and uses a
10	// token. Otherwise the next card to hit deals double on every hit and uses one token.
11	VulnerableDoublesOneHit bool
12	// StrengthLastsTheRound: Strength ends with the round, like Block and Counter. Otherwise
13	// it lasts the match.
14	StrengthLastsTheRound bool
15	// VulnerableLastsTheRound: unused Vulnerable ends with the round. Otherwise it lasts
16	// until hits use it.
17	VulnerableLastsTheRound bool
18}
source

Ruleset holds every card and number the rules use.

Methods on Ruleset

func CardByName

method on Ruleset
1func (rs *Ruleset) CardByName(name string) (CardID, bool)
source

func ClanByName

method on Ruleset
1func (rs *Ruleset) ClanByName(name string) (Clan, bool)
source

func LegalDeck

method on Ruleset
1func (rs *Ruleset) LegalDeck(clan Clan, deck uint64) bool
source

LegalDeck reports whether deck, a bit set by CardID, is deckSize cards of clan's pool holding exactly one Rare.

func LegalPlans

method on Ruleset
1func (rs *Ruleset) LegalPlans(s State, side Side, deck uint64) []Plan
source

LegalPlans lists every plan side can play from deck in state s: costs summing to 3, basics any number of times, each unspent special of deck at most once. Plans come in card order, depth first.

func PlanOf

method on Ruleset
1func (rs *Ruleset) PlanOf(names ...string) (Plan, bool)
source

PlanOf looks each card up by name. It reports false when a name matches no card.

func Resolve

method on Ruleset
1func (rs *Ruleset) Resolve(s State, a, b Plan) Outcome
source

Resolve plays round s.Round. Both plans must be legal for their side in s (LegalPlans); an illegal plan is a caller error.

func Start

method on Ruleset
1func (rs *Ruleset) Start() State
source

Start is the state before round 1.

func Trace

method on Ruleset
1func (rs *Ruleset) Trace(s State, a, b Plan) (Outcome, []Event)
source

Trace resolves the round as Resolve does and also returns its events in order.

type State

struct
1type State struct {
2	Round  int
3	Gnomes [2]Gnome
4}
source

State is the match between rounds. Round is the round about to be played, 1 to 3.

type Tier

ident
1type Tier int
source

Tier orders effects inside a phase.

type Vitals

struct
1type Vitals struct {
2	HP, Block, Counter, Vulnerable, Strength int
3}
source

Vitals is one gnome's numbers during a round.

Dependencies

Imports 0

Imports nothing.

/p/g1sl6fyq6mrc3wydt8xluhxx4aqsudpp9vhv6g2a/gnomehall/engine

Imported by indexer

Source Files 7