gizgame/procgen
worlds made from one seed. Every part takes its own seed from the world's and its name (seedOf), so a change to one part leaves the others as they were, and the same seed is the same world on every machine: all of it is integer hashing and f64 arithmetic in a fixed order. Terrain is fractal noise (gizlang/math noise2), ridged and warped as its Shape says, then worn by water drops (erode). Biomes come from height, warmth and wetness; scatter places things by Poisson disk. A dungeon is rooms in a binary space partition joined by a spanning tree and a few loops; a town is roads, lots and buildings. A quest is what a language model wrote against the world's facts (QUEST_PROMPT), kept only when every step names a fact (questOf): the model writes, the game checks.
import * as Procgen from "gizgame/procgen";Types
Shape
type Shape = { scale: f64; height: f64; octaves: i64; ridged: f64; warp: f64; sea: f64; }A terrain's shape: SCALE meters a feature, HEIGHT meters its range, OCTAVES of detail, RIDGED (0 to 1) how much of it is sharp crests, WARP meters of domain warp (twisted valleys), and the SEA level as a fraction of the range.
scale:f64height:f64octaves:i64ridged:f64warp:f64sea:f64
Biome
type Biome = { name: string; low: f64; high: f64; warm: f64; wet: f64; }A biome: its NAME and the warmth and wetness (0 to 1) it takes, at heights between LOW and HIGH meters.
name:stringlow:f64high:f64warm:f64wet:f64
Room
type Room = { x: i64; z: i64; width: i64; depth: i64; }A room of a dungeon: its corner and size in tiles.
x:i64z:i64width:i64depth:i64
Dungeon
type Dungeon = { columns: i64; rows: i64; tiles: Vec<i64>; rooms: Vec<Room>; }The tiles of a dungeon, row after row, and its rooms.
columns:i64rows:i64tiles:Vec<i64>rooms:Vec<M188.Room>
Triangles
type Triangles = { positions: Vec<f64>; indices: Vec<i64>; }The floor of D as triangles (positions x, y, z and indices) of TILE meters at height 0 and its walls at HEIGHT (a wall tile is a quad at that height, which navigation cannot climb), for a mesh to draw and for navigation to build on.
positions:Vec<f64>indices:Vec<i64>
Road
type Road = { a: Point3; b: Point3; width: f64; }A town: its roads (each from A to B, WIDTH meters) and its lots, each with a building's footprint (x, z, width, depth in meters), its floors and its KIND (house, shop, inn, hall, smithy, temple).
a:gizlang_geometry.Point3b:gizlang_geometry.Point3width:f64
Lot
type Lot = { x: f64; z: f64; width: f64; depth: f64; floors: i64; kind: string; }A building lot of a town: its center, size, floors and kind.
x:f64z:f64width:f64depth:f64floors:i64kind:string
Town
type Town = { roads: Vec<Road>; lots: Vec<Lot>; }The roads and lots of a town.
roads:Vec<M188.Road>lots:Vec<M188.Lot>
Fact
type Fact = { id: string; kind: string; about: string; }A fact of the world a quest may name: its ID, its KIND (person, place, item, creature) and a line about it.
id:stringkind:stringabout:string
Step
type Step = { kind: string; target: string; to?: string; count?: i64; text: string; }A step of a quest: go to a place, talk to a person, bring an item to a person, or defeat creatures (COUNT).
kind:stringtarget:stringto:_gizlang_sdk_core.Option<string>count:_gizlang_sdk_core.Option<i64>text:string
Quest
type Quest = { giver: string; title: string; steps: Vec<Step>; reward: string; }A quest: its giver (a person), its title, its steps in order and its reward (an item, or "" none).
giver:stringtitle:stringsteps:Vec<M188.Step>reward:string
Functions
seedOf
function seedOf(seed: i64, name: string): i64The seed of the part NAME of the world SEED (FNV-1a over the name, mixed with the seed).
Effects: fail.
hills
function hills(): ShapeRolling hills, 30 m high, with no sea.
mountains
function mountains(): ShapeRidged mountains, 180 m high, with valleys under a sea.
heightOf
function heightOf(shape: Shape, seed: i64, x: f64, z: f64): f64The height of the terrain SHAPE of SEED at X, Z in meters.
Effects: fail.
terrain
function terrain(shape: Shape, seed: i64, columns: i64, rows: i64, spacing: f64, origin: Point3): FieldThe terrain SHAPE of SEED as a field of COLUMNS by ROWS samples SPACING meters apart, from ORIGIN.
Effects: fail, alloc.
erode
function erode(f: Field, seed: i64, drops: i64): FieldF worn by DROPS water drops of SEED: each runs downhill, takes soil where it speeds up and drops it where it slows (hydraulic erosion as Beyer's 2015 thesis gives it, with its constants).
Effects: fail, read, write, alloc.
biomeAt
function biomeAt(biomes: Vec<Biome>, seed: i64, x: f64, z: f64, height: f64): stringThe biome of the point X, Z at HEIGHT of SEED among BIOMES: the nearest in warmth and wetness of those its height allows (warmth falls 0.6 every 100 m).
Effects: fail.
scatter
function scatter(seed: i64, low: Point3, high: Point3, spacing: f64, allows: (x: f64, z: f64) => bool): Vec<Point3>Points of SEED in the rectangle from LOW to HIGH (x, z), each at least SPACING from every other and kept by ALLOWS (Bridson's Poisson disk sampling, 30 tries a point).
Effects: fail, read, write, console, io, alloc.
dungeon
function dungeon(seed: i64, columns: i64, rows: i64, least: i64 = 8, loops: i64 = 4): DungeonA dungeon of SEED on COLUMNS by ROWS tiles: the space split in two again and again (never below LEAST tiles a side), a room in each leaf, the rooms joined by a minimum spanning tree of their centers and a loop for about one room in LOOPS more, each joint an L-shaped corridor with a door where it meets a room.
Effects: fail, read, write, alloc.
floorOf
function floorOf(d: Dungeon, tile: f64, height: f64): TrianglesThe floor and walls of D as triangles: TILE meters a tile, walls HEIGHT meters high.
Effects: fail, read, write, alloc.
surfaceOf
function surfaceOf(f: Field): TrianglesThe ground of F as triangles, two a cell, for navigation to build on (as floorOf gives a dungeon's).
Effects: fail, alloc.
town
function town(seed: i64, center: Point3, blocks: i64 = 4, block: f64 = 40.0): TownA town of SEED of BLOCKS by BLOCKS blocks of BLOCK meters around CENTER: a road grid bent by noise, each block cut into lots along its roads, the hall and the temple near the middle.
Effects: fail, alloc.
questPrompt
function questPrompt(facts: Vec<Fact>): stringThe prompt of FACTS: QUEST_PROMPT and one line a fact.
Effects: fail, read, write, console, io, alloc.
questOf
function questOf(text: string, facts: Vec<Fact>): Quest throws stringThe quest in TEXT (a model's answer: its first { to its last }), when every ID names a fact of the kind its
place asks; else why not, for the model to try again.
Effects: fail, alloc.
Constants
WALL
const WALL: i64 = 0A dungeon: a grid of COLUMNS by ROWS tiles (WALL, FLOOR or DOOR) and its rooms (x, z, width, depth in tiles).
FLOOR
const FLOOR: i64 = 1A dungeon tile one walks on.
DOOR
const DOOR: i64 = 2A dungeon tile where a corridor enters a room.
QUEST_PROMPT
const QUEST_PROMPT = "You write one quest for a game. Answer with JSON only: {\"giver\":ID,\"title\":TEXT," + "\"steps\":[{\"kind\":\"go|talk|bring|defeat\",\"target\":ID,\"to\":ID,\"count\":N,\"text\":TEXT}],\"reward\":ID}. " + "Every ID is one of the facts below: giver a person, go a place, talk a person, bring an item (to a person), " + "defeat a creature (count 1 to 10), reward an item or \"\". Use 1 to 5 steps that tell one small story.\nFacts:\n"What a language model is told before the facts, to answer with one Quest.