# seek_pins_test.ludic - phase 27.2a: IDLE and WANDER going to water or forage as they stand. Thirst # or hunger over 60 asks the world for a spot - water when thirst is the greater, forage on a tie - # and sets off (GO_DRINK / GO_FEED, 120 s) whatever its timer; no spot, no change; no roll either way import "ludic.wildlife" import "ludic.base" import "fake" import "pin" program SeekPins { 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 needy(wildlife_st: mut WildlifeState, state: int, thirst: float, hunger: float) -> WildAnimal { let a = pn_at(wildlife_st, 2, 0.0, 0.0, state, 5.0) a.thirst = thirst a.hunger = hunger wildlife_seed(wildlife_st, 6) pn_step(wildlife_st, a) return a } test "IDLE, thirst over 60 and over hunger: GO_DRINK to the world's water, 120 s, no roll" (wildlife_st: mut WildlifeState, wildlife_tests_fake_st: mut WildlifeTestsFakeState) { pn_setup(wildlife_st, wildlife_tests_fake_st) let a = needy(wildlife_st, WILD_IDLE, 70.0, 10.0) expect_eq(a.state, WILD_GO_DRINK) expect_eq(a.spot, 900) expect(a.spot_water) expect_near(a.spot_x, 30.0, 0.0001) expect_near(a.timer, 120.0, 0.0001) expect_near(a.way_t, 0.0, 0.00001) expect_eq(pn_drew(wildlife_st, 6), 0) } test "IDLE, hunger over 60 and over thirst: GO_FEED to forage; the two level: GO_DRINK" (wildlife_st: mut WildlifeState, wildlife_tests_fake_st: mut WildlifeTestsFakeState) { pn_setup(wildlife_st, wildlife_tests_fake_st) let a = needy(wildlife_st, WILD_IDLE, 10.0, 70.0) expect_eq(a.state, WILD_GO_FEED) expect(not a.spot_water) let b = needy(wildlife_st, WILD_IDLE, 70.0, 70.0) expect_eq(b.state, WILD_GO_DRINK) expect_eq(pn_drew(wildlife_st, 6), 0) } test "WANDER sets off the same way" (wildlife_st: mut WildlifeState, wildlife_tests_fake_st: mut WildlifeTestsFakeState) { pn_setup(wildlife_st, wildlife_tests_fake_st) let a = needy(wildlife_st, WILD_WANDER, 70.0, 10.0) expect_eq(a.state, WILD_GO_DRINK) expect_near(a.timer, 120.0, 0.0001) } test "no spot answered: IDLE stays, no roll" (wildlife_st: mut WildlifeState, wildlife_tests_fake_st: mut WildlifeTestsFakeState, wild_pin_st: mut WildPinState) { pn_setup(wildlife_st, wildlife_tests_fake_st) wild_pin_st.pn_no_spot = true let a = needy(wildlife_st, WILD_IDLE, 70.0, 10.0) expect_eq(a.state, WILD_IDLE) expect_eq(a.spot, 0) expect_near(a.timer, 4.95, 0.0001) expect_eq(pn_drew(wildlife_st, 6), 0) } test "thirst beats food set out: water first, the lure not taken" (wildlife_st: mut WildlifeState, wildlife_tests_fake_st: mut WildlifeTestsFakeState) { pn_setup(wildlife_st, wildlife_tests_fake_st) pn_lure(wildlife_tests_fake_st, 50, WILD_FEED, WILD_PLANTS, 5.0, 0.0) let a = needy(wildlife_st, WILD_IDLE, 70.0, 10.0) expect_eq(a.state, WILD_GO_DRINK) expect_eq(a.lure, 0) } }