xonecas.ioDon't click! Sean Caetano Martin Sign in

tiny-adventure / commits / 7bea4f1

One RNG, one class table and one item generator, with dead code and endpoints removed

The cleanup deletes 980 lines and adds 480. internal/rng is now the only RNG. sim.Classes now owns base stats and growth, which fixes rangers growing like fighters. Map loot and starting gear come from sim.BuildItem and sim.RollItem. The server now computes the threat edge, and the client copy is gone. The unused /api/ability, /api/combat/log and /api/seed endpoints are removed, along with the enemy archetypes, Describe, the gallery page and four abilities that nothing granted. The HTTP layer now rejects actions after a finished campaign. The scripts import hex.js and stats.js from the game and share serve.sh, and AGENT_BROWSER_HEADED=0 runs them headless. CLAUDE.md now maps the repo. Verified with go vet and go test, bot wins on seeds 1 to 20, a headless verify.sh with 0 failures at 6 resolutions, and a headless playthrough of seed 7 that wins on day 6.

Co-Authored-By: Claude Opus 5.5

sacenox2 days ago7bea4f1c7c2a2d1d8768eb50cbdd3e6fe3c0b1adparent f0f76c670 files changed

This diff is too big to show in full. The first 1000 lines are below, and every file is listed with its counts.

