wip(0.S3): the packages migrated by ludic migrate state packages - every package test green

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Orkun ÇAKILKAYA 2026-09-25 14:02:21 +03:00
parent 1e8b5b0523
commit 07505e7ef2
294 changed files with 14996 additions and 14675 deletions

View file

@ -1,31 +1,31 @@
# decide.ludic - lighting and feeding in three steps, so a machine that does not own the fire can
# ask the one that does: what it would come to (fire_decide), what it costs in wood
# (fire_cost), and doing it (fire_apply - only ever on the machine that owns the world)
export function fire_decide(wood: int) -> int {
if fr_lit {
export function fire_decide(fire_st: FireState, wood: int) -> int {
if fire_st.fr_lit {
if wood < 1 { return FIRE_NO_LOG }
return FIRE_FEED
}
if not FireWorld.allowed() { return FIRE_BANNED }
if wood < fr_light_wood { return FIRE_NO_WOOD }
if wood < fire_st.fr_light_wood { return FIRE_NO_WOOD }
if FireWorld.is_wet() and not FireWorld.sheltered() { return FIRE_SOAKED }
return FIRE_LIGHT
}
export function fire_cost(how: int) -> int {
if how == FIRE_LIGHT { return fr_light_wood }
export function fire_cost(fire_st: FireState, how: int) -> int {
if how == FIRE_LIGHT { return fire_st.fr_light_wood }
if how == FIRE_FEED { return 1 }
return 0
}
export function fire_apply(how: int) -> void {
if how == FIRE_FEED { fr_fuel = fr_fuel + fr_log_minutes }
export function fire_apply(base_st: mut BaseState, fire_st: mut FireState, how: int) -> void {
if how == FIRE_FEED { fire_st.fr_fuel = fire_st.fr_fuel + fire_st.fr_log_minutes }
if how == FIRE_LIGHT {
fr_lit = true
fr_fuel = fr_light_minutes
fr_fact(FIRE_LIT)
fire_st.fr_lit = true
fire_st.fr_fuel = fire_st.fr_light_minutes
fr_fact(base_st, fire_st, FIRE_LIT)
}
}
# the logs it takes to light one
export function fire_light_wood() -> int { return fr_light_wood }
export function fire_light_wood(fire_st: FireState) -> int { return fire_st.fr_light_wood }

View file

@ -1,16 +1,16 @@
# queries.ludic - what the world asks the fire
export function fire_lit() -> bool { return fr_lit }
export function fire_lit(fire_st: FireState) -> bool { return fire_st.fr_lit }
# game minutes of fuel left
export function fire_fuel() -> float { return fr_fuel }
export function fire_fuel(fire_st: FireState) -> float { return fire_st.fr_fuel }
export function fire_low() -> bool { return fr_lit and fr_fuel < fr_low_minutes }
export function fire_low(fire_st: FireState) -> bool { return fire_st.fr_lit and fire_st.fr_fuel < fire_st.fr_low_minutes }
# game hours today it has burned in the rain with something over it
export function fire_rain_hours() -> float { return fr_rain_h }
export function fire_rain_hours(fire_st: FireState) -> float { return fire_st.fr_rain_h }
# does it warm a body `dist` metres from it?
export function fire_warms(dist: float) -> bool { return fr_lit and dist < fr_warm_radius }
export function fire_warms(fire_st: FireState, dist: float) -> bool { return fire_st.fr_lit and dist < fire_st.fr_warm_radius }
# will it cook for someone `dist` metres from it? (a station that stands on it asks only fire_lit)
export function fire_cooks(dist: float) -> bool { return fr_lit and dist < fr_cook_radius }
export function fire_cooks(fire_st: FireState, dist: float) -> bool { return fire_st.fr_lit and dist < fire_st.fr_cook_radius }

View file

@ -10,12 +10,18 @@ export port FireWorld {
function fr_yes() -> bool { return true }
function fr_no() -> bool { return false }
var fr_light_wood: int = 3 # logs to light one
var fr_light_minutes: float = 120.0 # game minutes of fuel a new fire has
var fr_log_minutes: float = 60.0 # game minutes a log adds
var fr_low_minutes: float = 15.0 # under this, the fire is burning low
var fr_warm_radius: float = 3.6 # metres it warms a body
var fr_cook_radius: float = 3.5 # metres it cooks from
export state FireState {
fr_light_wood: int = 3 # logs to light one
fr_light_minutes: float = 120.0 # game minutes of fuel a new fire has
fr_log_minutes: float = 60.0 # game minutes a log adds
fr_low_minutes: float = 15.0 # under this, the fire is burning low
fr_warm_radius: float = 3.6 # metres it warms a body
fr_cook_radius: float = 3.5 # metres it cooks from
fr_lit: bool = false
fr_fuel: float = 0.0 # game minutes left
fr_rain_h: float = 0.0 # game hours today it burned in the rain under cover
fr_facts: Queue<FireFact> = null
}
# what lighting or feeding would come to, as the world stands
export const FIRE_NO_WOOD: int = 0 # not enough to light one
@ -35,34 +41,30 @@ export property FireFact {
fuel: float = 0.0
}
var fr_lit: bool = false
var fr_fuel: float = 0.0 # game minutes left
var fr_rain_h: float = 0.0 # game hours today it burned in the rain under cover
var fr_facts: Queue<FireFact> = null
# the facts, oldest first; the game drains them into its notices
export function fire_facts() -> Queue<FireFact> {
if fr_facts == null { fr_facts = queue_new("fire.facts") }
return fr_facts
export function fire_facts(base_st: mut BaseState, fire_st: mut FireState) -> Queue<FireFact> {
if fire_st.fr_facts == null { fire_st.fr_facts = queue_new(base_st, "fire.facts") }
return fire_st.fr_facts
}
function fr_fact(what: int) -> void {
function fr_fact(base_st: mut BaseState, fire_st: mut FireState, what: int) -> void {
let f = new FireFact
f.what = what
f.fuel = fr_fuel
q_push(fire_facts(), f)
f.fuel = fire_st.fr_fuel
q_push(base_st, fire_facts(base_st, fire_st), f)
}
# a game's numbers: logs to light, minutes a new fire and a log are worth, when it is low
export function fire_config(light_wood: int, light_minutes: float, log_minutes: float, low_minutes: float) -> void {
fr_light_wood = light_wood
fr_light_minutes = light_minutes
fr_log_minutes = log_minutes
fr_low_minutes = low_minutes
export function fire_config(fire_st: mut FireState, light_wood: int, light_minutes: float, log_minutes: float, low_minutes: float) -> void {
fire_st.fr_light_wood = light_wood
fire_st.fr_light_minutes = light_minutes
fire_st.fr_log_minutes = log_minutes
fire_st.fr_low_minutes = low_minutes
}
# how far it warms a body and how far it cooks from, in metres
export function fire_config_reach(warm: float, cook: float) -> void {
fr_warm_radius = warm
fr_cook_radius = cook
export function fire_config_reach(fire_st: mut FireState, warm: float, cook: float) -> void {
fire_st.fr_warm_radius = warm
fire_st.fr_cook_radius = cook
}

View file

@ -1,19 +1,19 @@
# system.ludic - the fire as a system: PH_SIMULATE, and its own save section
function fire_tick(t: Tick) -> void { fire_run(t.hours) }
function fire_tick(base_st: mut BaseState, fire_st: mut FireState, t: Tick) -> void { fire_run(base_st, fire_st, t.hours) }
export function fire_save() -> Val {
export function fire_save(fire_st: FireState) -> Val {
let v = Value.object()
sv_put_bool(v, "lit", fr_lit)
sv_put_float(v, "fuel", fr_fuel)
sv_put_float(v, "rain_h", fr_rain_h)
sv_put_bool(v, "lit", fire_st.fr_lit)
sv_put_float(v, "fuel", fire_st.fr_fuel)
sv_put_float(v, "rain_h", fire_st.fr_rain_h)
return v
}
export function fire_load(v: Val, version: int) -> void {
fire_reset()
fr_lit = sv_bool(v, "lit", false)
fr_fuel = sv_float(v, "fuel", 0.0)
fr_rain_h = sv_float(v, "rain_h", 0.0)
export function fire_load(base_st: mut BaseState, fire_st: mut FireState, v: Val, version: int) -> void {
fire_reset(base_st, fire_st)
fire_st.fr_lit = sv_bool(v, "lit", false)
fire_st.fr_fuel = sv_float(v, "fuel", 0.0)
fire_st.fr_rain_h = sv_float(v, "rain_h", 0.0)
}
export function fire_system() -> System {

View file

@ -4,15 +4,17 @@ import "ludic.fire"
import "ludic.base"
program FireTest {
numbers float
var owns: bool = true
var wet: bool = false
var tarp: bool = false
var ban: bool = false
state FiretestState {
owns: bool = true
wet: bool = false
tarp: bool = false
ban: bool = false
}
function fake_owns() -> bool { return owns }
function fake_wet() -> bool { return wet }
function fake_tarp() -> bool { return tarp }
function fake_allowed() -> bool { return not ban }
function fake_owns(firetest_st: FiretestState) -> bool { return firetest_st.owns }
function fake_wet(firetest_st: FiretestState) -> bool { return firetest_st.wet }
function fake_tarp(firetest_st: FiretestState) -> bool { return firetest_st.tarp }
function fake_allowed(firetest_st: FiretestState) -> bool { return not firetest_st.ban }
bind FireWorld {
owns_world: fn fake_owns
@ -21,125 +23,125 @@ program FireTest {
allowed: fn fake_allowed
}
function fresh() -> void {
fire_config(3, 120.0, 60.0, 15.0)
fire_config_reach(3.6, 3.5)
fire_reset()
function fresh(base_st: mut BaseState, fire_st: mut FireState) -> void {
fire_config(fire_st, 3, 120.0, 60.0, 15.0)
fire_config_reach(fire_st, 3.6, 3.5)
fire_reset(base_st, fire_st)
}
function facts() -> []FireFact { return q_drain(fire_facts()) }
function facts(base_st: mut BaseState, fire_st: mut FireState) -> []FireFact { return q_drain(base_st, fire_facts(base_st, fire_st)) }
function count(fs: []FireFact, what: int) -> int {
var n = 0
for i in 0 .. len(fs) { if fs[i].what == what { n += 1 } }
return n
}
function light() -> void { fire_apply(fire_decide(3)) }
function light(base_st: mut BaseState, fire_st: mut FireState) -> void { fire_apply(base_st, fire_st, fire_decide(fire_st, 3)) }
test "three logs light it, and that is a fact" {
fresh()
expect_eq(fire_decide(2), FIRE_NO_WOOD)
expect_eq(fire_decide(3), FIRE_LIGHT)
expect_eq(fire_cost(FIRE_LIGHT), 3)
light()
expect(fire_lit())
expect(fire_fuel() == 120.0)
expect_eq(count(facts(), FIRE_LIT), 1)
test "three logs light it, and that is a fact" (base_st: mut BaseState, fire_st: mut FireState) {
fresh(base_st, fire_st)
expect_eq(fire_decide(fire_st, 2), FIRE_NO_WOOD)
expect_eq(fire_decide(fire_st, 3), FIRE_LIGHT)
expect_eq(fire_cost(fire_st, FIRE_LIGHT), 3)
light(base_st, fire_st)
expect(fire_lit(fire_st))
expect(fire_fuel(fire_st) == 120.0)
expect_eq(count(facts(base_st, fire_st), FIRE_LIT), 1)
}
test "a lit fire takes a log for an hour" {
fresh()
light()
expect_eq(fire_decide(0), FIRE_NO_LOG)
expect_eq(fire_decide(1), FIRE_FEED)
expect_eq(fire_cost(FIRE_FEED), 1)
fire_apply(FIRE_FEED)
expect(fire_fuel() == 180.0)
test "a lit fire takes a log for an hour" (base_st: mut BaseState, fire_st: mut FireState) {
fresh(base_st, fire_st)
light(base_st, fire_st)
expect_eq(fire_decide(fire_st, 0), FIRE_NO_LOG)
expect_eq(fire_decide(fire_st, 1), FIRE_FEED)
expect_eq(fire_cost(fire_st, FIRE_FEED), 1)
fire_apply(base_st, fire_st, FIRE_FEED)
expect(fire_fuel(fire_st) == 180.0)
}
test "a ban and a soaked ring refuse, a tarp keeps it dry" {
fresh()
ban = true
expect_eq(fire_decide(5), FIRE_BANNED)
ban = false
wet = true
expect_eq(fire_decide(5), FIRE_SOAKED)
expect_eq(fire_cost(FIRE_SOAKED), 0)
tarp = true
expect_eq(fire_decide(5), FIRE_LIGHT)
test "a ban and a soaked ring refuse, a tarp keeps it dry" (base_st: mut BaseState, fire_st: mut FireState, firetest_st: mut FiretestState) {
fresh(base_st, fire_st)
firetest_st.ban = true
expect_eq(fire_decide(fire_st, 5), FIRE_BANNED)
firetest_st.ban = false
firetest_st.wet = true
expect_eq(fire_decide(fire_st, 5), FIRE_SOAKED)
expect_eq(fire_cost(fire_st, FIRE_SOAKED), 0)
firetest_st.tarp = true
expect_eq(fire_decide(fire_st, 5), FIRE_LIGHT)
}
test "it burns a minute a minute, runs low, and goes out as facts" {
fresh()
light()
facts()
fire_run(1.5)
expect(fire_fuel() == 30.0)
expect(not fire_low())
fire_run(0.3)
expect(fire_low())
expect_eq(count(facts(), FIRE_LOW_FUEL), 1)
fire_run(0.5)
expect(not fire_lit())
expect(fire_fuel() == 0.0)
expect_eq(count(facts(), FIRE_WENT_OUT), 1)
test "it burns a minute a minute, runs low, and goes out as facts" (base_st: mut BaseState, fire_st: mut FireState) {
fresh(base_st, fire_st)
light(base_st, fire_st)
facts(base_st, fire_st)
fire_run(base_st, fire_st, 1.5)
expect(fire_fuel(fire_st) == 30.0)
expect(not fire_low(fire_st))
fire_run(base_st, fire_st, 0.3)
expect(fire_low(fire_st))
expect_eq(count(facts(base_st, fire_st), FIRE_LOW_FUEL), 1)
fire_run(base_st, fire_st, 0.5)
expect(not fire_lit(fire_st))
expect(fire_fuel(fire_st) == 0.0)
expect_eq(count(facts(base_st, fire_st), FIRE_WENT_OUT), 1)
}
test "the rain burns it twice as fast, and under a tarp it counts the hours" {
fresh()
light()
wet = true
fire_run(0.5)
expect(fire_fuel() == 60.0)
tarp = true
fire_run(0.5)
expect(fire_fuel() == 30.0)
expect(fire_rain_hours() == 0.5)
fire_morning()
expect(fire_rain_hours() == 0.0)
test "the rain burns it twice as fast, and under a tarp it counts the hours" (base_st: mut BaseState, fire_st: mut FireState, firetest_st: mut FiretestState) {
fresh(base_st, fire_st)
light(base_st, fire_st)
firetest_st.wet = true
fire_run(base_st, fire_st, 0.5)
expect(fire_fuel(fire_st) == 60.0)
firetest_st.tarp = true
fire_run(base_st, fire_st, 0.5)
expect(fire_fuel(fire_st) == 30.0)
expect(fire_rain_hours(fire_st) == 0.5)
fire_morning(fire_st)
expect(fire_rain_hours(fire_st) == 0.0)
}
test "a machine that does not own the world burns nothing, but is told" {
fresh()
light()
owns = false
fire_run(5.0)
expect(fire_fuel() == 120.0)
facts()
fire_told(false, 0.0, true)
expect(not fire_lit())
expect_eq(count(facts(), FIRE_WENT_OUT), 1)
fire_told(true, 50.0, true)
fire_told(false, 0.0, false)
expect_eq(q_len(fire_facts()), 0)
test "a machine that does not own the world burns nothing, but is told" (base_st: mut BaseState, fire_st: mut FireState, firetest_st: mut FiretestState) {
fresh(base_st, fire_st)
light(base_st, fire_st)
firetest_st.owns = false
fire_run(base_st, fire_st, 5.0)
expect(fire_fuel(fire_st) == 120.0)
facts(base_st, fire_st)
fire_told(base_st, fire_st, false, 0.0, true)
expect(not fire_lit(fire_st))
expect_eq(count(facts(base_st, fire_st), FIRE_WENT_OUT), 1)
fire_told(base_st, fire_st, true, 50.0, true)
fire_told(base_st, fire_st, false, 0.0, false)
expect_eq(q_len(fire_facts(base_st, fire_st)), 0)
}
test "it warms and cooks close, and only while lit" {
fresh()
expect(not fire_warms(1.0))
light()
expect(fire_warms(3.5))
expect(not fire_warms(3.7))
expect(fire_cooks(3.4))
expect(not fire_cooks(3.55))
fire_out()
expect(not fire_cooks(0.0))
test "it warms and cooks close, and only while lit" (base_st: mut BaseState, fire_st: mut FireState) {
fresh(base_st, fire_st)
expect(not fire_warms(fire_st, 1.0))
light(base_st, fire_st)
expect(fire_warms(fire_st, 3.5))
expect(not fire_warms(fire_st, 3.7))
expect(fire_cooks(fire_st, 3.4))
expect(not fire_cooks(fire_st, 3.55))
fire_out(fire_st)
expect(not fire_cooks(fire_st, 0.0))
}
test "a save section reads back the same fire" {
fresh()
light()
wet = true
tarp = true
fire_run(0.25)
test "a save section reads back the same fire" (base_st: mut BaseState, fire_st: mut FireState, firetest_st: mut FiretestState) {
fresh(base_st, fire_st)
light(base_st, fire_st)
firetest_st.wet = true
firetest_st.tarp = true
fire_run(base_st, fire_st, 0.25)
let root = save_tree()
save_section(root, "fire", 1, fire_save())
save_section(root, "fire", 1, fire_save(fire_st))
let text = save_encode(root)
fire_reset()
fire_reset(base_st, fire_st)
let n = load_section(save_decode(text), "fire")
fire_load(n.data, n.version)
expect(fire_lit())
expect(fire_fuel() == 105.0)
expect(fire_rain_hours() == 0.25)
fire_load(base_st, fire_st, n.data, n.version)
expect(fire_lit(fire_st))
expect(fire_fuel(fire_st) == 105.0)
expect(fire_rain_hours(fire_st) == 0.25)
}
}

View file

@ -1,55 +1,55 @@
# verbs.ludic - the fire burning down, and the only other ways it changes
function fr_out() -> void {
fr_lit = false
fr_fuel = 0.0
fr_fact(FIRE_WENT_OUT)
function fr_out(base_st: mut BaseState, fire_st: mut FireState) -> void {
fire_st.fr_lit = false
fire_st.fr_fuel = 0.0
fr_fact(base_st, fire_st, FIRE_WENT_OUT)
}
# `gh` game hours of burning; in the rain it burns twice as fast with nothing over the ring,
# and under cover it counts the hours it held. Only the machine that owns the world burns it.
export function fire_run(gh: float) -> void {
if not fr_lit or not FireWorld.owns_world() { return }
let was = fr_fuel
fr_fuel = fr_fuel - gh * 60.0
export function fire_run(base_st: mut BaseState, fire_st: mut FireState, gh: float) -> void {
if not fire_st.fr_lit or not FireWorld.owns_world() { return }
let was = fire_st.fr_fuel
fire_st.fr_fuel = fire_st.fr_fuel - gh * 60.0
if FireWorld.is_wet() {
if FireWorld.sheltered() { fr_rain_h = fr_rain_h + gh } else { fr_fuel = fr_fuel - gh * 60.0 }
if FireWorld.sheltered() { fire_st.fr_rain_h = fire_st.fr_rain_h + gh } else { fire_st.fr_fuel = fire_st.fr_fuel - gh * 60.0 }
}
if fr_fuel < 0.0 {
fr_out()
if fire_st.fr_fuel < 0.0 {
fr_out(base_st, fire_st)
return
}
if was >= fr_low_minutes and fr_fuel < fr_low_minutes { fr_fact(FIRE_LOW_FUEL) }
if was >= fire_st.fr_low_minutes and fire_st.fr_fuel < fire_st.fr_low_minutes { fr_fact(base_st, fire_st, FIRE_LOW_FUEL) }
}
# put out, and nothing said (the night burns it down)
export function fire_out() -> void {
fr_lit = false
fr_fuel = 0.0
export function fire_out(fire_st: mut FireState) -> void {
fire_st.fr_lit = false
fire_st.fr_fuel = 0.0
}
# burning with `fuel` minutes, and nothing said (staging, a test)
export function fire_set_burning(fuel: float) -> void {
fr_lit = true
fr_fuel = fuel
export function fire_set_burning(fire_st: mut FireState, fuel: float) -> void {
fire_st.fr_lit = true
fire_st.fr_fuel = fuel
}
# what the machine that owns the world says the fire is; going out is a fact when `say`
export function fire_told(lit: bool, fuel: float, say: bool) -> void {
let was = fr_lit
fr_lit = lit
fr_fuel = fuel
if was and not lit and say { fr_fact(FIRE_WENT_OUT) }
export function fire_told(base_st: mut BaseState, fire_st: mut FireState, lit: bool, fuel: float, say: bool) -> void {
let was = fire_st.fr_lit
fire_st.fr_lit = lit
fire_st.fr_fuel = fuel
if was and not lit and say { fr_fact(base_st, fire_st, FIRE_WENT_OUT) }
}
# the rain hours outright (staging, a test)
export function fire_set_rain_hours(h: float) -> void { fr_rain_h = h }
export function fire_set_rain_hours(fire_st: mut FireState, h: float) -> void { fire_st.fr_rain_h = h }
# a new day: the rain hours start again
export function fire_morning() -> void { fr_rain_h = 0.0 }
export function fire_morning(fire_st: mut FireState) -> void { fire_st.fr_rain_h = 0.0 }
export function fire_reset() -> void {
fr_lit = false
fr_fuel = 0.0
fr_rain_h = 0.0
q_clear(fire_facts())
export function fire_reset(base_st: mut BaseState, fire_st: mut FireState) -> void {
fire_st.fr_lit = false
fire_st.fr_fuel = 0.0
fire_st.fr_rain_h = 0.0
q_clear(base_st, fire_facts(base_st, fire_st))
}