feat(ludic.steps): chapters of steps, their kinds, progress and a party's pooled shares
A step is (kind, param, need) and a question about state: a kind has a
shape (yes, a count, a mask counted, every bit of a mask) and a pool
(world, any, sum, or, max, each), handed in by the game as StepsKind
records. An arc is chapters of up to STEPS_PER_CHAPTER steps; steps_check
sticks each met step of the current chapter (STEPS_MET) and opens the
next when all are (STEPS_CHAPTER), so a step met before its chapter
ticks at once. With company each seat's shares are held per chapter,
pooled as the kind says (steps_met, steps_party_got), counted for an
EACH step (steps_each, steps_lacking), and a leaver takes theirs along.
Port: StepsWorld { value(kind, param, player) (required), party,
present }. The package knows no kind's meaning and no chapter's words.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
4318adc98c
commit
31e6740033
10 changed files with 719 additions and 0 deletions
224
packages/ludic.steps/tests/steps_test.ludic
Normal file
224
packages/ludic.steps/tests/steps_test.ludic
Normal file
|
|
@ -0,0 +1,224 @@
|
|||
# steps_test.ludic - shapes answered from a fake world, an arc that ticks and moves on, and a party
|
||||
# whose shares pool as each kind says
|
||||
import "ludic.steps"
|
||||
import "ludic.base"
|
||||
program StepsTest {
|
||||
numbers float
|
||||
var vals: []int = null # value of kind k for this machine
|
||||
var party: bool = false
|
||||
var seats: int = 1 # seats 0 .. seats-1 are taken
|
||||
|
||||
function fake_value(kind: int, param: int, player: int) -> int {
|
||||
if player != 0 or kind < 0 or kind >= len(vals) { return 0 }
|
||||
return vals[kind]
|
||||
}
|
||||
function fake_party() -> bool { return party }
|
||||
function fake_present(p: int) -> bool { return p < seats }
|
||||
|
||||
bind StepsWorld { value: fn fake_value, party: fn fake_party, present: fn fake_present }
|
||||
|
||||
const K_WOOD: int = 0 # count, summed
|
||||
const K_SIGNS: int = 1 # mask counted, or'd
|
||||
const K_ALL: int = 2 # every bit of param, or'd
|
||||
const K_FIRE: int = 3 # yes, anyone
|
||||
const K_REP: int = 4 # count, best of
|
||||
const K_COMPASS: int = 5 # yes, each
|
||||
const K_HOUR: int = 6 # yes, the world's
|
||||
|
||||
function kind(shape: int, pool: int, shows: bool) -> StepsKind {
|
||||
let k = new StepsKind
|
||||
k.shape = shape
|
||||
k.pool = pool
|
||||
k.shows = shows
|
||||
return k
|
||||
}
|
||||
|
||||
function fresh() -> void {
|
||||
steps_reset()
|
||||
steps_config(4)
|
||||
party = false
|
||||
seats = 1
|
||||
vals = new []int
|
||||
for i in 0 .. 7 { push(vals, 0) }
|
||||
let ks = new []StepsKind
|
||||
push(ks, kind(STEPS_SHAPE_COUNT, STEPS_POOL_SUM, true))
|
||||
push(ks, kind(STEPS_SHAPE_MASK, STEPS_POOL_OR, true))
|
||||
push(ks, kind(STEPS_SHAPE_MASK_ALL, STEPS_POOL_OR, true))
|
||||
push(ks, kind(STEPS_SHAPE_YES, STEPS_POOL_ANY, false))
|
||||
push(ks, kind(STEPS_SHAPE_COUNT, STEPS_POOL_MAX, true))
|
||||
push(ks, kind(STEPS_SHAPE_YES, STEPS_POOL_EACH, false))
|
||||
push(ks, kind(STEPS_SHAPE_YES, STEPS_POOL_WORLD, false))
|
||||
steps_kinds(ks)
|
||||
}
|
||||
|
||||
# chapter 0: 5 wood, a fire; chapter 1: two signs, the compass
|
||||
function two_chapters() -> void {
|
||||
steps_chapter_add()
|
||||
steps_add(K_WOOD, 0, 5)
|
||||
steps_add(K_FIRE, 0, 1)
|
||||
steps_chapter_add()
|
||||
steps_add(K_SIGNS, 0, 2)
|
||||
steps_add(K_COMPASS, 0, 1)
|
||||
}
|
||||
|
||||
function facts_of(what: int) -> int {
|
||||
let fs = q_drain(steps_facts())
|
||||
var n = 0
|
||||
for i in 0 .. len(fs) { if fs[i].what == what { n += 1 } }
|
||||
return n
|
||||
}
|
||||
|
||||
function shares(a: int, b: int) -> []int {
|
||||
let s = new []int
|
||||
push(s, a)
|
||||
push(s, b)
|
||||
return s
|
||||
}
|
||||
|
||||
test "a step is answered by its kind's shape" {
|
||||
fresh()
|
||||
vals[K_WOOD] = 4
|
||||
expect(not steps_eval(K_WOOD, 0, 5))
|
||||
vals[K_WOOD] = 5
|
||||
expect(steps_eval(K_WOOD, 0, 5))
|
||||
vals[K_SIGNS] = 5
|
||||
expect(steps_eval(K_SIGNS, 0, 2))
|
||||
expect_eq(steps_got(K_SIGNS, 0), 2)
|
||||
vals[K_ALL] = 3
|
||||
expect(not steps_eval(K_ALL, 7, 0))
|
||||
expect_eq(steps_got(K_ALL, 7), 2)
|
||||
expect_eq(steps_want(K_ALL, 7, 0), 3)
|
||||
expect_eq(steps_got(K_FIRE, 0), -1)
|
||||
}
|
||||
|
||||
test "an arc's steps stick as they are met, and a full chapter opens the next" {
|
||||
fresh()
|
||||
two_chapters()
|
||||
expect_eq(steps_count(), 2)
|
||||
expect_eq(steps_in(1), 2)
|
||||
vals[K_FIRE] = 1
|
||||
steps_check()
|
||||
expect(steps_done(1))
|
||||
expect(not steps_done(0))
|
||||
expect_eq(facts_of(STEPS_MET), 1)
|
||||
vals[K_FIRE] = 0
|
||||
steps_check()
|
||||
expect(steps_done(1))
|
||||
vals[K_WOOD] = 9
|
||||
steps_check()
|
||||
expect_eq(steps_current(), 1)
|
||||
expect_eq(steps_done_mask(), 0)
|
||||
let fs = q_drain(steps_facts())
|
||||
expect_eq(len(fs), 2)
|
||||
expect_eq(fs[1].what, STEPS_CHAPTER)
|
||||
expect_eq(fs[1].chapter, 0)
|
||||
}
|
||||
|
||||
test "a step met before its chapter opens ticks the moment it is looked at" {
|
||||
fresh()
|
||||
two_chapters()
|
||||
vals[K_SIGNS] = 3
|
||||
vals[K_COMPASS] = 1
|
||||
vals[K_WOOD] = 5
|
||||
vals[K_FIRE] = 1
|
||||
steps_check()
|
||||
expect_eq(steps_current(), 1)
|
||||
steps_check()
|
||||
expect(steps_finished())
|
||||
}
|
||||
|
||||
test "a chapter holds at most six steps" {
|
||||
fresh()
|
||||
expect(not steps_add(K_WOOD, 0, 1))
|
||||
steps_chapter_add()
|
||||
for i in 0 .. STEPS_PER_CHAPTER { expect(steps_add(K_WOOD, 0, i)) }
|
||||
expect(not steps_add(K_WOOD, 0, 9))
|
||||
}
|
||||
|
||||
test "the steps asked for right now" {
|
||||
fresh()
|
||||
two_chapters()
|
||||
expect(steps_wants(K_FIRE, -1))
|
||||
expect(not steps_wants(K_SIGNS, -1))
|
||||
}
|
||||
|
||||
test "a tally adds up across the party, and a mask unions" {
|
||||
fresh()
|
||||
two_chapters()
|
||||
party = true
|
||||
seats = 2
|
||||
vals[K_WOOD] = 3
|
||||
expect(not steps_met(0))
|
||||
steps_share(1, 0, shares(2, 0))
|
||||
expect(steps_met(0))
|
||||
expect_eq(steps_party_got(0), 5)
|
||||
steps_set_current(1)
|
||||
vals[K_SIGNS] = 1
|
||||
steps_share(1, 1, shares(2, 0))
|
||||
expect(steps_met(0))
|
||||
}
|
||||
|
||||
test "anyone having done it is the party having done it" {
|
||||
fresh()
|
||||
two_chapters()
|
||||
party = true
|
||||
seats = 3
|
||||
steps_share(2, 0, shares(0, 1))
|
||||
expect(steps_met(1))
|
||||
}
|
||||
|
||||
test "a thing in the pack is met when every player has one, and says who has not" {
|
||||
fresh()
|
||||
two_chapters()
|
||||
steps_set_current(1)
|
||||
party = true
|
||||
seats = 3
|
||||
vals[K_COMPASS] = 1
|
||||
steps_share(1, 1, shares(0, 1))
|
||||
expect(not steps_met(1))
|
||||
expect_eq(steps_each(1), 2)
|
||||
let lack = steps_lacking(1)
|
||||
expect_eq(len(lack), 1)
|
||||
expect_eq(lack[0], 2)
|
||||
steps_share(2, 1, shares(0, 1))
|
||||
expect(steps_met(1))
|
||||
}
|
||||
|
||||
test "a player who leaves takes their share with them" {
|
||||
fresh()
|
||||
two_chapters()
|
||||
party = true
|
||||
seats = 2
|
||||
steps_share(1, 0, shares(5, 0))
|
||||
expect(steps_met(0))
|
||||
steps_leave(1)
|
||||
expect(not steps_met(0))
|
||||
}
|
||||
|
||||
test "a share about another chapter is ignored, and the best of a tally is the best" {
|
||||
fresh()
|
||||
steps_chapter_add()
|
||||
steps_add(K_REP, 0, 25)
|
||||
party = true
|
||||
seats = 2
|
||||
steps_share(1, 3, shares(99, 0))
|
||||
expect(not steps_met(0))
|
||||
vals[K_REP] = 10
|
||||
steps_share(1, 0, shares(30, 0))
|
||||
expect(steps_met(0))
|
||||
expect_eq(steps_party_got(0), 30)
|
||||
}
|
||||
|
||||
test "the world's steps are asked of this machine alone" {
|
||||
fresh()
|
||||
steps_chapter_add()
|
||||
steps_add(K_HOUR, 0, 1)
|
||||
party = true
|
||||
seats = 2
|
||||
steps_share(1, 0, shares(1, 0))
|
||||
expect(not steps_met(0))
|
||||
vals[K_HOUR] = 1
|
||||
expect(steps_met(0))
|
||||
expect_eq(steps_mine(K_HOUR, 0, 1), 0)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue