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.

v0 source pure

Package physics is the Spot Kick penalty engine: a port of the browser game's gno-shots/src/physics.js that produces ...

Overview

Package physics is the Spot Kick penalty engine: a port of the browser game's gno-shots/src/physics.js that produces bit-identical results.

The JavaScript engine uses only + - * /, square roots, comparisons and 32-bit integer mixing inside its simulation, all of which IEEE-754 rounds exactly; gno does float64 arithmetic in software with the same rounding, and its math.Sqrt is correctly rounded. So the same inputs give the same bits here as in any browser, provided every operation happens in the same order. That is the rule this file follows, line by line:

  • every float constant is a variable, never a Go constant: constant expressions are folded at arbitrary precision, JavaScript rounds after each operation;
  • expressions keep the JavaScript order and grouping;
  • JavaScript's Math.min, Math.max and Math.round are reproduced exactly (jsMin, jsMax, jsRound), down to the sign of zero.

Unlike the browser, which keeps simulating for the replay, Simulate stops as soon as the kick is decided; nothing after that can change the verdict.

Constants 3

Variables 1

var PartNames

1var PartNames = [nParts]string{"left leg", "body", "left arm", "left glove", "right leg", "right arm", "right glove", "head"}
source

PartNames are the browser's names for the parts.

Functions 7

func ResultOf

1func ResultOf(r Result, pl Plan) penalty.Result
source

ResultOf summarises a decided kick in the realm's integer units.

func SimulateShot

1func SimulateShot(shot penalty.ShotParams, plan penalty.KeeperPlan, cfg penalty.Config) penalty.Result
source

SimulateShot is the realm's outcome function on this engine: the taker's six inputs and the keeper's four, under a game's constants.

func DefaultParams

1func DefaultParams() Params
source

DefaultParams returns the constants of the browser engine.

func ParamsOf

1func ParamsOf(c penalty.Config) Params
source

ParamsOf converts a game's constants from the realm's integer units (mm, mm/s, ms, per-mille, milli-radii) to the engine's. The defaults convert to DefaultParams exactly: each division is correctly rounded, so 2424/1000 is the same double as the browser's literal 2.424.

func DecodePlan

1func DecodePlan(raw [4]uint16, p Params) Plan
source

DecodePlan maps four uint16 onto a plan exactly as the browser does.

func Simulate

1func Simulate(in Shot, pl Plan, prm Params, opt Options) Result
source

Simulate plays a kick to its verdict. plan is ignored with opt.NoKeeper.

func ShotOf

1func ShotOf(s penalty.ShotParams) Shot
source

ShotOf converts the taker's ten-input half (integer units plus the mishit seed) to the engine's units, as the web game does: each value / 1000.

Types 8

type Commit

struct
1type Commit struct {
2	Step int
3	T0   float64
4	VX   float64
5	Jump float64
6	Star bool
7	Read bool
8}
source

Commit is one move the keeper made: when, how fast sideways, how high.

type Contact

struct
1type Contact struct {
2	Step    int
3	Part    int // index into PartNames
4	Catch   bool
5	GaveWay bool
6}
source

Contact is one keeper touch, decided at its first contact.

type Launch

struct
1type Launch struct {
2	Vel, Spin          [3]float64
3	Speed              float64
4	FuzzX, FuzzY       float64 // contact error the mishit seed added, ball radii
5	ContactX, ContactY float64 // where the boot actually met the ball
6}
source

Launch is the ball as it leaves the boot.

type Options

struct
1type Options struct {
2	NoKeeper  bool // an empty goal
3	NoMisread bool // a keeper that reads perfectly
4	// Trace folds the state into Result.Trace every TraceEvery steps and at
5	// the deciding step, for comparing with the browser engine bit for bit.
6	Trace      bool
7	TraceEvery int
8}
source

Options are for tests and analysis.

type Params

struct
 1type Params struct {
 2	GoalHalfWidth float64 // m
 3	GoalHeight    float64 // m
 4	KeeperScale   float64
 5	ReactionMin   float64 // s
 6	ReactionMax   float64
 7	StarShare     float64 // of the speed range
 8	ReadShare     float64
 9	DiveMin       float64 // m/s
10	DiveMax       float64
11	JumpMin       float64 // m/s
12	JumpMax       float64
13	BallMinSpeed  float64 // m/s
14	BallMaxSpeed  float64
15	FuzzBase      float64 // ball radii
16	FuzzPower     float64
17	MaxContact    float64 // ball radii
18}
source

Params are the constants a game may change (penalty.Config, in SI units). DefaultParams are the browser engine's.

type Plan

struct
1type Plan struct {
2	Raw       [4]uint16
3	Mode      int
4	Direction float64 // degrees: 0 = along the line to the taker's right, 180 = left
5	Speed     float64 // m/s
6	Jump      float64 // m/s
7	Reaction  float64 // s
8}
source

Plan is a keeper plan decoded from its four uint16.

type Result

struct
 1type Result struct {
 2	Outcome     int
 3	DecidedStep int     // the 1 kHz step it was decided in
 4	DecidedAt   float64 // s after contact
 5	Launch      Launch
 6	Touch       int // first part to touch the ball, -1 for none
 7	TouchStep   int
 8	Woodwork    int // first frame part it hit, 0 for none
 9	Caught      bool
10	Pounced     bool // decided by the keeper pouncing on a loose ball
11	Contacts    []Contact
12	Commits     []Commit
13	Misread     [4]float64 // the keeper's four normal draws (x, y, vx, jump)
14	// Where the ball's centre first reached the goal line (rounded to the
15	// millimetre, as the browser reports it), if it did.
16	LineCross           bool
17	LineT, LineX, LineY float64
18	// Where it was when the whole ball was over the whole line, if it was.
19	Crossing               bool
20	CrossT, CrossX, CrossY float64
21	EndX, EndY             float64 // the ball when the kick was decided, m
22	Steps                  int
23	Trace                  uint32 // see Options.Trace
24}
source

Result is a decided kick.

type Shot

struct
1type Shot struct {
2	AimX, AimY         float64 // m, point on the goal plane the swing heads for
3	ContactX, ContactY float64 // ball radii
4	Power              float64 // 0..1
5	Mishit             [24]byte
6	HasMishit          bool
7}
source

Shot is the taker's input in the browser engine's units.

Dependencies

Imports 2

/p/g1lnkytfqcjwllws63gvf0mv9yt04aswy4y9amhm/penalty/physics/v0

Imported by indexer

Source Files 6