fix(ludic.fishing): fact records pooled (the ludic.wildlife idiom) - a record made per cast, bite and crossing was never given back
tests: fifty fish, their facts drained each time, make 5 records. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
968030535e
commit
36358e7a43
4 changed files with 41 additions and 2 deletions
19
packages/ludic.fishing/facts.ludic
Normal file
19
packages/ludic.fishing/facts.ludic
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
# facts.ludic - a fishing fact's record: one no drain holds any more, made fresh (and kept) only when
|
||||||
|
# every one is held. A cast, a bite, every crossing and run of a fight is a fact, and a record a fact
|
||||||
|
# is never given back (the ludic.wildlife idiom, facts.ludic there)
|
||||||
|
function fishing_fact_record(fishing_st: mut FishingState) -> FishingFact {
|
||||||
|
if fishing_st.fishing_fnext[0] >= len(fishing_st.fishing_ffree) {
|
||||||
|
q_unheld(fishing_st.fishing_fact_q, fishing_st.fishing_fpool, fishing_st.fishing_ffree)
|
||||||
|
fishing_st.fishing_fnext[0] = 0
|
||||||
|
}
|
||||||
|
if fishing_st.fishing_fnext[0] < len(fishing_st.fishing_ffree) {
|
||||||
|
let f = fishing_st.fishing_ffree[fishing_st.fishing_fnext[0]]
|
||||||
|
fishing_st.fishing_fnext[0] += 1
|
||||||
|
return f
|
||||||
|
}
|
||||||
|
let f = new FishingFact
|
||||||
|
push(fishing_st.fishing_fpool, f)
|
||||||
|
return f
|
||||||
|
}
|
||||||
|
# how many fact records have ever been made: the peak held at once, not the facts said
|
||||||
|
export function fishing_fact_records(fishing_st: FishingState) -> int { return len(fishing_st.fishing_fpool) }
|
||||||
|
|
@ -6,6 +6,7 @@ import "ludic.base"
|
||||||
import "kinds.ludic"
|
import "kinds.ludic"
|
||||||
import "ports.ludic"
|
import "ports.ludic"
|
||||||
import "state.ludic"
|
import "state.ludic"
|
||||||
|
import "facts.ludic"
|
||||||
import "fight.ludic"
|
import "fight.ludic"
|
||||||
import "verbs.ludic"
|
import "verbs.ludic"
|
||||||
import "run.ludic"
|
import "run.ludic"
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,9 @@ export state FishingState {
|
||||||
fishing_run_next: float = 0.0
|
fishing_run_next: float = 0.0
|
||||||
fishing_dice: Rng = null
|
fishing_dice: Rng = null
|
||||||
fishing_fact_q: Queue<FishingFact> = fishing_fact_q__new()
|
fishing_fact_q: Queue<FishingFact> = fishing_fact_q__new()
|
||||||
|
fishing_fpool: []FishingFact = new []FishingFact # every fact record made, reused once no drain holds it (facts.ludic)
|
||||||
|
fishing_ffree: []FishingFact = new []FishingFact
|
||||||
|
fishing_fnext: []int = words(1)
|
||||||
fishing_n: int = 0 # the record: caught, the biggest (cm), a legend landed
|
fishing_n: int = 0 # the record: caught, the biggest (cm), a legend landed
|
||||||
fishing_big: int = 0
|
fishing_big: int = 0
|
||||||
fishing_leg: bool = false
|
fishing_leg: bool = false
|
||||||
|
|
@ -51,8 +54,8 @@ function fishing_rand(fishing_st: mut FishingState) -> float {
|
||||||
return rng_float(fishing_st.fishing_dice)
|
return rng_float(fishing_st.fishing_dice)
|
||||||
}
|
}
|
||||||
|
|
||||||
function fishing_say(fishing_st: FishingState, what: int) -> void {
|
function fishing_say(fishing_st: mut FishingState, what: int) -> void {
|
||||||
let f = new FishingFact
|
let f = fishing_fact_record(fishing_st)
|
||||||
f.what = what
|
f.what = what
|
||||||
f.species = fishing_st.fishing_sp
|
f.species = fishing_st.fishing_sp
|
||||||
f.cm = fishing_st.fishing_len
|
f.cm = fishing_st.fishing_len
|
||||||
|
|
|
||||||
|
|
@ -254,4 +254,20 @@ program FishingTest {
|
||||||
expect(fishing_legend_caught(fishing_st))
|
expect(fishing_legend_caught(fishing_st))
|
||||||
expect(not fishing_active(fishing_st))
|
expect(not fishing_active(fishing_st))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test "fifty fish, their facts drained each time, reuse a handful of records" (fishing_st: mut FishingState, fishing_test_st: mut FishingTestState) {
|
||||||
|
fresh(fishing_st, fishing_test_st)
|
||||||
|
for k in 0 .. 50 {
|
||||||
|
fishing_cast(fishing_st, 20.0, 0.0)
|
||||||
|
facts(fishing_st)
|
||||||
|
hook(fishing_st)
|
||||||
|
facts(fishing_st)
|
||||||
|
play(fishing_st, 12)
|
||||||
|
facts(fishing_st)
|
||||||
|
fishing_stop(fishing_st)
|
||||||
|
facts(fishing_st)
|
||||||
|
}
|
||||||
|
print(`fishing: 50 fish, {fishing_fact_records(fishing_st)} fact records made`)
|
||||||
|
expect(fishing_fact_records(fishing_st) < 30)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue