Playground
config.gno
// Package penalty holds everything about a penalty kick that is pure
// computation: the constants a game is played with, the ten parameters of a
// kick, how 32 bytes of entropy map onto them, the shootout rules, and
// SimulateShot.
//
// It has no state and no realm dependencies, so every version of the game
// realm agrees on these types, and a client can run the same code to check a
// result. All quantities are integers: millimetres, mm/s, milliseconds,
// per-mille (0..1000) and milli-radii (thousandths of the ball's radius), so
// the outcome is identical on every node.
package penalty
import (
"errors"
"strconv"
"strings"
)
// Config is the set of keeper and ball constants a game is created with.
type Config struct {
GoalWidth int64 // inside width, mm
GoalHeight int64 // inside height, mm
KeeperScale int64 // keeper size relative to a ~1.85 m keeper, per-mille
ReactionMin int64 // keeper reaction delay range, ms
ReactionMax int64
StarShare int64 // share of the keeper's speed range that means "star jump", per-mille
ReadShare int64 // share that means "wait and read the shot", per-mille
DiveMin int64 // committed dive speed range, mm/s
DiveMax int64
JumpMin int64 // keeper vertical launch speed range, mm/s (negative = collapse low)
JumpMax int64
BallMinSpeed int64 // ball speed at 0% power, mm/s
BallMaxSpeed int64 // ball speed at 100% power, mm/s
FuzzBase int64 // std-dev of the mishit at 0% power, milli-radii
FuzzPower int64 // extra std-dev at 100% power, milli-radii
MaxContact int64 // farthest contact offset a taker may choose, milli-radii
}
// DefaultConfig returns the constants the reference simulation is tuned for.
func DefaultConfig() Config {
return Config{
GoalWidth: 6555,
GoalHeight: 2424,
KeeperScale: 1176,
ReactionMin: 20,
ReactionMax: 120,
StarShare: 60,
ReadShare: 240, // as the browser engine (PLAN.READ_SHARE)
DiveMin: 2600,
DiveMax: 5200,
JumpMin: -1400,
JumpMax: 4000,
BallMinSpeed: 10000,
BallMaxSpeed: 34000,
FuzzBase: 30,
FuzzPower: 100,
MaxContact: 500,
}
}
type bound struct {
name string
lo, hi int64
}
// The range each constant may be set to, so a game cannot be created with
// physics the simulation was never meant to handle. Order matches field().
var bounds = []bound{
{"goalWidth", 5000, 7320},
{"goalHeight", 1800, 2440},
{"keeperScale", 900, 1300},
{"reactionMin", 0, 300},
{"reactionMax", 0, 400},
{"starShare", 0, 300},
{"readShare", 0, 700},
{"diveMin", 1500, 7000},
{"diveMax", 1500, 7000},
{"jumpMin", -2500, 0},
{"jumpMax", 0, 5000},
{"ballMinSpeed", 5000, 40000},
{"ballMaxSpeed", 5000, 40000},
{"fuzzBase", 0, 150},
{"fuzzPower", 0, 300},
{"maxContact", 200, 800},
}
func (c *Config) field(i int) *int64 {
switch i {
case 0:
return &c.GoalWidth
case 1:
return &c.GoalHeight
case 2:
return &c.KeeperScale
case 3:
return &c.ReactionMin
case 4:
return &c.ReactionMax
case 5:
return &c.StarShare
case 6:
return &c.ReadShare
case 7:
return &c.DiveMin
case 8:
return &c.DiveMax
case 9:
return &c.JumpMin
case 10:
return &c.JumpMax
case 11:
return &c.BallMinSpeed
case 12:
return &c.BallMaxSpeed
case 13:
return &c.FuzzBase
case 14:
return &c.FuzzPower
case 15:
return &c.MaxContact
}
panic("penalty: no config field " + strconv.Itoa(i))
}
var (
ErrConfigRange = errors.New("penalty: config value out of range")
ErrConfigOrder = errors.New("penalty: config range is inverted")
ErrConfigShares = errors.New("penalty: starShare + readShare must not exceed 900")
ErrConfigUnknown = errors.New("penalty: unknown config key")
ErrConfigSyntax = errors.New("penalty: config must be key=value pairs separated by commas")
)
// Validate checks every constant against its allowed range.
func (c Config) Validate() error {
for i, b := range bounds {
v := *c.field(i)
if v < b.lo || v > b.hi {
return errors.New(ErrConfigRange.Error() + ": " + b.name + "=" + strconv.FormatInt(v, 10) +
" (allowed " + strconv.FormatInt(b.lo, 10) + ".." + strconv.FormatInt(b.hi, 10) + ")")
}
}
if c.ReactionMin > c.ReactionMax || c.DiveMin > c.DiveMax ||
c.JumpMin > c.JumpMax || c.BallMinSpeed > c.BallMaxSpeed {
return ErrConfigOrder
}
if c.StarShare+c.ReadShare > 900 {
return ErrConfigShares
}
return nil
}
// ParseConfig applies "key=value,key=value" overrides to DefaultConfig and
// validates the result. An empty string gives the defaults. Keys are the
// lower-camel names String prints, e.g. "goalWidth=6400,reactionMax=150".
func ParseConfig(s string) (Config, error) {
c := DefaultConfig()
s = strings.TrimSpace(s)
if s != "" {
for _, kv := range strings.Split(s, ",") {
parts := strings.Split(strings.TrimSpace(kv), "=")
if len(parts) != 2 {
return Config{}, ErrConfigSyntax
}
key := strings.TrimSpace(parts[0])
v, err := strconv.ParseInt(strings.TrimSpace(parts[1]), 10, 64)
if err != nil {
return Config{}, ErrConfigSyntax
}
found := false
for i, b := range bounds {
if b.name == key {
*c.field(i) = v
found = true
break
}
}
if !found {
return Config{}, errors.New(ErrConfigUnknown.Error() + ": " + key)
}
}
}
if err := c.Validate(); err != nil {
return Config{}, err
}
return c, nil
}
// String prints the config in the form ParseConfig accepts.
func (c Config) String() string {
var b strings.Builder
for i, bd := range bounds {
if i > 0 {
b.WriteString(",")
}
b.WriteString(bd.name + "=" + strconv.FormatInt(*c.field(i), 10))
}
return b.String()
}
gnomod.toml
module = "gno.land/p/g1lnkytfqcjwllws63gvf0mv9yt04aswy4y9amhm/penalty/v0" gno = "0.9" [addpkg] creator = "g1lnkytfqcjwllws63gvf0mv9yt04aswy4y9amhm" height = 163379 max_deposit = "100000000ugnot"
params.gno
package penalty
import (
"errors"
"strconv"
)
const (
BallRadius = 110 // mm
PostRadius = 60 // mm
Distance = 11000 // penalty spot to goal line, mm
Gravity = 9810 // mm/s²
AimMaxX = 6000 // the aim point must lie within ±6 m of the goal centre
AimMaxY = 4000 // and between the grass and 4 m up
)
// ShotInput is what a taker chooses: the five numbers a player sends.
type ShotInput struct {
AimX int64 // point on the goal plane the swing heads for, mm from the centre (+ = taker's right)
AimY int64 // its height, mm
ContactX int64 // where the boot meets the ball, milli-radii from its centre (+ = right)
ContactY int64 // milli-radii (+ = above centre)
Power int64 // per-mille
}
// ShotParams is a complete kick: the taker's five choices plus the 24-byte
// mishit seed that decides how far the boot lands from the chosen contact.
// These six, with a keeper's four, are the ten inputs of SimulateShot.
type ShotParams struct {
AimX int64
AimY int64
ContactX int64
ContactY int64
Power int64
Mishit [24]byte
}
// KeeperPlan is the keeper's commitment: four uint16 values that DecodePlan
// maps onto a dive using the game's Config.
type KeeperPlan struct {
Direction uint16
Speed uint16
Jump uint16
Reaction uint16
}
var ErrShotRange = errors.New("penalty: shot parameter out of range")
// Validate checks a taker's choices against the game's constants.
func (s ShotInput) Validate(c Config) error {
if s.AimX < -AimMaxX || s.AimX > AimMaxX {
return errors.New(ErrShotRange.Error() + ": aimX must be within ±" + strconv.Itoa(AimMaxX) + " mm")
}
if s.AimY < 0 || s.AimY > AimMaxY {
return errors.New(ErrShotRange.Error() + ": aimY must be within 0.." + strconv.Itoa(AimMaxY) + " mm")
}
if s.ContactX*s.ContactX+s.ContactY*s.ContactY > c.MaxContact*c.MaxContact {
return errors.New(ErrShotRange.Error() + ": contact offset must be within " +
strconv.FormatInt(c.MaxContact, 10) + " milli-radii of the centre")
}
if s.Power < 0 || s.Power > 1000 {
return errors.New(ErrShotRange.Error() + ": power must be within 0..1000")
}
return nil
}
// WithMishit completes a taker's choices with a mishit seed.
func (s ShotInput) WithMishit(m [24]byte) ShotParams {
return ShotParams{AimX: s.AimX, AimY: s.AimY, ContactX: s.ContactX, ContactY: s.ContactY, Power: s.Power, Mishit: m}
}
// Input returns the taker's five choices.
func (s ShotParams) Input() ShotInput {
return ShotInput{AimX: s.AimX, AimY: s.AimY, ContactX: s.ContactX, ContactY: s.ContactY, Power: s.Power}
}
func (s ShotInput) String() string {
return "aim=(" + strconv.FormatInt(s.AimX, 10) + "," + strconv.FormatInt(s.AimY, 10) + ")mm contact=(" +
strconv.FormatInt(s.ContactX, 10) + "," + strconv.FormatInt(s.ContactY, 10) + ")mR power=" +
strconv.FormatInt(s.Power, 10) + "‰"
}
func (p KeeperPlan) String() string {
return "plan=(" + strconv.Itoa(int(p.Direction)) + "," + strconv.Itoa(int(p.Speed)) + "," +
strconv.Itoa(int(p.Jump)) + "," + strconv.Itoa(int(p.Reaction)) + ")"
}
plan.gno
package penalty
// Mode is what kind of move a keeper plan describes.
type Mode uint8
const (
ModeStar Mode = iota + 1 // spread into a star jump
ModeRead // hold and react to the shot
ModeDive // commit to a dive
)
func (m Mode) String() string {
switch m {
case ModeStar:
return "star jump"
case ModeRead:
return "wait and read"
case ModeDive:
return "committed dive"
}
return "unknown"
}
// Plan is a KeeperPlan decoded with a game's constants.
type Plan struct {
Mode Mode
Heading int64 // deci-degrees: 0 = along the line to the taker's right, 1800 = to the left, 900 = straight out
Speed int64 // mm/s along the ground (0 for a read)
Jump int64 // mm/s upwards (negative = collapse low)
Reaction int64 // ms after contact before moving
}
// Dive headings stay within ForwardMax of the line, except for the middle
// CentreShare of the direction range, which sweeps the headings in between.
const (
ForwardMax = 220 // deci-degrees
CentreShare = 60 // per-mille of the direction range
StarMaxSpd = 1150
)
// DecodePlan maps the four uint16 of a keeper plan onto a move:
//
// direction monotonic 0..65535 -> heading 0°..180°
// speed lowest StarShare -> star jump, next ReadShare -> wait and read,
// the rest -> dive at DiveMin..DiveMax
// jump JumpMin..JumpMax
// reaction ReactionMin..ReactionMax
//
// For a read plan the direction and jump are unused: the keeper decides them
// from the ball.
func DecodePlan(p KeeperPlan, c Config) Plan {
out := Plan{
Heading: heading(p.Direction),
Jump: span(p.Jump, c.JumpMin, c.JumpMax),
Reaction: span(p.Reaction, c.ReactionMin, c.ReactionMax),
}
u := int64(p.Speed)
starEdge := 65535 * c.StarShare / 1000
readEdge := 65535 * (c.StarShare + c.ReadShare) / 1000
switch {
case u < starEdge:
out.Mode = ModeStar
out.Speed = StarMaxSpd * u / starEdge
case u < readEdge:
out.Mode = ModeRead
default:
out.Mode = ModeDive
out.Speed = c.DiveMin + (c.DiveMax-c.DiveMin)*(u-readEdge)/maxI(1, 65535-readEdge)
}
return out
}
func heading(d uint16) int64 {
s := 2*int64(d) - 65535 // -65535 (right) .. 65535 (left)
c := int64(65535 * CentreShare / 1000)
switch {
case s <= -c:
return ForwardMax * (65535 + s) / (65535 - c)
case s >= c:
return 1800 - ForwardMax*(65535-s)/(65535-c)
}
return 900 + (900-ForwardMax)*s/c
}
// cosPermille approximates cos(heading) × 1000 (Bhaskara I), heading in
// deci-degrees within 0..1800. Integer-only, accurate to about 0.2%.
func cosPermille(h int64) int64 {
sign := int64(1)
if h > 900 {
h = 1800 - h
sign = -1
}
d2 := h * h // (deci-degrees)²
return sign * 1000 * (3240000 - 4*d2) / (3240000 + d2)
}
func maxI(a, b int64) int64 {
if a > b {
return a
}
return b
}
func minI(a, b int64) int64 {
if a < b {
return a
}
return b
}
func absI(a int64) int64 {
if a < 0 {
return -a
}
return a
}
func clampI(x, lo, hi int64) int64 {
if x < lo {
return lo
}
if x > hi {
return hi
}
return x
}
seed.gno
package penalty
// Seed is the 32 bytes of entropy that complete a kick.
//
// When the player shoots, the seed supplies the computer's keeper and the
// player's mishit:
//
// bytes 0-7 keeper plan: four big-endian uint16 (direction, speed, jump, reaction)
// bytes 8-31 mishit seed (24 bytes)
//
// When the player keeps, the seed supplies the computer's whole kick:
//
// bytes 0-1 aim x uint16 -> ±(GoalWidth/2 - ChainAimInset) mm
// bytes 2-3 aim y uint16 -> ChainAimMinY .. GoalHeight + ChainAimOverY mm
// bytes 4-5 power uint16 -> ChainPowerMin .. 1000 per-mille
// byte 6 contact x int8 -> ±ChainContact milli-radii
// byte 7 contact y int8 -> ±ChainContact milli-radii
// bytes 8-31 mishit seed (24 bytes)
//
// So the layout is the same either way: the first eight bytes are "the
// computer's move", the last twenty-four are the mishit.
type Seed [32]byte
// How the computer takes its kicks: inside the frame, aimed a little high to
// allow for the drop, struck with at least ChainPowerMin.
const (
ChainAimInset = 250 // mm inside each post
ChainAimMinY = 300 // mm
ChainAimOverY = 200 // mm above the bar at most
ChainPowerMin = 450 // per-mille
ChainContact = 350 // milli-radii
)
func u16(b []byte) uint16 { return uint16(b[0])<<8 | uint16(b[1]) }
// span maps a uint16 linearly onto lo..hi.
func span(u uint16, lo, hi int64) int64 { return lo + (hi-lo)*int64(u)/65535 }
// KeeperPlan reads the computer's keeper plan from bytes 0-7.
func (s Seed) KeeperPlan() KeeperPlan {
return KeeperPlan{
Direction: u16(s[0:2]),
Speed: u16(s[2:4]),
Jump: u16(s[4:6]),
Reaction: u16(s[6:8]),
}
}
// Mishit returns bytes 8-31.
func (s Seed) Mishit() [24]byte {
var m [24]byte
copy(m[:], s[8:32])
return m
}
// ChainShot reads the computer's kick from bytes 0-7 (see Seed).
func (s Seed) ChainShot(c Config) ShotInput {
halfW := c.GoalWidth/2 - ChainAimInset
in := ShotInput{
AimX: span(u16(s[0:2]), -halfW, halfW),
AimY: span(u16(s[2:4]), ChainAimMinY, c.GoalHeight+ChainAimOverY),
Power: span(u16(s[4:6]), ChainPowerMin, 1000),
ContactX: (int64(s[6]) - 128) * ChainContact / 128,
ContactY: (int64(s[7]) - 128) * ChainContact / 128,
}
// Keep the contact inside this game's selectable disc.
r2 := in.ContactX*in.ContactX + in.ContactY*in.ContactY
if m := c.MaxContact; r2 > m*m {
r := isqrt(r2)
in.ContactX = in.ContactX * m / r
in.ContactY = in.ContactY * m / r
}
return in
}
const hexDigits = "0123456789abcdef"
// Hex prints the seed as 64 hex characters.
func (s Seed) Hex() string { return toHex(s[:]) }
func toHex(b []byte) string {
out := make([]byte, len(b)*2)
for i, v := range b {
out[2*i] = hexDigits[v>>4]
out[2*i+1] = hexDigits[v&15]
}
return string(out)
}
// MishitHex prints a mishit seed as 48 hex characters.
func MishitHex(m [24]byte) string { return toHex(m[:]) }
// ParseMishitHex reads 48 hex characters.
func ParseMishitHex(s string) ([24]byte, bool) {
var m [24]byte
if len(s) != 48 {
return m, false
}
for i := 0; i < 24; i++ {
hi, ok1 := hexVal(s[2*i])
lo, ok2 := hexVal(s[2*i+1])
if !ok1 || !ok2 {
return m, false
}
m[i] = hi<<4 | lo
}
return m, true
}
func hexVal(c byte) (byte, bool) {
switch {
case c >= '0' && c <= '9':
return c - '0', true
case c >= 'a' && c <= 'f':
return c - 'a' + 10, true
case c >= 'A' && c <= 'F':
return c - 'A' + 10, true
}
return 0, false
}
// isqrt is the integer square root (floor).
func isqrt(n int64) int64 {
if n <= 0 {
return 0
}
x := n
y := (x + 1) / 2
for y < x {
x = y
y = (x + n/x) / 2
}
return x
}
shootout.gno
package penalty
// Side is who takes a kick.
type Side uint8
const (
SidePlayer Side = iota + 1
SideChain
)
func (s Side) String() string {
switch s {
case SidePlayer:
return "player"
case SideChain:
return "chain"
}
return "none"
}
// Other returns the opposing side.
func (s Side) Other() Side {
if s == SidePlayer {
return SideChain
}
return SidePlayer
}
// RegulationKicks is how many kicks each side takes before sudden death.
const RegulationKicks = 5
// Shootout is the score of a penalty shootout in which the player always
// kicks first in each round:
//
// - each side takes RegulationKicks kicks, alternating;
// - it ends early as soon as one side cannot be caught with the kicks the
// other has left;
// - level after regulation, it goes to sudden death: rounds of one kick
// each, decided when one side scores and the other does not.
type Shootout struct {
PlayerKicks int
PlayerGoals int
ChainKicks int
ChainGoals int
}
// Next returns who kicks next (SidePlayer at the start of every round).
func (s Shootout) Next() Side {
if s.PlayerKicks == s.ChainKicks {
return SidePlayer
}
return SideChain
}
// Round is the 1-based number of the round in progress.
func (s Shootout) Round() int { return s.ChainKicks + 1 }
// SuddenDeath reports whether regulation is over.
func (s Shootout) SuddenDeath() bool { return s.ChainKicks >= RegulationKicks }
// Record adds a kick for side. It panics if side is out of turn or the
// shootout is already decided.
func (s *Shootout) Record(side Side, scored bool) {
if s.Winner() != 0 {
panic("penalty: the shootout is already decided")
}
if side != s.Next() {
panic("penalty: " + side.String() + " is kicking out of turn")
}
g := 0
if scored {
g = 1
}
if side == SidePlayer {
s.PlayerKicks++
s.PlayerGoals += g
} else {
s.ChainKicks++
s.ChainGoals += g
}
}
// Winner returns the side that has won, or 0 while undecided.
func (s Shootout) Winner() Side {
if s.PlayerKicks <= RegulationKicks && s.ChainKicks <= RegulationKicks {
playerLeft := RegulationKicks - s.PlayerKicks
chainLeft := RegulationKicks - s.ChainKicks
if s.PlayerGoals > s.ChainGoals+chainLeft {
return SidePlayer
}
if s.ChainGoals > s.PlayerGoals+playerLeft {
return SideChain
}
return 0
}
// Sudden death: decided only once both have kicked in the round.
if s.PlayerKicks == s.ChainKicks && s.PlayerGoals != s.ChainGoals {
if s.PlayerGoals > s.ChainGoals {
return SidePlayer
}
return SideChain
}
return 0
}
simulate.gno
package penalty
// Outcome of a single kick.
type Outcome uint8
const (
OutcomeGoal Outcome = iota + 1
OutcomeSave
OutcomeMiss
OutcomePost
)
func (o Outcome) String() string {
switch o {
case OutcomeGoal:
return "goal"
case OutcomeSave:
return "save"
case OutcomeMiss:
return "miss"
case OutcomePost:
return "woodwork"
}
return "unknown"
}
// Scored reports whether the kick counts as a goal.
func (o Outcome) Scored() bool { return o == OutcomeGoal }
// Result is what SimulateShot reports.
type Result struct {
Outcome Outcome
X, Y int64 // where the ball crosses (or would cross) the goal line, mm
ArrivalMS int64 // time from contact to the line
BallSpeed int64 // mm/s
MishitX int64 // contact error the mishit seed added, milli-radii
MishitY int64
Keeper Mode
}
// SimulateShot decides a kick from its ten inputs: the taker's six (five
// choices plus the mishit seed) and the keeper's four, played with the
// game's constants. It is a pure function: the same inputs give the same
// Result on every node, so anyone can re-run it to check a recorded kick.
//
// SUPERSEDED. This is the coarse integer model the realm used before the
// physics engine was ported (gno.land/p/g1lnkytfqcjwllws63gvf0mv9yt04aswy4y9amhm/penalty/physics/v0, which
// matches the browser game bit for bit and is what impl/v1 calls). It is kept
// so that kicks recorded under it can still be re-run.
func SimulateShot(shot ShotParams, plan KeeperPlan, c Config) Result {
power := clampI(shot.Power, 0, 1000)
// The boot lands off the chosen contact by a seeded, power-dependent error.
sigma := c.FuzzBase + c.FuzzPower*power/1000
mx := normalPermille(shot.Mishit, 0) * sigma / 1000
my := normalPermille(shot.Mishit, 12) * sigma / 1000
cx := clampI(shot.ContactX+mx, -800, 800)
cy := clampI(shot.ContactY+my, -800, 800)
// Glancing contact loses pace: about 1 - r²/2 of a centred strike.
eff := 1000 - (cx*cx+cy*cy)*225/1000000
speed := (c.BallMinSpeed + (c.BallMaxSpeed-c.BallMinSpeed)*power/1000) * eff / 1000
t := Distance * 1000 / speed // ms to the line
// Striking the right side sends the ball left and curls it further left;
// hitting below centre lifts it, above centre dips it; gravity drops it.
x := shot.AimX - cx*CurlPerMilliR/10
drop := Gravity * t * t / 2 / 1000000
y := shot.AimY - drop - cy*LiftPerMilliR/10
if y < BallRadius {
y = BallRadius
}
d := DecodePlan(plan, c)
res := Result{X: x, Y: y, ArrivalMS: t, BallSpeed: speed, MishitX: mx, MishitY: my, Keeper: d.Mode}
halfW := c.GoalWidth / 2
ax := absI(x)
inside := ax <= halfW-BallRadius && y <= c.GoalHeight-BallRadius
clear := ax >= halfW+2*PostRadius+BallRadius || y >= c.GoalHeight+2*PostRadius+BallRadius
switch {
case clear:
res.Outcome = OutcomeMiss
case !inside:
res.Outcome = OutcomePost
case keeperCovers(d, c, shot, x, y, t, cx):
res.Outcome = OutcomeSave
default:
res.Outcome = OutcomeGoal
}
return res
}
const (
CurlPerMilliR = 45 // tenths of a mm of sideways travel per milli-radius of side contact
LiftPerMilliR = 28 // tenths of a mm of lift per milli-radius below centre
LaunchShare = 20 // tenths of a mm of that sideways travel visible in the launch direction
)
// keeperCovers is the placeholder keeper: whether its body and hands reach
// (x, y) by the time the ball arrives (t ms after contact).
func keeperCovers(d Plan, c Config, shot ShotParams, x, y, t, cx int64) bool {
s := c.KeeperScale
reach := 900 * s / 1000 // hips to fingertips, sideways
switch d.Mode {
case ModeStar:
// Spread wide in the middle of the goal, off the ground.
return absI(x) <= 1100*s/1000 && y >= 450*s/1000
case ModeRead:
// Commits after seeing the ball: the slower the shot, the further it
// gets. It reads the launch line, not the curl.
commit := 160 + d.Reaction
avail := t - commit
if avail <= 0 {
return absI(x) <= 350*s/1000 && y <= 1800*s/1000
}
predicted := shot.AimX - cx*LaunchShare/10
cover := minI(reach+3500*avail/1000, c.GoalWidth/2+200)
return absI(predicted) <= cover && absI(x-predicted) <= 450*s/1000
}
// Committed dive: the hips travel along the heading once the push-off
// starts, the hands reach out from there, and the jump sets the height
// band it covers.
moving := t - d.Reaction - 60
if moving < 0 {
moving = 0
}
vx := d.Speed * cosPermille(d.Heading) / 1000
hipX := clampI(vx*moving/1000, -2600*s/1000, 2600*s/1000)
if absI(x) <= 300 && moving < 150 {
return true // straight at a keeper that has barely left the spot
}
centre := 900 + d.Jump*450/1000
band := 650 * s / 1000
return absI(x-hipX) <= reach+150 && y >= centre-band && y <= centre+band
}
// normalPermille turns 12 bytes of a mishit seed into an approximately
// standard-normal value × 1000: six uint16 uniforms summed (Irwin-Hall,
// n = 6), centred and scaled.
func normalPermille(m [24]byte, offset int) int64 {
var sum int64
for i := 0; i < 6; i++ {
sum += int64(u16(m[offset+2*i : offset+2*i+2]))
}
return (sum - 3*65535) * 1414 / 65535
}