wip(0.S3): packages and examples migrated again from their pre-0.S sources in one run
ludic migrate state packages <every example program> packages/ludic.lab/example/plate.ludic 1804 vars into 126 states, 64 into lets; 23498 edits in 460 files Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
5ffe50ed02
commit
19fcf60599
459 changed files with 17862 additions and 17603 deletions
|
|
@ -17,147 +17,149 @@ program GearTest {
|
|||
def GearCharges lamp { item: IT_LAMP, full: 100.0, rate: GV_DRAIN }
|
||||
def GearCharges radio { item: 9, full: 100.0, per_hour: 5.0, hand: false }
|
||||
|
||||
var money: int = 0
|
||||
var rep: int = 0
|
||||
var pack: []int = null
|
||||
var hide_pack: bool = false
|
||||
state GearTestState {
|
||||
money: int = 0
|
||||
rep: int = 0
|
||||
pack: []int = null
|
||||
hide_pack: bool = false
|
||||
}
|
||||
|
||||
function purse_money() -> int { return money }
|
||||
function purse_spend(n: int) -> bool {
|
||||
if n > money { return false }
|
||||
money -= n
|
||||
function purse_money(gear_test_st: GearTestState) -> int { return gear_test_st.money }
|
||||
function purse_spend(gear_test_st: mut GearTestState, n: int) -> bool {
|
||||
if n > gear_test_st.money { return false }
|
||||
gear_test_st.money -= n
|
||||
return true
|
||||
}
|
||||
function purse_rep() -> int { return rep }
|
||||
function pack_count(it: int) -> int { return pack[it] }
|
||||
function pack_add(it: int, n: int) -> int {
|
||||
pack[it] = pack[it] + n
|
||||
function purse_rep(gear_test_st: GearTestState) -> int { return gear_test_st.rep }
|
||||
function pack_count(gear_test_st: GearTestState, it: int) -> int { return gear_test_st.pack[it] }
|
||||
function pack_add(gear_test_st: mut GearTestState, it: int, n: int) -> int {
|
||||
gear_test_st.pack[it] = gear_test_st.pack[it] + n
|
||||
return n
|
||||
}
|
||||
function hidden(k: int) -> bool { return hide_pack and k == GEAR_PACK }
|
||||
function hidden(gear_test_st: GearTestState, k: int) -> bool { return gear_test_st.hide_pack and k == GEAR_PACK }
|
||||
|
||||
bind GearPurse { money: fn purse_money, spend: fn purse_spend, rep: fn purse_rep }
|
||||
bind GearPack { count: fn pack_count, add: fn pack_add }
|
||||
bind GearWorld { hidden: fn hidden }
|
||||
|
||||
function fresh() -> void {
|
||||
money = 0
|
||||
rep = 0
|
||||
hide_pack = false
|
||||
pack = new []int
|
||||
for i in 0 .. 12 { push(pack, 0) }
|
||||
gear_reset()
|
||||
function fresh(base_st: mut BaseState, gear_st: mut GearState, gear_test_st: mut GearTestState) -> void {
|
||||
gear_test_st.money = 0
|
||||
gear_test_st.rep = 0
|
||||
gear_test_st.hide_pack = false
|
||||
gear_test_st.pack = new []int
|
||||
for i in 0 .. 12 { push(gear_test_st.pack, 0) }
|
||||
gear_reset(base_st, gear_st)
|
||||
}
|
||||
|
||||
function ran_out() -> int {
|
||||
let fs = q_drain(gear_facts())
|
||||
function ran_out(base_st: mut BaseState, gear_st: mut GearState) -> int {
|
||||
let fs = q_drain(base_st, gear_facts(base_st, gear_st))
|
||||
var n = -1
|
||||
for i in 0 .. len(fs) { if fs[i].what == GEAR_RAN_OUT { n = fs[i].charge } }
|
||||
return n
|
||||
}
|
||||
|
||||
test "a new trip starts where the kinds say" {
|
||||
fresh()
|
||||
expect_eq(gear_level(GEAR_ROD), 0)
|
||||
expect_eq(gear_level(GEAR_CAMERA), 1)
|
||||
expect(gear_next_name(GEAR_CAMERA) == "Zoom")
|
||||
expect_eq(gear_next_cost(GEAR_ROD), 30)
|
||||
test "a new trip starts where the kinds say" (base_st: mut BaseState, gear_st: mut GearState, gear_test_st: mut GearTestState) {
|
||||
fresh(base_st, gear_st, gear_test_st)
|
||||
expect_eq(gear_level(gear_st, GEAR_ROD), 0)
|
||||
expect_eq(gear_level(gear_st, GEAR_CAMERA), 1)
|
||||
expect(gear_next_name(gear_st, GEAR_CAMERA) == "Zoom")
|
||||
expect_eq(gear_next_cost(gear_st, GEAR_ROD), 30)
|
||||
}
|
||||
|
||||
test "bought with money once the standing is there, and the item follows" {
|
||||
fresh()
|
||||
expect(not gear_buy(GEAR_ROD))
|
||||
money = 200
|
||||
expect(gear_buy(GEAR_ROD))
|
||||
expect_eq(money, 170)
|
||||
expect_eq(pack[IT_ROD], 1)
|
||||
expect(not gear_can_buy(GEAR_ROD))
|
||||
rep = 10
|
||||
expect(gear_buy(GEAR_ROD))
|
||||
expect_eq(pack[IT_ROD], 1)
|
||||
let fs = q_drain(gear_facts())
|
||||
test "bought with money once the standing is there, and the item follows" (base_st: mut BaseState, gear_st: mut GearState, gear_test_st: mut GearTestState) {
|
||||
fresh(base_st, gear_st, gear_test_st)
|
||||
expect(not gear_buy(base_st, gear_st, GEAR_ROD))
|
||||
gear_test_st.money = 200
|
||||
expect(gear_buy(base_st, gear_st, GEAR_ROD))
|
||||
expect_eq(gear_test_st.money, 170)
|
||||
expect_eq(gear_test_st.pack[IT_ROD], 1)
|
||||
expect(not gear_can_buy(gear_st, GEAR_ROD))
|
||||
gear_test_st.rep = 10
|
||||
expect(gear_buy(base_st, gear_st, GEAR_ROD))
|
||||
expect_eq(gear_test_st.pack[IT_ROD], 1)
|
||||
let fs = q_drain(base_st, gear_facts(base_st, gear_st))
|
||||
expect_eq(len(fs), 2)
|
||||
expect_eq(fs[1].what, GEAR_BOUGHT)
|
||||
expect_eq(fs[1].level, 2)
|
||||
expect_eq(fs[1].cost, 100)
|
||||
}
|
||||
|
||||
test "the best tier is the end, and a hidden kind is not for sale" {
|
||||
fresh()
|
||||
money = 1000
|
||||
rep = 50
|
||||
for i in 0 .. 5 { gear_buy(GEAR_PACK) }
|
||||
expect(gear_best(GEAR_PACK))
|
||||
expect_eq(gear_level(GEAR_PACK), 3)
|
||||
fresh()
|
||||
money = 100
|
||||
hide_pack = true
|
||||
expect(not gear_buy(GEAR_PACK))
|
||||
test "the best tier is the end, and a hidden kind is not for sale" (base_st: mut BaseState, gear_st: mut GearState, gear_test_st: mut GearTestState) {
|
||||
fresh(base_st, gear_st, gear_test_st)
|
||||
gear_test_st.money = 1000
|
||||
gear_test_st.rep = 50
|
||||
for i in 0 .. 5 { gear_buy(base_st, gear_st, GEAR_PACK) }
|
||||
expect(gear_best(gear_st, GEAR_PACK))
|
||||
expect_eq(gear_level(gear_st, GEAR_PACK), 3)
|
||||
fresh(base_st, gear_st, gear_test_st)
|
||||
gear_test_st.money = 100
|
||||
gear_test_st.hide_pack = true
|
||||
expect(not gear_buy(base_st, gear_st, GEAR_PACK))
|
||||
expect_eq(len(gear_kinds_at(-1)), 2)
|
||||
}
|
||||
|
||||
test "a tier decides a value and a mult, and the stack's room follows" {
|
||||
fresh()
|
||||
expect_eq(gear_value(GV_BITE), 1.0)
|
||||
gear_set_level(GEAR_ROD, 3)
|
||||
expect_eq(gear_value(GV_BITE), 0.55)
|
||||
expect_eq(gear_mult(GEAR_PACK), 1.0)
|
||||
gear_set_level(GEAR_PACK, 2)
|
||||
expect_eq(gear_mult(GEAR_PACK), 1.7)
|
||||
expect_eq(gear_stack_limit(10, gear_mult(GEAR_PACK)), 17)
|
||||
test "a tier decides a value and a mult, and the stack's room follows" (base_st: mut BaseState, gear_st: mut GearState, gear_test_st: mut GearTestState) {
|
||||
fresh(base_st, gear_st, gear_test_st)
|
||||
expect_eq(gear_value(gear_st, GV_BITE), 1.0)
|
||||
gear_set_level(gear_st, GEAR_ROD, 3)
|
||||
expect_eq(gear_value(gear_st, GV_BITE), 0.55)
|
||||
expect_eq(gear_mult(gear_st, GEAR_PACK), 1.0)
|
||||
gear_set_level(gear_st, GEAR_PACK, 2)
|
||||
expect_eq(gear_mult(gear_st, GEAR_PACK), 1.7)
|
||||
expect_eq(gear_stack_limit(10, gear_mult(gear_st, GEAR_PACK)), 17)
|
||||
expect_eq(gear_stack_limit(1, 3.0), 1)
|
||||
expect_eq(gear_stack_limit(4, 0.1), 1)
|
||||
expect_eq(gear_mult(GEAR_ROD), 1.0)
|
||||
expect_eq(gear_mult(gear_st, GEAR_ROD), 1.0)
|
||||
}
|
||||
|
||||
test "a carried item counts as the first tier" {
|
||||
fresh()
|
||||
pack[IT_ROD] = 1
|
||||
gear_sync()
|
||||
expect_eq(gear_level(GEAR_ROD), 1)
|
||||
test "a carried item counts as the first tier" (base_st: mut BaseState, gear_st: mut GearState, gear_test_st: mut GearTestState) {
|
||||
fresh(base_st, gear_st, gear_test_st)
|
||||
gear_test_st.pack[IT_ROD] = 1
|
||||
gear_sync(gear_st)
|
||||
expect_eq(gear_level(gear_st, GEAR_ROD), 1)
|
||||
}
|
||||
|
||||
test "a held charge runs only in the hand, burns by the hour and runs out" {
|
||||
fresh()
|
||||
test "a held charge runs only in the hand, burns by the hour and runs out" (base_st: mut BaseState, gear_st: mut GearState, gear_test_st: mut GearTestState) {
|
||||
fresh(base_st, gear_st, gear_test_st)
|
||||
let t = CHARGE_TORCH
|
||||
expect(not gear_run(t, true))
|
||||
gear_set_hand(IT_TORCH)
|
||||
expect(gear_run(t, true))
|
||||
expect(gear_lit())
|
||||
expect(not gear_run(gear_st, t, true))
|
||||
gear_set_hand(gear_st, IT_TORCH)
|
||||
expect(gear_run(gear_st, t, true))
|
||||
expect(gear_lit(gear_st))
|
||||
gear_system().tick(tick_new(0.1, 1, 0.5))
|
||||
expect_eq(gear_charge(t), 30.0)
|
||||
expect_eq(gear_charge(gear_st, t), 30.0)
|
||||
gear_system().tick(tick_new(0.1, 2, 0.6))
|
||||
expect_eq(gear_charge(t), 0.0)
|
||||
expect(not gear_lit())
|
||||
expect_eq(ran_out(), t)
|
||||
expect(not gear_run(t, true))
|
||||
expect_eq(gear_charge(gear_st, t), 0.0)
|
||||
expect(not gear_lit(gear_st))
|
||||
expect_eq(ran_out(base_st, gear_st), t)
|
||||
expect(not gear_run(gear_st, t, true))
|
||||
}
|
||||
|
||||
test "a charge's rate can be its tier's, and a new hand puts the light out" {
|
||||
fresh()
|
||||
gear_set_hand(IT_LAMP)
|
||||
gear_run(CHARGE_LAMP, true)
|
||||
test "a charge's rate can be its tier's, and a new hand puts the light out" (base_st: mut BaseState, gear_st: mut GearState, gear_test_st: mut GearTestState) {
|
||||
fresh(base_st, gear_st, gear_test_st)
|
||||
gear_set_hand(gear_st, IT_LAMP)
|
||||
gear_run(gear_st, CHARGE_LAMP, true)
|
||||
gear_system().tick(tick_new(0.1, 1, 1.0))
|
||||
expect_eq(gear_charge(CHARGE_LAMP), 86.0)
|
||||
gear_set_level(GEAR_CAMERA, 2)
|
||||
expect_eq(gear_charge(gear_st, CHARGE_LAMP), 86.0)
|
||||
gear_set_level(gear_st, GEAR_CAMERA, 2)
|
||||
gear_system().tick(tick_new(0.1, 2, 1.0))
|
||||
expect_eq(gear_charge(CHARGE_LAMP), 78.0)
|
||||
gear_run(CHARGE_RADIO, true)
|
||||
gear_set_hand(-1)
|
||||
expect(not gear_running(CHARGE_LAMP))
|
||||
expect(gear_running(CHARGE_RADIO))
|
||||
expect_eq(gear_charge(gear_st, CHARGE_LAMP), 78.0)
|
||||
gear_run(gear_st, CHARGE_RADIO, true)
|
||||
gear_set_hand(gear_st, -1)
|
||||
expect(not gear_running(gear_st, CHARGE_LAMP))
|
||||
expect(gear_running(gear_st, CHARGE_RADIO))
|
||||
}
|
||||
|
||||
test "levels and charges are saved by key" {
|
||||
fresh()
|
||||
gear_set_level(GEAR_ROD, 2)
|
||||
gear_charge_set(CHARGE_TORCH, 12.5)
|
||||
let v = gear_save()
|
||||
fresh()
|
||||
gear_load(v, 1)
|
||||
expect_eq(gear_level(GEAR_ROD), 2)
|
||||
expect_eq(gear_level(GEAR_CAMERA), 1)
|
||||
expect_eq(gear_charge(CHARGE_TORCH), 12.5)
|
||||
expect_eq(gear_charge(CHARGE_LAMP), 100.0)
|
||||
test "levels and charges are saved by key" (base_st: mut BaseState, gear_st: mut GearState, gear_test_st: mut GearTestState) {
|
||||
fresh(base_st, gear_st, gear_test_st)
|
||||
gear_set_level(gear_st, GEAR_ROD, 2)
|
||||
gear_charge_set(gear_st, CHARGE_TORCH, 12.5)
|
||||
let v = gear_save(gear_st)
|
||||
fresh(base_st, gear_st, gear_test_st)
|
||||
gear_load(base_st, gear_st, v, 1)
|
||||
expect_eq(gear_level(gear_st, GEAR_ROD), 2)
|
||||
expect_eq(gear_level(gear_st, GEAR_CAMERA), 1)
|
||||
expect_eq(gear_charge(gear_st, CHARGE_TORCH), 12.5)
|
||||
expect_eq(gear_charge(gear_st, CHARGE_LAMP), 100.0)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue