Search Apps Documentation Source Content File Folder Download Copy Actions Download State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

course source pure

Package course is what golf and a hole agree on: a hole as data (Simple, GG1), its weather, and how a stroke is launc...

Overview

Package course is what golf and a hole agree on: a hole as data (Simple, GG1), its weather, and how a stroke is launched and drops.

Constants 8

const Clear, Wind, Rain, Fog, Storm, Snow

1const (
2	Clear = ""      // Clear is no weather at all
3	Wind  = "wind"  // Wind is a Slope: a steady push, Vec per substep
4	Rain  = "rain"  // Rain is a Surface a little quicker than dry grass
5	Fog   = "fog"   // Fog is a Surface of scale 1: it only hides the far end
6	Storm = "storm" // Storm is rain and wind in gusts, and lightning to look at
7	Snow  = "snow"  // Snow is a Surface a little slower
8)
source

The weather kinds. Each but Clear is also the skin of its whole-board zones.

const WindMin, WindMax, RainScale, WetIce, SnowScale

 1const (
 2	// WindMin is the weakest wind, per substep.
 3	WindMin = 0.08
 4	// WindMax is the strongest wind, per substep.
 5	WindMax = 0.15
 6	// RainScale is how much quicker the green is in the rain: a touch, not
 7	// ice (much more and every board turns to pinball).
 8	RainScale = 1.025
 9	// WetIce is how much quicker again the rain makes ice.
10	WetIce = 1.06
11	// SnowScale is how much slower the green is in the snow.
12	SnowScale = 0.9
13)
source

The weather's strengths.

const BoardW, BoardH

1const BoardW, BoardH = 32, 16
source

BoardW and BoardH are the board author.Fit gives a hole declared without W and H, in board units (nothing deployed reads them: Decode holds W and H to 1..MaxBoard).

const Kick

1const Kick = 0.79
source

Kick turns a stroke's power (0 to 10) into the ball's speed per substep, Kick·p^(3/4), so the roll (v²/2a) grows as p^(3/2). A full stroke rolls 44 on the usual green, a board's length. Calibrated to keep every hole's par.

const Magic

1const Magic = "GG1"
source

Magic starts GG1, a hole as one little-endian binary string, frozen with this package: magic, header, field, skin table (str = u8 len + bytes), walls (style runs, then segments and, outside pulses, their Lengths), posts, zones, pulses; each list a count first. Encode is the layout.

const MaxBoard

1const MaxBoard = 96
source

MaxBoard is the longest side a board may have: it bounds the text board and the flood a client runs.

const WearW, WearH

1const WearW, WearH = 16, 8
source

WearW and WearH are the wear grid, stretched over any board: 128 counters.

Functions 15

func Capture

1func Capture(cup, ball, off float64) float64
source

Capture is the fastest a ball of radius ball crossing a cup of radius cup, off its centre by off, can go and still drop, in board units per substep; 0 when it cannot drop at all. Holmes's criterion (Am. J. Phys. 59, 1991): (2·sqrt(R² − b²) − r) · sqrt(G / 2r).

func Encode

1func Encode(h *Simple) string
source

Encode is the hole as GG1. It stores what it is given: call it on a hole after Fit, with its walls prepared.

func Exact

1func Exact(h *Simple) bool
source

