spar

package
v0.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 24, 2026 License: MIT Imports: 8 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package spar provides a controlled PvP sparring harness: it logs in two or more agents, equips and moves them to a non-empire arena, and runs scripted (or human-partnered) battles so combat mechanics are observable and testable.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsNonEmpireArena

func IsNonEmpireArena(s game.SystemData) bool

IsNonEmpireArena reports whether a system permits anything-goes PvP: it is not owned by an empire, or is lawless / unpoliced / a pirate stronghold.

func SelectArena

func SelectArena(systems []game.SystemData, byID map[string]game.SystemData, reachable func(systemID string) bool) (string, error)

SelectArena picks the best non-empire arena from systems: it must be a non-empire system, be reachable by all combatants (reachable(id) true), have a rendezvous POI, and have safe-space adjacency. Among candidates the first match (by input order) is returned. Pure — no network.

func ValidateArenaSystem

func ValidateArenaSystem(s game.SystemData) error

ValidateArenaSystem checks that an already-loaded system is a legal arena. Used at arrival to confirm a --arena value really is outside empire space.

Types

type Action

type Action struct {
	Kind         string         // "battle" | "noop"
	BattleAction string         // advance | retreat | stance | target
	Payload      map[string]any // stance, target_id
}

Action is a Policy's chosen move. Kind is "battle" (dispatch via client.Battle with BattleAction+Payload) or "noop" (do nothing this tick).

type Combatant

type Combatant struct {
	AgentID  string
	Username string
	Client   game.GameClient
	Policy   Policy // nil for the human partner slot
	WeaponID string
	ShieldID string
	NoEquip  bool
	Logger   *log.Logger // must be non-nil: game.NavigateToSystem dereferences it
}

Combatant is one logged-in agent plus its assigned policy and setup config.

func (*Combatant) PlayerID

func (c *Combatant) PlayerID() string

PlayerID returns the combatant's player id from live state.

func (*Combatant) Setup

func (c *Combatant) Setup(ctx context.Context, arenaSystem, rendezvousType string) error

Setup equips the combatant (if needed), navigates it to the arena system, and travels to the rendezvous POI type. Equip runs first because stations are typically one or more jumps from lawless arenas.

type Match

type Match struct {
	Combatants   []*Combatant
	Arena        string // arena system id (must be set; auto-discovery deferred)
	Rendezvous   string // POI type, e.g. "asteroid_belt"
	AggressorIdx int    // index of the bot that initiates (botvbot mode)
	Partner      bool   // partner mode: don't initiate; wait for a human to attack
	MaxTicks     int
	Logger       *log.Logger
}

Match orchestrates a sparring session.

func (*Match) Run

func (m *Match) Run(ctx context.Context) error

Run sets up all combatants, initiates (or waits for) the fight, drives the bots, and prints telemetry plus a final summary.

type Policy

type Policy interface {
	Name() string
	Decide(View) Action
}

Policy decides one battle action from a View. Implementations are pure functions of the View, which keeps them unit-testable. This interface is the seam where custom .smolt-style battle scripts plug in later.

func NewAggressor

func NewAggressor() Policy

NewAggressor advances to the engaged zone, then targets the nearest enemy and holds the fire stance.

func NewDummy

func NewDummy() Policy

NewDummy braces and never advances or fires — a low-risk practice partner.

func NewRetreater

func NewRetreater() Policy

NewRetreater immediately adopts the flee stance (which auto-retreats over several ticks), exercising the escape mechanic.

func NewSkirmisher

func NewSkirmisher(hullFloor int) Policy

NewSkirmisher holds the mid zone and fires, but retreats one zone when its own hull percentage drops below hullFloor.

func PolicyByName

func PolicyByName(name string) (Policy, error)

PolicyByName resolves a preset name to a Policy. The skirmisher uses a 40% hull floor by default.

type View

type View struct {
	Self     game.BattleParticipant
	Enemies  []game.BattleParticipant
	Allies   []game.BattleParticipant
	BattleID string
}

View is the read-only battle picture handed to a Policy each tick.

func BuildView

func BuildView(b *game.BattleState, selfID string) (View, bool)

BuildView assembles a View for the participant whose PlayerID is selfID. Returns ok=false if selfID is not among the participants.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL