ludic/packages/ludic.wildlife/tests/drink_pins_test.ludic
Orkuncakilkaya 67d477af77 ludic.wildlife: pin every transition of the 15 WILD_* states and the dice each draws (phase 27.2a)
Sixteen test programs under tests/*_pins_test.ludic, on today's code, each one tick from a set
state through the public step (wildlife_tick_ground / _bird / wildlife_tick, wildlife_release,
wildlife_new): the state it goes to, its timer, and how many of the package's rolls it took and
which (the next roll is read off a newborn's yaw, compared with a stream of the same seed). IDLE,
WANDER, ALERT, WARY, FLEE, CHARGE, GO_DRINK, GO_FEED, DRINK, APPROACH, EAT, TRAPPED, FLY, LAND,
PERCH; the droppings' roll before them; the newborn's seven (eight for a bird); what the step
leaves alone. tests/pin/ holds the shared step, the dice reader and two species of its own (a tame
horse, a crow that never lands on its own). Compiled, not run here: 27.2 holds to them unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-30 16:57:15 +03:00

80 lines
3.1 KiB
Text

# drink_pins_test.ludic - phase 27.2a: DRINK as it stands. It drinks (a water spot) or grazes at
# 600 a game hour, its timer run down twice a tick; its time up - or EITHER need under 1, not only
# the one it is meeting - it takes home where it stands and wanders 6 s toward (r0, r1)
import "ludic.wildlife"
import "ludic.base"
import "fake"
import "pin"
program DrinkPins {
numbers float
bind WildlifeWorld {
ground: fn fk_ground
water: fn fk_water
players: fn fk_players
player_on: fn fk_player_on
player_x: fn fk_x
player_y: fn fk_y
player_z: fn fk_z
about: fn fk_about_of
lures: fn fk_count
lure: fn fk_lure
present: fn fk_present
spot: fn pn_spot
taught: fn pn_taught
}
function drinking(wildlife_st: mut WildlifeState, water: bool, thirst: float, hunger: float, timer: float) -> WildAnimal {
let a = pn_at(wildlife_st, 2, 3.0, 0.0, WILD_DRINK, timer)
a.spot = 900
a.spot_water = water
a.thirst = thirst
a.hunger = hunger
wildlife_seed(wildlife_st, 10)
pn_step(wildlife_st, a)
return a
}
test "DRINK at water: thirst down 600 a game hour, the timer 2 dt a tick, no roll" (wildlife_st: mut WildlifeState, wildlife_tests_fake_st: mut WildlifeTestsFakeState) {
pn_setup(wildlife_st, wildlife_tests_fake_st)
let a = drinking(wildlife_st, true, 50.0, 50.0, 5.0)
expect_eq(a.state, WILD_DRINK)
expect_near(a.timer, 4.9, 0.0001)
expect_near(a.speed, 0.0, 0.00001)
expect_near(a.thirst, 50.0 + 12.0 * 0.05 / 60.0 - 0.5, 0.0001)
expect_near(a.hunger, 50.0 + 5.0 * 0.05 / 60.0, 0.0001)
expect_eq(pn_drew(wildlife_st, 10), 0)
}
test "DRINK at forage grazes hunger down instead" (wildlife_st: mut WildlifeState, wildlife_tests_fake_st: mut WildlifeTestsFakeState) {
pn_setup(wildlife_st, wildlife_tests_fake_st)
let a = drinking(wildlife_st, false, 50.0, 50.0, 5.0)
expect_near(a.hunger, 50.0 + 5.0 * 0.05 / 60.0 - 0.5, 0.0001)
expect_near(a.thirst, 50.0 + 12.0 * 0.05 / 60.0, 0.0001)
}
test "DRINK, its time up: home where it stands, WANDER 6 s toward (r0, r1), two rolls" (wildlife_st: mut WildlifeState, wildlife_tests_fake_st: mut WildlifeTestsFakeState) {
pn_setup(wildlife_st, wildlife_tests_fake_st)
let b = pn_at(wildlife_st, 2, 3.0, 0.0, WILD_DRINK, 0.05)
b.spot = 900
b.spot_water = true
b.home_x = 50.0
b.thirst = 50.0
b.hunger = 50.0
wildlife_seed(wildlife_st, 10)
pn_step(wildlife_st, b)
expect_eq(b.state, WILD_WANDER)
expect_near(b.timer, 6.0, 0.0001)
expect_near(b.home_x, 3.0, 0.0001)
expect_near(b.tx, pn_tx(b, 10, 0, 60.0), 0.001)
expect_near(b.tz, pn_tz(b, 10, 0, 60.0), 0.001)
expect_eq(pn_drew(wildlife_st, 10), 2)
}
test "DRINK at water with hunger under 1: it leaves thirsty, WANDER 6 s, two rolls" (wildlife_st: mut WildlifeState, wildlife_tests_fake_st: mut WildlifeTestsFakeState) {
pn_setup(wildlife_st, wildlife_tests_fake_st)
let a = drinking(wildlife_st, true, 80.0, 0.0, 5.0)
expect_eq(a.state, WILD_WANDER)
expect(a.thirst > 79.0)
expect_eq(pn_drew(wildlife_st, 10), 2)
}
}