Exact reports whether a decoded hole's stored lengths are its walls' own, its prep bit for bit the one Prepare works out. Use it on a value fresh from Decode: it prepares a copy of the field, which can panic on a hole stored in another realm (the copy keeps that realm's read-only mark).

func IsWorld

1func IsWorld(w string) bool
source

IsWorld is whether w can name a world: 1 to MaxWorld letters a-z, as Decode holds data to.

func Launch

1func Launch(angle, power float64) physics.Vec2
source

Launch is the ball's starting velocity for a stroke. Every hole should use it, so that the same pull means the same shot on every course.

func Sink

1func Sink(shot physics.Shot, pin physics.Vec2, radius, ball float64) (physics.Shot, bool)
source

Sink decides whether a shot ends in the cup: it stops within radius of the pin, or crosses the cup no faster than Capture allows a ball of radius ball. When it drops, the path is cut there and ends on the pin.

func WearIndexOn

1func WearIndexOn(p physics.Vec2, w, h int) int
source

WearIndexOn maps a position on a w x h board to its wear cell, clamped.

func WeatherFor

1func WeatherFor(kind string, h *Simple, seed uint64) (physics.Vec2, []physics.Zone)
source

WeatherFor is the wind and zones of one kind of weather on a hole, drawn from seed: the wind's side and strength, where the rain leaves its puddles.

func WithExtras

1func WithExtras(f *physics.Field, walls []physics.Wall, posts []physics.Post) *physics.Field
source

WithExtras is the field plus one stroke's pieces, the hole's own left as is. It may return f itself: do not mutate what it returns.

func WithWeather

1func WithWeather(f *physics.Field, weather []physics.Zone) *physics.Field
source

WithWeather lays weather over a field: the sky's whole-board zones go under its own (the sand stays sand in the rain), puddles and wet ice over them. It may return f itself: do not mutate what it returns.

func WithZones

1func WithZones(f *physics.Field, zones []physics.Zone) *physics.Field
source

WithZones is the field with zones put first (a puddle over the sand is the puddle). It may return f itself: do not mutate what it returns.

func WorstForecastWork

1func WorstForecastWork(h *Simple) int
source

WorstForecastWork bounds the Work of h's forecast in any period and world: a storm's, whose puddle tries all fail, each after dryLand has tested every piece (a try that fails sooner costs less, and one that places a puddle ends them sooner). Golf refuses a hole whose worst forecast leaves a commit no room for its heaviest shot.

func ForecastFor

1func ForecastFor(id, world string, h *Simple, period int64) Forecast
source

ForecastFor is the weather of hole id (in world) for a period: a hash of the two looked up in the world's climate. Nobody picks it.

func Decode

1func Decode(s string) (*Simple, error)
source

Decode reads a GG1 hole; anything outside the format, its limits or its value bounds is an error, with nothing returned. It prepares the walls from the stored lengths (physics.PrepareWith) and trusts them: check them once with Exact, or use DecodeChecked, before accepting data from anyone.

func DecodeChecked

1func DecodeChecked(s string) (*Simple, error)
source

DecodeChecked is Decode, then Exact: for data anyone wrote. It costs a Prepare more; data once checked can be read back with Decode.

Types 3

type Forecast

struct
1type Forecast struct {
2	Period int64
3	Kind   string
4	Wind   physics.Vec2
5	Zones  []physics.Zone
6	// Work is what drawing it cost, in physics.MaxWork's units (about a
7	// thousand gas); golf counts it in a commit's budget.
8	Work int
9}
source

Forecast is one hole's weather for one period. Whole-board zones lie under the hole's own; the rest (puddles, wet ice) lie over it.

type Pulse

struct
1type Pulse struct {
2	Every, On, Phase int
3	Walls            []physics.Wall
4	Posts            []physics.Post
5	Zones            []physics.Zone
6}
source

Pulse is pieces that come and go: present on the strokes where (stroke+Phase) % Every < On, a timed wall's rule (physics.There) applied per stroke. The clock is the stroke number in the player's own round (0 is the first shot), never shared between players: previewing shot N and committing it meet the same course.

type Simple

struct
 1type Simple struct {
 2	W, H      int // the board, 1 to MaxBoard a side (Decode holds data to it, author.Fit sets it)
 3	Title     string
 4	Strokes   int // par: the strokes a good round takes (0 means 3)
 5	Tee, Pin  physics.Vec2
 6	Course    *physics.Field
 7	Pulses    []Pulse // pieces that come and go with the stroke number
 8	Substeps  int
 9	CupRadius float64
10	// World is the hole's world (1 to MaxWorld letters a-z, as Decode holds
11	// it); Order is its place there, 0 to MaxOrder (a course hole 1 or more).
12	World string
13	Order float64
14	// Shelter caps the wind the hole is played in (0: the world's own).
15	Shelter float64
16}
source

Simple is a hole: its geometry, what Decode gives golf. Fields and methods pair up (Strokes/Par, Tee/Start, Pin/Cup, Course/Field) because a field and a method cannot share a name.

Methods on Simple

func Cup

method on Simple
1func (h *Simple) Cup() physics.Vec2
source

Cup is where the cup is.

func ExtraZones

method on Simple
1func (h *Simple) ExtraZones(stroke int) []physics.Zone
source

ExtraZones is the zones the hole's pulses lay down at a stroke.

func Extras

method on Simple
1func (h *Simple) Extras(stroke int) ([]physics.Wall, []physics.Post)
source

Extras is the walls and posts the hole's pulses add at a stroke.

func Field

method on Simple
1func (h *Simple) Field() *physics.Field
source

Field is the course as the physics sees it.

func Par

method on Simple
1func (h *Simple) Par() int
source

Par is the strokes a good round takes: Strokes, 3 unless it says 1 to 19.

func PreviewWith

method on Simple
1func (h *Simple) PreviewWith(ball physics.Vec2, angle, power float64, stroke, tick int, weather []physics.Zone) (physics.Shot, bool)
source

PreviewWith plays a stroke of a round in some weather, read-only, the timed pieces starting at tick. A pulse piece that came back on the ball pushes it out, never across the hole's own walls. A ball left where the next stroke brings a hazard back returns to where this stroke started, as under a timed hazard (else that hazard would cost a stroke for nothing).

func Start

method on Simple
1func (h *Simple) Start() physics.Vec2
source

Start is the tee.

func Varies

method on Simple
1func (h *Simple) Varies() bool
source

Varies says whether the hole has pulses: pieces that come and go.

Imports 4

Source Files 3