CLAUDE.md+35-4
@@ -1,13 +1,44 @@
11 # Tiny Adventure
22
3-Go server in `cmd/` and `internal/`, Three.js client in `web/`. API in `docs/api.md`.
3+A seeded tabletop campaign: a Go server owns every rule, a Three.js client in `web/` renders it. API in `docs/api.md`, harness in `docs/verification.md`, player-facing rules in `README.md`.
4+
5+## Layout
6+
7+- `cmd/server`: flags and boot.
8+- `internal/model`: wire and state types only. No logic beyond tiny helpers.
9+- `internal/rng`: the one RNG (`math/rand/v2` PCG), `Sub(seed, tag)` streams, `Pick`, `Shuffled`, `Between`, six-digit `NewSeed`.
10+- `internal/world`: hex math, noise, terrain bytes, pathfinding.
11+- `internal/gen`: builds a `World` from a seed: terrain, factions, POIs, spawns, bands, loot, landmarks, missions, party, encounters.
12+- `internal/sim`: game rules that are pure functions: classes and growth, abilities, items (`BuildItem`, `RollItem`), traits and `EdgeOf`, combat, `Forecast` odds, XP.
13+- `internal/server`: HTTP and the stateful game: move, bands, hazards, landmarks, clock and camping, shops, threat view, fights.
14+- `web/js`: one concern per file. `main.js` wires the flow. `kit.js` is the canvas-texture UI layer, `frames.js` its widgets, `text.js` fonts and text, `theme.js` colour roles, `layout.js` widget rects. Board and art: `board.js`, `flora.js`, `props.js`, `figures.js`, `minis.js`, `beasts.js`, `sky.js`.
15+- `scripts`: the harness. `serve.sh` starts a server, `driver.mjs` drives the browser, `bot.mjs` is the careful player policy shared by verify and playthrough, `layout.mjs` checks rects.
16+
17+## Commands
18+
19+- Play: `go run ./cmd/server --seed 7`, then open http://localhost:8080.
20+- Check: `go vet ./... && go test ./...`.
21+- Harness: `scripts/verify.sh <outdir> [seed]`, `scripts/playthrough.sh <outdir> <seed>`. `AGENT_BROWSER_HEADED=0` keeps the browser off the desktop. Use it when the user is at the machine.
22+- Frame time: open the game in a normal GPU browser and read `__game.perf()`. The harness uses SwiftShader, so its frame rate means nothing.
423
524 ## Rules
625
726 - No code comments.
8-- All game UI is drawn in Three.js with generated textures from `web/assets`: HUD, panels, buttons, menus, title and end screens, floating numbers. Do not build UI from DOM panels, CSS-styled divs or HTML buttons. The only DOM elements allowed are the canvas and the error fallback.
9-- `window.__game` (`web/js/debug.js`) must keep working after any UI change. It exposes mode, party state, busy flag, `rects()` (UI rects in CSS pixels, each with a name and `essential` flag), `tileScreen(x, y)` and `focusTile(x, y)`. When the UI moves into Three.js, replace the DOM rect provider with `__game.setRects(fn)` returning the real widget rects. The harness reads layout only from there.
10-- Game code changes need `go vet ./... && go test ./...` plus the live harness.
27+- The server decides; the client renders. Odds, wounds, edge, clock, shop stock and every rule live in Go. The client may format and aggregate for display, never re-derive a rule.
28+- One generator per thing: classes, items and abilities live in `sim`, worlds in `gen`, randomness in `rng`. Do not add a second.
29+- All game UI is drawn on canvas textures through `kit.js` and `frames.js`: HUD, panels, buttons, menus, title and end screens, floating numbers. The only DOM elements are the canvas and the `#fatal` fallback.
30+- Text goes through `drawText` with a box height `h`: it centres the cap height in the box. Never place text with magic offsets. MedievalSharp (`display: true`) is for titles, headings, place labels and odds words only; Alegreya with lining numerals is the body. Fonts are vendored in `web/fonts` and load before the first draw.
31+- Colours come from roles in `theme.js`: a grey ramp, one amber accent for state and the primary action, red only for danger. Radius at most 4. No gradients.
32+- `window.__game` (`web/js/debug.js`) must keep working: `mode`, `busy`, `state()`, `rects()` via `setRects`, `tileScreen`, `focusTile`, `pickAt`, `perf()`. The harness reads layout only from `rects()`.
33+- Scripts import `web/js/stats.js` and `web/js/hex.js`; keep those free of browser APIs.
34+- Generated art: the `openrouter` skill can make images when a texture or icon is needed.
35+
36+## Gotchas
37+
38+- Instanced board meshes start with zero matrices, so their bounding spheres are degenerate. Keep `frustumCulled = false` on them.
39+- Defeat ends the campaign. Any harness setup that fights through the API can end the run; pin the seed and check `phase`.
40+- Never kill processes with `pkill -f`; it matches the agent's own shell. Find a server by port: `ss -ltnpH 'sport = :PORT'`.
41+- Seeds above 2^53 lose precision in JS. `rng.NewSeed` stays below a million.
1142
1243 ## Definition of done
1344
cmd/server/main.go+2-2
@@ -5,8 +5,8 @@ import (
55 "log"
66 "net/http"
77
8- "tinyadventure/internal/gen"
98 "tinyadventure/internal/model"
9+ "tinyadventure/internal/rng"
1010 "tinyadventure/internal/server"
1111 )
1212
@@ -17,7 +17,7 @@ func main() {
1717 flag.Parse()
1818 s := model.Seed(*seed)
1919 if *seed == 0 {
20- s = gen.NewSeed()
20+ s = rng.NewSeed()
2121 }
2222 log.Printf("seed %d, listening on %s", s, *addr)
2323 log.Fatal(http.ListenAndServe(*addr, server.New(s, *web)))
docs/api.md+4-36
@@ -4,7 +4,7 @@ All bodies are JSON. Types live in `internal/model`. Single player first: the pl
44
55 Errors return a non-2xx status and `{"error": "message"}` (`ErrorResponse`).
66
7-Every endpoint except `/api/seed` and `/api/combat/log` returns a full `GameState`. `phase` is one of `explore`, `combat`, `victory`, `defeat`.
7+Every endpoint returns a full `GameState`. After victory or defeat every POST except `/api/new` fails with 400. `phase` is one of `explore`, `combat`, `victory`, `defeat`.
88
99 `stats.hp` is a unit's current health. It carries from fight to fight and is capped by `maxHp` plus gear `maxHp` bonuses. Every item has a `value` in gold. `party.potions` counts potions.
1010
@@ -134,14 +134,14 @@ Response: `GameState` with a fresh campaign.
134134 Moves the party toward hex `x,y`. The server paths over walkable hexes and returns the new state. The route avoids uncleared POIs and bands unless they block the only way. The party never walks onto an uncleared POI or band. It stops on the hex before it, and `threat` describes the fight. Every second step, roaming bands move. A band that ends next to the party stops the walk with a `threat`:
135135
136136 ```json
137-{"poi": "poi1", "enemies": [], "odds": 82, "wounds": 35, "barred": false}
137+{"poi": "poi1", "enemies": [], "odds": 82, "wounds": 35, "barred": false, "edge": {"hits": ["fire (Isolde)"], "blunted": []}}
138138 ```
139139
140140 ```json
141-{"band": "band1", "enemies": [], "odds": 64, "wounds": 50}
141+{"band": "band1", "enemies": [], "odds": 64, "wounds": 50, "edge": {"hits": [], "blunted": ["frost (Cael)"]}}
142142 ```
143143
144-`odds` is the percent of 40 simulated fights the party wins as it stands now. `wounds` is the average percent of the party's current health lost in those fights. `barred` is true for the boss until every other main step is done. Start the fight with `POST /api/interact` on the POI or band id. Any other action clears `threat`. Loot on any tile the party walks over is picked up automatically and listed in `found`; key items on a POI tile are picked up when the POI is cleared. Rejected with 400 for …
144+`odds` is the percent of 40 simulated fights the party wins as it stands now. `wounds` is the average percent of the party's current health lost in those fights. `barred` is true for the boss until every other main step is done. `edge` names each hero whose element or pierce hits an enemy weakness, and each whose element the enemies resist. Start the fight with `POST /api/interact` on the POI or band id. Any other action clears `threat`. Loot on any tile the party walks over is picked up automat …
145145
146146 ```json
147147 {"x": 12, "y": 7}
@@ -173,16 +173,6 @@ Equips an inventory item on a unit, or unequips the slot item when `unequip` is
173173
174174 Response: `GameState` with updated `party.units[].gear` and `party.inventory`.
175175
176-## POST /api/ability
177-
178-Assigns an ability to the unit's equipped ability slot, used by auto-combat.
179-
180-```json
181-{"unit": "u1", "ability": "a1", "slot": 0}
182-```
183-
184-Response: `GameState` with updated `party.units[].abilities`.
185-
186176 ## Traders and camping
187177
188178 Traders work at the spawns and at cleared POIs of kind `camp` or `village`. While the party stands on one, `shop` is set:
@@ -221,28 +211,6 @@ Drinks a potion on a hero, anywhere, healing half of their maximum health. Fails
221211 {"unit": "u1"}
222212 ```
223213
224-## GET /api/combat/log
225-
226-Returns the combat log of the latest fight.
227-
228-Response:
229-
230-```json
231-{
232- "log": [
233- {"tick": 1, "actor": "u1", "target": "m1", "ability": "a1", "amount": 3, "crit": false, "killed": false, "text": "Ayla slashes Bat for 3"}
234- ]
235-}
236-```
237-
238-## GET /api/seed
239-
240-Returns the seed and the enabled systems.
241-
242-```json
243-{"seed": 42, "systems": ["factions", "sidequests"]}
244-```
245-
246214 ## Mission templates
247215
248216 A mission is a list of `MissionStep`. Each step has typed `slots` (`poiKind`, `faction`, `item`) filled from the seed, so the `mine`/`vampires`/`key` template becomes `beach`/`lizardfolk`/`key` by changing slot values only.
docs/verification.md+2-2
@@ -10,8 +10,8 @@ scripts/verify.sh <outdir> [seed]
1010
1111 Needs `go`, `node`, `ffmpeg` (for the recording), `python3`, and `agent-browser`. The default seed is 7. The script:
1212
13-1. Builds and starts the server on a free port with `--seed`.
14-2. Opens a headed Chrome on `DISPLAY` (default `:0`) with software WebGL flags, so a window appears on the desktop. Do not touch the desktop while it runs.
13+1. Builds and starts the server on a free port with `--seed`, through `scripts/serve.sh`, which both launchers share.
14+2. Opens Chrome with software WebGL (SwiftShader), so frames are the same on every machine and slow on purpose. By default the window is headed on `DISPLAY` (default `:0`) and appears on the desktop. Do not touch it while it runs. `AGENT_BROWSER_HEADED=0` runs it headless, off the desktop.
1515 3. For each of 1280x720, 1920x1080, 2560x1440, 1366x768, 800x600 and 390x844, resets the campaign to the seed and plays through input only: clicks Begin, presses T at the wagon and clicks a potion, clicks a ground tile, presses I, J and Escape, then clicks the first main POI, clicks Prepare and back, and clicks Fight. Then the careful bot in `scripts/bot.mjs` plays a few steps with real clicks. Setup through the API walks until dusk, the page reloads, and the harness clicks Make camp and checks …
1616 4. Exits non-zero if any assertion failed.
1717
internal/gen/bands.go+3-2
@@ -2,16 +2,17 @@ package gen
22
33 import (
44 "tinyadventure/internal/model"
5+ "tinyadventure/internal/rng"
56 )
67
78 var bandNames = []string{"Patrol", "Warband", "Raiders", "Hunters"}
89
910 func placeBands(p *placer, maxDist int, byPower []model.Faction) []model.Band {
1011 var out []model.Band
11- for _, c := range p.take(between(p.r, 7, 10), 6, func([2]int) bool { return true }) {
12+ for _, c := range p.take(rng.Between(p.r, 7, 10), 6, func([2]int) bool { return true }) {
1213 f := factionAt(byPower, p.progress(c, maxDist), p.r.Float64())
1314 out = append(out, model.Band{
14- Kind: "roam", Name: pick(p.r, bandNames), Faction: f.ID,
15+ Kind: "roam", Name: rng.Pick(p.r, bandNames), Faction: f.ID,
1516 Level: levelAt(p.origin, maxDist, c[0], c[1]), X: c[0], Y: c[1], HomeX: c[0], HomeY: c[1],
1617 })
1718 }
internal/gen/describe.go+0-39
@@ -1,39 +0,0 @@
1-package gen
2-
3-import (
4- "fmt"
5- "strings"
6-)
7-
8-func (w World) Describe() string {
9- var b strings.Builder
10- c := w.Campaign
11- fmt.Fprintf(&b, "seed %d\nsystems: %s\n", c.Seed, strings.Join(c.Systems, ", "))
12- for _, f := range c.Factions {
13- fmt.Fprintf(&b, "faction %s %s theme=%s power=%d\n", f.ID, f.Name, f.Theme, f.Power)
14- }
15- fmt.Fprintf(&b, "main: %s (%s)\n", c.Main.Name, c.Main.Template)
16- for _, s := range c.Main.Steps {
17- fmt.Fprintf(&b, " %s [%s] %s\n", s.ID, s.Kind, s.Text)
18- }
19- for _, q := range c.SideQuests {
20- fmt.Fprintf(&b, "side: %s\n", q.Name)
21- for _, s := range q.Steps {
22- fmt.Fprintf(&b, " %s [%s] %s\n", s.ID, s.Kind, s.Text)
23- }
24- }
25- for _, s := range w.Map.Spawns {
26- fmt.Fprintf(&b, "spawn %s at (%d,%d): %s\n", s.Kind, s.X, s.Y, s.Hint)
27- }
28- for _, p := range w.Map.POIs {
29- fmt.Fprintf(&b, "poi %s %s (%d,%d) faction=%s\n", p.ID, p.Name, p.X, p.Y, p.Faction)
30- }
31- for _, e := range w.Encounters {
32- fmt.Fprintf(&b, "enc %s boss=%v enemies=%d lvl=%d hp=%d\n", e.ID, e.Boss, len(e.Enemies), e.Enemies[len(e.Enemies)-1].Level, e.Enemies[0].Stats.MaxHP)
33- }
34- for _, u := range w.Party.Units {
35- fmt.Fprintf(&b, "hero %s the %s hp=%d atk=%d gear=%d abilities=%d\n", u.Name, u.Class, u.Stats.MaxHP, u.Stats.Attack, len(u.Gear), len(u.Abilities))
36- }
37- fmt.Fprintf(&b, "loot nodes: %d\n", len(w.Map.Loot))
38- return b.String()
39-}
internal/gen/encounters.go+18-17
@@ -2,10 +2,11 @@ package gen
22
33 import (
44 "fmt"
5- "math/rand"
5+ "math/rand/v2"
66 "slices"
77
88 "tinyadventure/internal/model"
9+ "tinyadventure/internal/rng"
910 )
1011
1112 var bossEpithets = []string{"the Pale", "the Unbroken", "the Hungering", "of the Long Night", "the Merciless", "Ironhand"}
@@ -13,18 +14,18 @@ var bossNames = []string{"Valdric", "Sskarra", "Morgath", "Neveth", "Karzul", "Y
1314
1415 func bossName(r *rand.Rand, f model.Faction) string {
1516 d := defOf(f)
16- return fmt.Sprintf("%s %s %s", pick(r, d.titles), pick(r, bossNames), pick(r, bossEpithets))
17+ return fmt.Sprintf("%s %s %s", rng.Pick(r, d.titles), rng.Pick(r, bossNames), rng.Pick(r, bossEpithets))
1718 }
1819
1920 func enemy(r *rand.Rand, id string, l look, f model.Faction, level int, hpMult, atkMult float64) model.Unit {
20- hp := int(float64(hpBase+level*hpGrow+r.Intn(5)) * hpMult)
21+ hp := int(float64(hpBase+level*hpGrow+r.IntN(5)) * hpMult)
2122 n := natures[defOf(f).name]
2223 return model.Unit{
2324 Traits: slices.DeleteFunc(slices.Clone(n.traits), func(t string) bool { return t == "swarm" }), Weak: n.weak, Resist: n.resist,
2425 ID: id, Name: l.name, Race: l.race, Class: l.class, Faction: f.ID, Level: level,
2526 Stats: model.Stats{
2627 HP: hp, MaxHP: hp, Attack: int(float64(atkBase+level*atkGrow/2) * atkMult), Defense: 1 + level/2,
27- Magic: level, Speed: between(r, 3, 7), Crit: 5,
28+ Magic: level, Speed: rng.Between(r, 3, 7), Crit: 5,
2829 },
2930 Abilities: []model.Ability{{ID: "strike", Name: "Strike", Kind: "damage", Power: 1.0, Cooldown: 0, Target: "enemy"}},
3031 }
@@ -36,6 +37,13 @@ const (
3637 swarmHP, swarmAtk = 0.65, 0.8
3738 )
3839
40+func squad(d factionDef, n int) (int, float64, float64) {
41+ if slices.Contains(natures[d.name].traits, "swarm") {
42+ return n + 1, swarmHP, swarmAtk
43+ }
44+ return n, 1, 1
45+}
46+
3947 func buildEncounter(r *rand.Rand, poi model.POI, f model.Faction, level int, boss string) model.Encounter {
4048 d := defOf(f)
4149 e := model.Encounter{ID: "enc-" + poi.ID, POI: poi.ID}
@@ -43,17 +51,13 @@ func buildEncounter(r *rand.Rand, poi model.POI, f model.Faction, level int, bos
4351 e.Boss = true
4452 e.Enemies = append(e.Enemies, enemy(r, e.ID+"-boss", look{boss, d.boss.race, d.boss.class}, f, level+1, bossHP, bossAtk))
4553 }
46- count := between(r, 2, 2+min(2, level/3))
54+ count := rng.Between(r, 2, 2+min(2, level/3))
4755 if boss != "" {
4856 count = 2
4957 }
50- hpMult, atkMult := 1.0, 1.0
51- if slices.Contains(natures[d.name].traits, "swarm") {
52- count++
53- hpMult, atkMult = swarmHP, swarmAtk
54- }
55- for i := 0; i < count; i++ {
56- e.Enemies = append(e.Enemies, enemy(r, fmt.Sprintf("%s-e%d", e.ID, i+1), pick(r, d.minions), f, level, hpMult, atkMult))
58+ count, hpMult, atkMult := squad(d, count)
59+ for i := range count {
60+ e.Enemies = append(e.Enemies, enemy(r, fmt.Sprintf("%s-e%d", e.ID, i+1), rng.Pick(r, d.minions), f, level, hpMult, atkMult))
5761 }
5862 return e
5963 }
@@ -69,12 +73,9 @@ func buildBandEncounter(r *rand.Rand, b model.Band, f model.Faction) model.Encou
6973 return e
7074 }
7175 d := defOf(f)
72- count, hpMult, atkMult := 2, 1.0, 1.0
73- if slices.Contains(natures[d.name].traits, "swarm") {
74- count, hpMult, atkMult = 3, swarmHP, swarmAtk
75- }
76+ count, hpMult, atkMult := squad(d, 2)
7677 for i := range count {
77- e.Enemies = append(e.Enemies, enemy(r, fmt.Sprintf("%s-e%d", e.ID, i+1), pick(r, d.minions), f, b.Level, hpMult, atkMult))
78+ e.Enemies = append(e.Enemies, enemy(r, fmt.Sprintf("%s-e%d", e.ID, i+1), rng.Pick(r, d.minions), f, b.Level, hpMult, atkMult))
7879 }
7980 return e
8081 }
internal/gen/factions.go+4-3
@@ -2,9 +2,10 @@ package gen
22
33 import (
44 "fmt"
5- "math/rand"
5+ "math/rand/v2"
66
77 "tinyadventure/internal/model"
8+ "tinyadventure/internal/rng"
89 )
910
1011 type look struct{ name, race, class string }
@@ -48,10 +49,10 @@ func rollFactions(r *rand.Rand, on bool) []model.Faction {
4849 if !on {
4950 return []model.Faction{factionOf(wildFaction, 0, 3)}
5051 }
51- chosen := shuffled(r, factionPool)[:between(r, 2, 4)]
52+ chosen := rng.Shuffled(r, factionPool)[:rng.Between(r, 2, 4)]
5253 out := make([]model.Faction, len(chosen))
5354 for i, d := range chosen {
54- out[i] = factionOf(d, i, 1+i*2+r.Intn(2))
55+ out[i] = factionOf(d, i, 1+i*2+r.IntN(2))
5556 }
5657 return out
5758 }
internal/gen/gen.go+11-10
@@ -5,6 +5,7 @@ import (
55 "slices"
66
77 "tinyadventure/internal/model"
8+ "tinyadventure/internal/rng"
89 "tinyadventure/internal/world"
910 )
1011
@@ -16,18 +17,18 @@ type World struct {
1617 }
1718
1819 func Generate(seed model.Seed) World {
19- sys := rollSystems(sub(seed, "systems"))
20- factions := rollFactions(sub(seed, "factions"), sys.Factions)
20+ sys := rollSystems(rng.Sub(seed, "systems"))
21+ factions := rollFactions(rng.Sub(seed, "factions"), sys.Factions)
2122 byID := map[string]model.Faction{}
2223 for _, f := range factions {
2324 byID[f.ID] = f
2425 }
2526
26- lr := sub(seed, "layout")
27- nMain := between(lr, 7, 10)
27+ lr := rng.Sub(seed, "layout")
28+ nMain := rng.Between(lr, 7, 10)
2829 nSide := 0
2930 if sys.SideQuest {
30- nSide = between(lr, 2, 4)
31+ nSide = rng.Between(lr, 2, 4)
3132 }
3233 byPower := append([]model.Faction(nil), factions...)
3334 slices.SortStableFunc(byPower, func(a, b model.Faction) int { return a.Power - b.Power })
@@ -39,13 +40,13 @@ func Generate(seed model.Seed) World {
3940 boss := pois[nMain-1]
4041 maxDist := world.Distance(boss.X, boss.Y, spawns[0].X, spawns[0].Y)
4142
42- qr := sub(seed, "quests")
43+ qr := rng.Sub(seed, "quests")
4344 q := &questBuilder{r: qr, sys: sys, factions: byID, names: rollKeyNames(qr)}
4445 name := bossName(qr, byID[boss.Faction])
4546 camp := model.Campaign{Seed: seed, Systems: sys.List(), Factions: factions, SideQuests: []model.Mission{}}
4647 camp.Main = q.main(pois[:nMain], name)
4748 for i, rest := 0, pois[nMain:]; len(rest) > 0; i++ {
48- take := min(len(rest), between(qr, 1, 2))
49+ take := min(len(rest), rng.Between(qr, 1, 2))
4950 camp.SideQuests = append(camp.SideQuests, q.side(i, rest[:take]))
5051 rest = rest[take:]
5152 }
@@ -72,7 +73,7 @@ func Generate(seed model.Seed) World {
7273 }
7374 }
7475 }
75- pl := newPlacer(sub(seed, "loot"), &m, spawns[0], 4)
76+ pl := newPlacer(rng.Sub(seed, "loot"), &m, spawns[0], 4)
7677 bands := placeLoot(pl, maxDist, byPower)
7778 pl.far = 9
7879 bands = append(bands, placeBands(pl, maxDist, byPower)...)
@@ -83,7 +84,7 @@ func Generate(seed model.Seed) World {
8384 }
8485 m.Bands = bands
8586
86- er := sub(seed, "encounters")
87+ er := rng.Sub(seed, "encounters")
8788 var encs []model.Encounter
8889 for i, p := range pois {
8990 b := ""
@@ -100,7 +101,7 @@ func Generate(seed model.Seed) World {
100101 for _, b := range m.Bands {
101102 encs = append(encs, buildBandEncounter(er, b, byID[b.Faction]))
102103 }
103- return World{Campaign: camp, Map: m, Party: rollParty(sub(seed, "party"), spawns[0]), Encounters: encs}
104+ return World{Campaign: camp, Map: m, Party: rollParty(rng.Sub(seed, "party"), spawns[0]), Encounters: encs}
104105 }
105106
106107 func poiByID(pois []model.POI, id string) model.POI {
internal/gen/gen_test.go+2-16
@@ -1,12 +1,12 @@
11 package gen
22
33 import (
4- "os"
54 "reflect"
65 "strings"
76 "testing"
87
98 "tinyadventure/internal/model"
9+ "tinyadventure/internal/rng"
1010 "tinyadventure/internal/world"
1111 )
1212
@@ -24,7 +24,7 @@ func bfs(m model.Map, sx, sy int) map[[2]int]bool {
2424
2525 func TestSolvable(t *testing.T) {
2626 for i := 0; i < 200; i++ {
27- seed := NewSeed() + model.Seed(i)
27+ seed := rng.NewSeed() + model.Seed(i)
2828 w := Generate(seed)
2929 c := w.Campaign
3030 if n := len(c.Main.Steps); n < 6 || n > 10 {
@@ -114,17 +114,3 @@ func TestSeedsVary(t *testing.T) {
114114 t.Fatalf("too little variety: %d %d %d", len(systems), len(factions), len(names))
115115 }
116116 }
117-
118-func TestWriteSamples(t *testing.T) {
119- path := os.Getenv("SAMPLE_OUT")
120- if path == "" {
121- t.Skip()
122- }
123- var b strings.Builder
124- for _, s := range []model.Seed{1, 7, 2024, 31337} {
125- b.WriteString(Generate(s).Describe() + "\n---\n")
126- }
127- if err := os.WriteFile(path, []byte(b.String()), 0o644); err != nil {
128- t.Fatal(err)
129- }
130-}
internal/gen/items.go+0-66
@@ -1,66 +0,0 @@
1-package gen
2-
3-import (
4- "fmt"
5- "math/rand"
6-
7- "tinyadventure/internal/model"
8- "tinyadventure/internal/sim"
9-)
10-
11-var rarities = []string{"common", "uncommon", "rare", "epic", "legendary"}
12-
13-var slotNames = map[model.Slot][]string{
14- model.SlotWeapon: {"Sword", "Axe", "Staff", "Dagger", "Bow", "Mace"},
15- model.SlotArmor: {"Mail", "Leathers", "Robe", "Brigandine"},
16- model.SlotHelm: {"Helm", "Cap", "Hood", "Circlet"},
17- model.SlotTrinket: {"Charm", "Ring", "Amulet", "Talisman"},
18-}
19-
20-var slots = []model.Slot{model.SlotWeapon, model.SlotArmor, model.SlotHelm, model.SlotTrinket}
21-
22-var rarityPrefix = []string{"Rusty", "Sturdy", "Fine", "Runed", "Legendary"}
23-
24-var keyNames = []string{"Sunken Crown", "Bone Key", "Moonstone Sigil", "Ember Seal", "Gilded Chalice", "Black Lantern", "Serpent Idol"}
25-
26-func rarityFor(r *rand.Rand, level int) int {
27- tier := min(4, (level-1)/2)
28- if r.Intn(4) == 0 {
29- tier = min(4, tier+1)
30- }
31- return tier
32-}
33-
34-func makeItem(r *rand.Rand, id string, level int) model.Item {
35- slot := pick(r, slots)
36- tier := rarityFor(r, level)
37- pow := 1 + level/2 + tier
38- it := model.Item{
39- ID: id, Slot: slot, Rarity: rarities[tier],
40- Name: rarityPrefix[tier] + " " + pick(r, slotNames[slot]),
41- }
42- switch slot {
43- case model.SlotWeapon:
44- it.Bonus = model.Stats{Attack: pow + r.Intn(3), Crit: tier}
45- case model.SlotArmor:
46- it.Bonus = model.Stats{Defense: pow, MaxHP: pow * 3}
47- case model.SlotHelm:
48- it.Bonus = model.Stats{Defense: 1 + pow/2, Magic: r.Intn(pow + 1)}
49- default:
50- it.Bonus = model.Stats{Speed: 1 + tier, Magic: pow, Crit: r.Intn(tier + 2)}
51- }
52- it.Value = model.Price(it)
53- sim.Imbue(r.Intn, &it)
54- return it
55-}
56-
57-func makeKeyItem(r *rand.Rand, n int, name string) model.Item {
58- return model.Item{
59- ID: fmt.Sprintf("key%d", n), Name: name, Slot: model.SlotTrinket, Rarity: "rare",
60- Bonus: model.Stats{Magic: 2 + r.Intn(3)}, Key: true,
61- }
62-}
63-
64-func rollKeyNames(r *rand.Rand) []string {
65- return shuffled(r, keyNames)
66-}
internal/gen/landmarks.go+1-6
@@ -2,17 +2,12 @@ package gen
22
33 import (
44 "fmt"
5- "slices"
65
76 "tinyadventure/internal/model"
8- "tinyadventure/internal/world"
97 )
108
119 func hilltop(m *model.Map, c [2]int) bool {
12- h := m.Hex(c[0], c[1])
13- return h[0] == model.ShapeHill && !slices.ContainsFunc(world.Neighbours(c[0], c[1]), func(n [2]int) bool {
14- return m.In(n[0], n[1]) && m.Hex(n[0], n[1])[2] > h[2]
15- })
10+ return m.Hex(c[0], c[1])[0] == model.ShapeHill && summit(m, c)
1611 }
1712
1813 func placeLandmarks(p *placer) []model.Landmark {
internal/gen/loot.go+5-3
@@ -4,6 +4,8 @@ import (
44 "fmt"
55
66 "tinyadventure/internal/model"
7+ "tinyadventure/internal/rng"
8+ "tinyadventure/internal/sim"
79 )
810
911 const (
@@ -14,10 +16,10 @@ const (
1416
1517 func placeLoot(p *placer, maxDist int, byPower []model.Faction) []model.Band {
1618 var bands []model.Band
17- for _, c := range p.take(between(p.r, 10, 14), 4, func([2]int) bool { return true }) {
19+ for _, c := range p.take(rng.Between(p.r, 10, 14), 4, func([2]int) bool { return true }) {
1820 lv := levelAt(p.origin, maxDist, c[0], c[1])
1921 id := fmt.Sprintf("chest%d", len(p.m.Loot)+1)
20- roll := p.r.Intn(100)
22+ roll := p.r.IntN(100)
2123 bonus := 0
2224 node := model.LootNode{ID: id, X: c[0], Y: c[1]}
2325 switch {
@@ -32,7 +34,7 @@ func placeLoot(p *placer, maxDist int, byPower []model.Faction) []model.Band {
3234 bonus = 1
3335 node.Trap = true
3436 }
35- node.Item = makeItem(p.r, fmt.Sprintf("item%d", len(p.m.Loot)+1), lv+2*bonus)
37+ node.Item = sim.RollItem(p.r, lv+2*bonus)
3638 p.m.Loot = append(p.m.Loot, node)
3739 }
3840 return bands
internal/gen/mission.go+18-4
@@ -2,9 +2,10 @@ package gen
22
33 import (
44 "fmt"
5- "math/rand"
5+ "math/rand/v2"
66
77 "tinyadventure/internal/model"
8+ "tinyadventure/internal/rng"
89 )
910
1011 var mainNames = []string{"The Fall of the %s", "Ashes Under the %s", "Bane of the %s"}
@@ -56,14 +57,14 @@ func (q *questBuilder) main(pois []model.POI, boss string) model.Mission {
5657 for i, p := range pois[:len(pois)-1] {
5758 kind := "reach"
5859 if i > 0 {
59- kind = pick(q.r, kinds)
60+ kind = rng.Pick(q.r, kinds)
6061 }
6162 steps = append(steps, q.step(fmt.Sprintf("m%d", i+1), kind, p))
6263 }
6364 bs := q.step(fmt.Sprintf("m%d", len(pois)), "boss", last)
6465 bs.Text = fmt.Sprintf("Slay %s in %s", boss, last.Name)
6566 steps = append(steps, bs)
66- ti := q.r.Intn(len(mainTemplates))
67+ ti := q.r.IntN(len(mainTemplates))
6768 return model.Mission{
6869 Template: mainTemplates[ti],
6970 Name: fmt.Sprintf(mainNames[ti], q.factions[last.Faction].Name),
@@ -75,7 +76,20 @@ func (q *questBuilder) side(i int, pois []model.POI) model.Mission {
7576 kinds := kindsFor(q.sys)
7677 steps := make([]model.MissionStep, len(pois))
7778 for j, p := range pois {
78- steps[j] = q.step(fmt.Sprintf("s%d_%d", i+1, j+1), pick(q.r, kinds), p)
79+ steps[j] = q.step(fmt.Sprintf("s%d_%d", i+1, j+1), rng.Pick(q.r, kinds), p)
7980 }
8081 return model.Mission{Template: "side", Name: sideNames[i%len(sideNames)], Steps: steps}
8182 }
83+
84+var keyNames = []string{"Sunken Crown", "Bone Key", "Moonstone Sigil", "Ember Seal", "Gilded Chalice", "Black Lantern", "Serpent Idol"}
85+
86+func makeKeyItem(r *rand.Rand, n int, name string) model.Item {
87+ return model.Item{
88+ ID: fmt.Sprintf("key%d", n), Name: name, Slot: model.SlotTrinket, Rarity: "rare",
89+ Bonus: model.Stats{Magic: 2 + r.IntN(3)}, Key: true,
90+ }
91+}
92+
93+func rollKeyNames(r *rand.Rand) []string {
94+ return rng.Shuffled(r, keyNames)
95+}
internal/gen/party.go+15-33
@@ -2,27 +2,13 @@ package gen
22
33 import (
44 "fmt"
5- "math/rand"
5+ "math/rand/v2"
66
77 "tinyadventure/internal/model"
8+ "tinyadventure/internal/rng"
89 "tinyadventure/internal/sim"
910 )
1011
11-type classDef struct {
12- name string
13- hp, atk int
14- def, mag int
15- abilities []string
16-}
17-
18-var classes = []classDef{
19- {"fighter", 30, 6, 4, 1, []string{"cleave", "shield-bash"}},
20- {"rogue", 22, 7, 2, 1, []string{"backstab", "poison-dart"}},
21- {"mage", 18, 2, 1, 8, []string{"firebolt", "frost-nova"}},
22- {"cleric", 24, 3, 3, 6, []string{"heal", "smite"}},
23- {"ranger", 22, 6, 2, 2, []string{"piercing-shot", "volley"}},
24-}
25-
2612 type raceDef struct {
2713 name string
2814 hp, atk, def int
@@ -39,29 +25,25 @@ var races = []raceDef{
3925 var heroNames = []string{"Ayla", "Brom", "Cael", "Dara", "Edrin", "Fenna", "Garrick", "Hilde", "Isolde", "Joren", "Kestrel", "Lysa", "Mordo", "Nyx", "Orin", "Perrin"}
4026
4127 func rollParty(r *rand.Rand, spawn model.SpawnPoint) model.Party {
42- cs := shuffled(r, classes)[:between(r, 3, 4)]
43- names := shuffled(r, heroNames)
44- p := model.Party{X: spawn.X, Y: spawn.Y, Gold: between(r, 10, 40)}
28+ cs := rng.Shuffled(r, sim.Classes)[:rng.Between(r, 3, 4)]
29+ names := rng.Shuffled(r, heroNames)
30+ p := model.Party{X: spawn.X, Y: spawn.Y, Gold: rng.Between(r, 10, 40)}
4531 for i, c := range cs {
46- rc := pick(r, races)
47- hp := c.hp + rc.hp + r.Intn(7)
32+ rc := rng.Pick(r, races)
33+ b := c.Base
34+ hp := b.MaxHP + rc.hp + r.IntN(7)
4835 u := model.Unit{
49- ID: fmt.Sprintf("u%d", i+1), Name: names[i], Class: c.name, Race: rc.name, Level: 1,
36+ ID: fmt.Sprintf("u%d", i+1), Name: names[i], Class: c.Name, Race: rc.name, Level: 1,
5037 Stats: model.Stats{
51- HP: hp, MaxHP: hp, Attack: c.atk + rc.atk + r.Intn(3), Defense: c.def + rc.def + r.Intn(2),
52- Magic: c.mag + rc.mag + r.Intn(3), Speed: between(r, 3, 8) + rc.speed, Crit: between(r, 3, 10) + rc.crit,
38+ HP: hp, MaxHP: hp, Attack: b.Attack + rc.atk + r.IntN(3), Defense: b.Defense + rc.def + r.IntN(2),
39+ Magic: b.Magic + rc.mag + r.IntN(3), Speed: rng.Between(r, 3, 8) + rc.speed, Crit: rng.Between(r, 3, 10) + rc.crit,
5340 },
54- Abilities: sim.Abilities(c.abilities...),
41+ Abilities: sim.Abilities(c.Abilities...),
5542 Gear: model.Gear{},
5643 }
57- for _, s := range shuffled(r, slots)[:between(r, 2, 3)] {
58- for {
59- it := makeItem(r, fmt.Sprintf("start%d_%s", i+1, s), 1)
60- if it.Slot == s {
61- u.Gear[s] = &it
62- break
63- }
64- }
44+ for _, s := range rng.Shuffled(r, sim.Slots)[:rng.Between(r, 2, 3)] {
45+ it := sim.BuildItem(r, s, "common", 1)
46+ u.Gear[s] = &it
6547 }
6648 p.Units = append(p.Units, u)
6749 }
internal/gen/place.go+9-2
@@ -1,9 +1,11 @@
11 package gen
22
33 import (
4- "math/rand"
4+ "math/rand/v2"
5+ "slices"
56
67 "tinyadventure/internal/model"
8+ "tinyadventure/internal/rng"
79 "tinyadventure/internal/world"
810 )
911
@@ -29,7 +31,7 @@ func newPlacer(r *rand.Rand, m *model.Map, origin model.SpawnPoint, far int) *pl
2931
3032 func (p *placer) take(n, gap int, fits func(c [2]int) bool) [][2]int {
3133 var out [][2]int
32- for _, c := range shuffled(p.r, hexes(p.m, func(c [2]int) bool { return p.reach[c] && open(p.m, c) && !p.used[c] && fits(c) })) {
34+ for _, c := range rng.Shuffled(p.r, hexes(p.m, func(c [2]int) bool { return p.reach[c] && open(p.m, c) && !p.used[c] && fits(c) })) {
3335 if len(out) == n {
3436 break
3537 }
@@ -64,3 +66,8 @@ func open(m *model.Map, c [2]int) bool {
6466 s := m.Hex(c[0], c[1])[0]
6567 return s == model.ShapePlain || s == model.ShapeHill
6668 }
69+
70+func summit(m *model.Map, c [2]int) bool {
71+ h := m.Hex(c[0], c[1])[2]
72+ return !slices.ContainsFunc(world.Neighbours(c[0], c[1]), func(n [2]int) bool { return m.In(n[0], n[1]) && m.Hex(n[0], n[1])[2] > h })
73+}
internal/gen/pois.go+8-12
@@ -2,11 +2,12 @@ package gen
22
33 import (
44 "fmt"
5- "math/rand"
5+ "math/rand/v2"
66 "slices"
77 "sort"
88
99 "tinyadventure/internal/model"
10+ "tinyadventure/internal/rng"
1011 "tinyadventure/internal/world"
1112 )
1213
@@ -33,12 +34,7 @@ var poiFits = map[string]func(m *model.Map, c [2]int) bool{
3334 h := m.Hex(c[0], c[1])
3435 return h[0] == model.ShapePlain && h[3]&model.FlagForest == 0
3536 },
36- "tower": func(m *model.Map, c [2]int) bool {
37- h := m.Hex(c[0], c[1])
38- return h[0] >= model.ShapeHill && !slices.ContainsFunc(world.Neighbours(c[0], c[1]), func(n [2]int) bool {
39- return m.In(n[0], n[1]) && m.Hex(n[0], n[1])[2] > h[2]
40- })
41- },
37+ "tower": func(m *model.Map, c [2]int) bool { return m.Hex(c[0], c[1])[0] >= model.ShapeHill && summit(m, c) },
4238 "camp": func(m *model.Map, c [2]int) bool { return m.Hex(c[0], c[1])[3]&model.FlagForest != 0 },
4339 "ruins": func(m *model.Map, c [2]int) bool { return true },
4440 }
@@ -93,11 +89,11 @@ func (l *layout) place(cx int, near *model.SpawnPoint, prog float64, boss bool)
9389 band = hb
9490 }
9591 }
96- kinds := shuffled(l.r, l.sys.POIKinds)
97- kind, at := kinds[0], pick(l.r, band)
92+ kinds := rng.Shuffled(l.r, l.sys.POIKinds)
93+ kind, at := kinds[0], rng.Pick(l.r, band)
9894 for _, k := range kinds {
9995 if fit := filter(band, func(c [2]int) bool { return poiFits[k](l.m, c) }); len(fit) > 0 {
100- kind, at = k, pick(l.r, fit)
96+ kind, at = k, rng.Pick(l.r, fit)
10197 break
10298 }
10399 }
@@ -124,14 +120,14 @@ func layoutPOIs(l *layout, nMain, nSide int) []model.POI {
124120 l.place(x0+5+int(prog*float64(mapW-x0-10)), near, prog, i == nMain-1)
125121 }
126122 for range nSide {
127- l.place(between(l.r, x0+6, mapW-12), nil, l.r.Float64(), false)
123+ l.place(rng.Between(l.r, x0+6, mapW-12), nil, l.r.Float64(), false)
128124 }
129125 return l.pois
130126 }
131127
132128 func uniqueName(r *rand.Rand, pois []model.POI, kind string) string {
133129 for {
134- n := pick(r, poiAdjectives) + " " + poiTitles[kind]
130+ n := rng.Pick(r, poiAdjectives) + " " + poiTitles[kind]
135131 dup := false
136132 for _, p := range pois {
137133 dup = dup || p.Name == n
internal/gen/rng.go+0-33
@@ -1,33 +0,0 @@
1-package gen
2-
3-import (
4- "hash/fnv"
5- "math/rand"
6- "time"
7-
8- "tinyadventure/internal/model"
9-)
10-
11-func NewSeed() model.Seed {
12- return model.Seed(rand.New(rand.NewSource(time.Now().UnixNano())).Int63n(1_000_000))
13-}
14-
15-func sub(seed model.Seed, tag string) *rand.Rand {
16- h := fnv.New64a()
17- h.Write([]byte(tag))
18- return rand.New(rand.NewSource(int64(seed) ^ int64(h.Sum64())))
19-}
20-
21-func pick[T any](r *rand.Rand, s []T) T {
22- return s[r.Intn(len(s))]
23-}
24-
25-func shuffled[T any](r *rand.Rand, s []T) []T {
26- out := append([]T(nil), s...)
27- r.Shuffle(len(out), func(i, j int) { out[i], out[j] = out[j], out[i] })
28- return out
29-}
30-
31-func between(r *rand.Rand, lo, hi int) int {
32- return lo + r.Intn(hi-lo+1)
33-}
internal/gen/spawn.go+5-4
@@ -2,9 +2,10 @@ package gen
22
33 import (
44 "fmt"
5- "math/rand"
5+ "math/rand/v2"
66
77 "tinyadventure/internal/model"
8+ "tinyadventure/internal/rng"
89 "tinyadventure/internal/world"
910 )
1011
@@ -17,7 +18,7 @@ var spawnKinds = []struct{ kind, hint string }{
1718 }
1819
1920 func buildSpawns(r *rand.Rand, m *model.Map, main map[[2]int]bool) []model.SpawnPoint {
20- kinds := shuffled(r, spawnKinds)
21+ kinds := rng.Shuffled(r, spawnKinds)
2122 west := func(open bool) func(c [2]int) bool {
2223 return func(c [2]int) bool {
2324 h := m.Hex(c[0], c[1])
@@ -28,9 +29,9 @@ func buildSpawns(r *rand.Rand, m *model.Map, main map[[2]int]bool) []model.Spawn
2829 if len(sites) < 2 {
2930 sites = hexes(m, west(false))
3031 }
31- a := pick(r, sites)
32+ a := rng.Pick(r, sites)
3233 b := a
33- for _, c := range shuffled(r, sites) {
34+ for _, c := range rng.Shuffled(r, sites) {
3435 if d := world.Distance(a[0], a[1], c[0], c[1]); d >= 6 && d <= 14 {
3536 b = c
3637 break
internal/gen/systems.go+10-6
@@ -1,6 +1,10 @@
11 package gen
22
3-import "math/rand"
3+import (
4+ "math/rand/v2"
5+
6+ "tinyadventure/internal/rng"
7+)
48
59 var allPOIKinds = []string{"mine", "beach", "ruins", "crypt", "village", "tower", "camp"}
610
@@ -13,12 +17,12 @@ type Systems struct {
1317 }
1418
1519 func rollSystems(r *rand.Rand) Systems {
16- kinds := shuffled(r, allPOIKinds)[:between(r, 4, len(allPOIKinds))]
20+ kinds := rng.Shuffled(r, allPOIKinds)[:rng.Between(r, 4, len(allPOIKinds))]
1721 return Systems{
18- Factions: r.Intn(4) != 0,
19- KeyItems: r.Intn(4) != 0,
20- SideQuest: r.Intn(4) != 0,
21- Hazards: r.Intn(2) == 0,
22+ Factions: r.IntN(4) != 0,
23+ KeyItems: r.IntN(4) != 0,
24+ SideQuest: r.IntN(4) != 0,
25+ Hazards: r.IntN(2) == 0,
2226 POIKinds: kinds,
2327 }
2428 }
internal/model/api.go+0-15
@@ -19,12 +19,6 @@ type EquipRequest struct {
1919 Unequip bool `json:"unequip,omitempty"`
2020 }
2121
22-type AbilityRequest struct {
23- Unit string `json:"unit"`
24- Ability string `json:"ability"`
25- Slot int `json:"slot"`
26-}
27-
2822 type ItemRequest struct {
2923 Item string `json:"item"`
3024 }
@@ -33,15 +27,6 @@ type UnitRequest struct {
3327 Unit string `json:"unit"`
3428 }
3529
36-type SeedResponse struct {
37- Seed Seed `json:"seed"`
38- Systems []string `json:"systems"`
39-}
40-
41-type CombatLogResponse struct {
42- Log []CombatEvent `json:"log"`
43-}
44-
4530 type ErrorResponse struct {
4631 Error string `json:"error"`
4732 }
internal/model/campaign.go+0-6
@@ -22,12 +22,6 @@ type MissionStep struct {
2222 Done bool `json:"done"`
2323 }
2424
25-type MissionTemplate struct {
26- ID string `json:"id"`
27- Name string `json:"name"`
28- Steps []MissionStep `json:"steps"`
29-}
30-
3125 type Mission struct {
3226 Template string `json:"template"`
3327 Name string `json:"name"`
internal/model/combat.go+6-0
@@ -14,6 +14,12 @@ type Threat struct {
1414 Odds int `json:"odds"`
1515 Wounds int `json:"wounds"`
1616 Barred bool `json:"barred,omitempty"`
17+ Edge Edge `json:"edge"`
18+}
19+
20+type Edge struct {
21+ Hits []string `json:"hits"`
22+ Blunted []string `json:"blunted"`
1723 }
1824
1925 type CombatEvent struct {
internal/rng/rng.go+37-0
@@ -0,0 +1,37 @@
1+package rng
2+
3+import (
4+ "hash/fnv"
5+ "math/rand/v2"
6+ "time"
7+
8+ "tinyadventure/internal/model"
9+)
10+
11+func New(seed model.Seed) *rand.Rand {
12+ return rand.New(rand.NewPCG(uint64(seed), 0x9e3779b97f4a7c15))
13+}
14+
15+func Sub(seed model.Seed, tag string) *rand.Rand {
16+ h := fnv.New64a()
17+ h.Write([]byte(tag))
18+ return New(seed ^ model.Seed(h.Sum64()))
19+}
20+
21+func NewSeed() model.Seed {
22+ return model.Seed(New(model.Seed(time.Now().UnixNano())).Int64N(1_000_000))
23+}
24+
25+func Pick[T any](r *rand.Rand, xs []T) T {
26+ return xs[r.IntN(len(xs))]
27+}
28+
29+func Shuffled[T any](r *rand.Rand, xs []T) []T {
30+ out := append([]T(nil), xs...)
31+ r.Shuffle(len(out), func(i, j int) { out[i], out[j] = out[j], out[i] })
32+ return out
33+}
34+
35+func Between(r *rand.Rand, lo, hi int) int {
36+ return lo + r.IntN(hi-lo+1)
37+}
internal/server/bands.go+5-5
@@ -2,7 +2,7 @@ package server
22
33 import (
44 "tinyadventure/internal/model"
5- "tinyadventure/internal/sim"
5+ "tinyadventure/internal/rng"
66 "tinyadventure/internal/world"
77 )
88
@@ -46,7 +46,7 @@ func (g *game) tickBands() string {
4646 if night {
4747 reach = nightAggro
4848 }
49- r := sim.NewRNG(g.state.Seed ^ model.Seed(g.ticks)*6151)
49+ r := rng.New(g.state.Seed ^ model.Seed(g.ticks)*6151)
5050 m := &g.state.Map
5151 px, py := g.state.Party.X, g.state.Party.Y
5252 for i := range m.Bands {
@@ -55,14 +55,14 @@ func (g *game) tickBands() string {
5555 continue
5656 }
5757 var next [2]int
58- if b.Calm == 0 && dist(b.X, b.Y, px, py) <= reach {
58+ if b.Calm == 0 && world.Distance(b.X, b.Y, px, py) <= reach {
5959 if path := world.Path(m, [2]int{b.X, b.Y}, [2]int{px, py}, g.occupied); len(path) > 1 {
6060 next = path[0]
6161 }
6262 } else {
6363 n := world.Neighbours(b.X, b.Y)
6464 c := n[r.IntN(len(n))]
65- if m.Walkable(c[0], c[1]) && m.Hex(c[0], c[1])[0] >= model.ShapePlain && dist(c[0], c[1], b.HomeX, b.HomeY) <= wanderOff {
65+ if m.Walkable(c[0], c[1]) && m.Hex(c[0], c[1])[0] >= model.ShapePlain && world.Distance(c[0], c[1], b.HomeX, b.HomeY) <= wanderOff {
6666 next = c
6767 }
6868 }
@@ -89,7 +89,7 @@ func (g *game) settle() {
8989
9090 func (g *game) contact() string {
9191 for _, b := range g.state.Map.Bands {

Cut short: this commit's diff is over 1000 lines.

internal/server/clock.go+3-5

Cut short: this commit's diff is over 1000 lines.

internal/server/danger_test.go+2-1

Cut short: this commit's diff is over 1000 lines.

internal/server/equip.go+0-27

Cut short: this commit's diff is over 1000 lines.

internal/server/game.go+2-1

Cut short: this commit's diff is over 1000 lines.

internal/server/interact.go+2-4

Cut short: this commit's diff is over 1000 lines.

internal/server/move.go+0-3

Cut short: this commit's diff is over 1000 lines.

internal/server/play_test.go+4-3

Cut short: this commit's diff is over 1000 lines.

internal/server/server.go+8-25

Cut short: this commit's diff is over 1000 lines.

internal/server/server_test.go+15-7

Cut short: this commit's diff is over 1000 lines.

internal/server/shop.go+2-10

Cut short: this commit's diff is over 1000 lines.

internal/server/threat.go+3-2

Cut short: this commit's diff is over 1000 lines.

internal/sim/abilities.go+0-4

Cut short: this commit's diff is over 1000 lines.

internal/sim/classes.go+14-60

Cut short: this commit's diff is over 1000 lines.

internal/sim/enemies.go+0-96

Cut short: this commit's diff is over 1000 lines.

internal/sim/gear.go+6-5

Cut short: this commit's diff is over 1000 lines.

internal/sim/rng.go+0-15

Cut short: this commit's diff is over 1000 lines.

internal/sim/sim_test.go+80-135

Cut short: this commit's diff is over 1000 lines.

internal/sim/traits.go+42-2

Cut short: this commit's diff is over 1000 lines.

internal/sim/traits_test.go+18-3

Cut short: this commit's diff is over 1000 lines.

internal/world/hex.go+0-11

Cut short: this commit's diff is over 1000 lines.

scripts/bot.mjs+21-2

Cut short: this commit's diff is over 1000 lines.

scripts/driver.mjs+0-29

Cut short: this commit's diff is over 1000 lines.

scripts/playthrough.mjs+2-2

Cut short: this commit's diff is over 1000 lines.

scripts/playthrough.sh+3-11

Cut short: this commit's diff is over 1000 lines.

scripts/serve.sh+17-0

Cut short: this commit's diff is over 1000 lines.

scripts/verify.mjs+5-14

Cut short: this commit's diff is over 1000 lines.

scripts/verify.sh+3-11

Cut short: this commit's diff is over 1000 lines.

web/gallery.html+0-13

Cut short: this commit's diff is over 1000 lines.

web/js/api.js+0-1

Cut short: this commit's diff is over 1000 lines.

web/js/beasts.js+1-1

Cut short: this commit's diff is over 1000 lines.

web/js/board.js+2-2

Cut short: this commit's diff is over 1000 lines.

web/js/flora.js+1-1

Cut short: this commit's diff is over 1000 lines.

web/js/frames.js+9-1

Cut short: this commit's diff is over 1000 lines.

web/js/gallery.js+0-94

Cut short: this commit's diff is over 1000 lines.

web/js/inventory.js+2-8

Cut short: this commit's diff is over 1000 lines.

web/js/journal.js+1-7

Cut short: this commit's diff is over 1000 lines.

web/js/looks.js+0-2

Cut short: this commit's diff is over 1000 lines.

web/js/minis.js+1-1

Cut short: this commit's diff is over 1000 lines.

web/js/paint.js+1-1

Cut short: this commit's diff is over 1000 lines.

web/js/shop.js+1-0

Cut short: this commit's diff is over 1000 lines.

web/js/text.js+2-2

Cut short: this commit's diff is over 1000 lines.

web/js/theme.js+1-1

Cut short: this commit's diff is over 1000 lines.

web/js/threat.js+2-2

Cut short: this commit's diff is over 1000 lines.

web/js/traits.js+1-27

Cut short: this commit's diff is over 1000 lines.

web/js/world.js+1-1

Cut short: this commit's diff is over 1000 lines.