ludic.base's Queue<T> carries a QueueTag (its name and pending count): queue_new(name), q_push(q, v), q_drain(q), q_clear(q) take no BaseState, and core_undrained(tags) names the given queues still holding facts. A reducer on a package's state can now call that package's verbs (wallet_earn(wallet_st, n)). ludic migrate state --prune (ludicc --migrate-prune) takes out each state parameter a function no longer uses, nor anything it calls, and the argument that fills it - including an argument for a parameter the callee has dropped, which is taken out before the call is checked, so a generic's T is told by the argument that says it. A reducer keeps its state. --dry-run now counts the edits it would make. Every package was moved with it: 608 base_st parameters and their arguments, 1889 edits. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
236 lines
11 KiB
Text
236 lines
11 KiB
Text
# photo_test.ludic - a lens at the origin looking down -z over flat ground, a ridge 45 m out on the
|
|
# left and a trunk 30 m out on the right: what is in the frame, the grade's four parts, the frame's
|
|
# best subject, keeping, the card filling, value and selling, forgetting a frame, the roll's order
|
|
# and pages, the file name and the save
|
|
import "ludic.photo"
|
|
import "ludic.base"
|
|
program PhotoTest {
|
|
numbers float
|
|
|
|
state PhotoTestState {
|
|
hour: float = 12.0
|
|
night: bool = false
|
|
moon: float = 0.0
|
|
dim: int = 0
|
|
sun_z: float = 0.0
|
|
behaviour: bool = false
|
|
sx: float = 0.5
|
|
sy: float = 0.5
|
|
}
|
|
|
|
function fk_y() -> float { return 1.5 }
|
|
function fk_fz() -> float { return -1.0 }
|
|
function fk_fov() -> float { return 0.8 }
|
|
# a pinhole at the origin: across by x over the distance, down by the height over it
|
|
function fk_project(photo_test_st: mut PhotoTestState, x: float, y: float, z: float) -> bool {
|
|
let d = Math.max(-z, 0.5)
|
|
photo_test_st.sx = 0.5 + x / d
|
|
photo_test_st.sy = 0.5 - (y - 1.5) / d
|
|
return z < 0.0
|
|
}
|
|
function fk_sx(photo_test_st: PhotoTestState) -> float { return photo_test_st.sx }
|
|
function fk_sy(photo_test_st: PhotoTestState) -> float { return photo_test_st.sy }
|
|
function fk_ground(x: float, z: float) -> float {
|
|
if x < 0.0 and z < -45.0 and z > -50.0 { return 10.0 }
|
|
return 0.0
|
|
}
|
|
function fk_trunk(x: float, z: float, r: float) -> bool { return Math.abs(x - 3.75) < 1.6 and Math.abs(z + 30.0) < 1.6 }
|
|
function fk_range() -> float { return 80.0 }
|
|
function fk_hour(photo_test_st: PhotoTestState) -> float { return photo_test_st.hour }
|
|
function fk_night(photo_test_st: PhotoTestState) -> bool { return photo_test_st.night }
|
|
function fk_moon(photo_test_st: PhotoTestState) -> float { return photo_test_st.moon }
|
|
function fk_dim(photo_test_st: PhotoTestState) -> int { return photo_test_st.dim }
|
|
function fk_sun_z(photo_test_st: PhotoTestState) -> float { return photo_test_st.sun_z }
|
|
function fk_behaviour(photo_test_st: PhotoTestState) -> bool { return photo_test_st.behaviour }
|
|
function fk_value(sp: int) -> int { return 10 + sp }
|
|
|
|
bind PhotoLens { y: fn fk_y, fz: fn fk_fz, fov: fn fk_fov, project: fn fk_project, sx: fn fk_sx, sy: fn fk_sy, ground: fn fk_ground, trunk: fn fk_trunk, range: fn fk_range }
|
|
bind PhotoLight { hour: fn fk_hour, night: fn fk_night, moon: fn fk_moon, dim: fn fk_dim, sun_z: fn fk_sun_z }
|
|
bind PhotoRules { behaviour: fn fk_behaviour, subject_value: fn fk_value }
|
|
|
|
function fresh(photo_st: mut PhotoState, photo_test_st: mut PhotoTestState) -> void {
|
|
photo_config(photo_st, 4)
|
|
photo_test_st.hour = 12.0
|
|
photo_test_st.night = false
|
|
photo_test_st.dim = 0
|
|
photo_test_st.sun_z = 0.0
|
|
photo_test_st.behaviour = false
|
|
}
|
|
function facts(photo_st: mut PhotoState) -> []PhotoFact { return q_drain(photo_facts(photo_st)) }
|
|
function count(fs: []PhotoFact, what: int) -> int {
|
|
var n = 0
|
|
for i in 0 .. len(fs) { if fs[i].what == what { n += 1 } }
|
|
return n
|
|
}
|
|
# a deer-sized subject straight ahead at `d` metres, doing something worth `moment`
|
|
function shoot(photo_st: mut PhotoState, sp: int, x: float, d: float, h: float, moment: int) -> bool {
|
|
photo_frame_begin(photo_st)
|
|
return photo_frame_subject(photo_st, sp, "deer", x, 0.0, -d, h, false, moment)
|
|
}
|
|
|
|
test "a subject ahead and in reach is in the frame; behind, too far, over a ridge or a trunk it is not" (photo_st: mut PhotoState, photo_test_st: mut PhotoTestState) {
|
|
fresh(photo_st, photo_test_st)
|
|
expect(shoot(photo_st, 1, 0.0, 20.0, 1.1, 10))
|
|
expect_eq(photo_pending_mask(photo_st), 2)
|
|
expect(photo_pending_tags(photo_st) == "deer")
|
|
expect(photo_pending_grade(photo_st) > 0)
|
|
expect(not shoot(photo_st, 1, 0.0, -20.0, 1.1, 10))
|
|
expect(not shoot(photo_st, 1, 0.0, 90.0, 1.1, 10))
|
|
expect(not shoot(photo_st, 1, -2.0, 60.0, 1.1, 10))
|
|
expect(not shoot(photo_st, 1, 5.0, 40.0, 1.1, 10))
|
|
expect_eq(photo_pending_mask(photo_st), 0)
|
|
}
|
|
|
|
test "size: a record shot is a record shot, and the band that pays is a quarter to two thirds" {
|
|
expect(photo_score_size(0.02) < 6)
|
|
expect_eq(photo_score_size(0.5), 40)
|
|
expect(photo_score_size(0.95) < 34)
|
|
expect(photo_score_frame(1.0 / 3.0, 1.0 / 3.0, 0.1) > photo_score_frame(0.5, 0.5, 0.1))
|
|
expect(photo_score_frame(0.02, 0.4, 0.3) < 7)
|
|
expect_eq(photo_score_frame(1.4, 0.4, 0.1), 0)
|
|
}
|
|
|
|
test "the light: gold after dawn, flat at noon, the moon at night, the weather, and backlit" (photo_st: mut PhotoState, photo_test_st: mut PhotoTestState) {
|
|
fresh(photo_st, photo_test_st)
|
|
photo_test_st.hour = 6.5
|
|
expect_eq(photo_score_light(0.0, -20.0), 20)
|
|
photo_test_st.hour = 12.0
|
|
expect_eq(photo_score_light(0.0, -20.0), 9)
|
|
photo_test_st.dim = 4
|
|
expect_eq(photo_score_light(0.0, -20.0), 5)
|
|
photo_test_st.dim = 0
|
|
photo_test_st.sun_z = -1.0
|
|
expect_eq(photo_score_light(0.0, -20.0), 2)
|
|
photo_test_st.sun_z = 0.0
|
|
photo_test_st.night = true
|
|
photo_test_st.moon = 1.0
|
|
expect_eq(photo_score_light(0.0, -20.0), 9)
|
|
}
|
|
|
|
test "the moment counts by how much subject there is, and a judge of behaviour doubles it" (photo_st: mut PhotoState, photo_test_st: mut PhotoTestState) {
|
|
fresh(photo_st, photo_test_st)
|
|
shoot(photo_st, 1, 0.0, 70.0, 0.3, 20)
|
|
let tiny = photo_pending_grade(photo_st)
|
|
shoot(photo_st, 1, 0.0, 6.0, 1.1, 6)
|
|
let big = photo_pending_grade(photo_st)
|
|
expect(big > tiny)
|
|
expect(tiny < 20)
|
|
shoot(photo_st, 1, 0.0, 6.0, 1.1, 20)
|
|
let busy = photo_pending_grade(photo_st)
|
|
photo_test_st.behaviour = true
|
|
shoot(photo_st, 1, 0.0, 6.0, 1.1, 20)
|
|
expect(photo_pending_grade(photo_st) > busy - 21)
|
|
expect_near(photo_comp(photo_st, 3), 40.0, 0.01)
|
|
}
|
|
|
|
test "the frame takes its best subject, tags each kind once and every legend" (photo_st: mut PhotoState, photo_test_st: mut PhotoTestState) {
|
|
fresh(photo_st, photo_test_st)
|
|
photo_frame_begin(photo_st)
|
|
photo_frame_subject(photo_st, 2, "elk", 0.0, 0.0, -60.0, 1.9, false, 6)
|
|
let far = photo_pending_grade(photo_st)
|
|
photo_frame_subject(photo_st, 2, "elk", 1.0, 0.0, -8.0, 1.9, false, 17)
|
|
photo_frame_subject(photo_st, 4, "the Ghost Elk", -1.0, 0.0, -9.0, 2.2, true, 20)
|
|
photo_frame_tag(photo_st, "Maroon Lake")
|
|
expect(photo_pending_grade(photo_st) > far)
|
|
expect(photo_pending_tags(photo_st) == "elk, the Ghost Elk, Maroon Lake")
|
|
expect_eq(photo_pending_mask(photo_st), 4 + 16)
|
|
expect_eq(photo_pending_legend(photo_st), 16)
|
|
expect(photo_pending_why(photo_st) >= PHOTO_WHY_SIZE)
|
|
}
|
|
|
|
test "a kept frame is on the roll, its subjects are photographed for good, and a full card says so" (photo_st: mut PhotoState, photo_test_st: mut PhotoTestState) {
|
|
fresh(photo_st, photo_test_st)
|
|
shoot(photo_st, 3, 0.0, 10.0, 1.1, 15)
|
|
let g = photo_pending_grade(photo_st)
|
|
expect_eq(photo_keep(photo_st, "a.png", 2, 7.5), 0)
|
|
let fs = facts(photo_st)
|
|
expect_eq(count(fs, PHOTO_KEPT), 1)
|
|
expect_eq(fs[0].firsts, 8)
|
|
expect_eq(photo_species_shot(photo_st), 8)
|
|
expect_eq(photo_best(photo_st, 3), g)
|
|
expect_eq(photo_day(photo_st, 0), 2)
|
|
shoot(photo_st, 3, 0.0, 10.0, 1.1, 15)
|
|
photo_keep(photo_st, "b.png", 2, 8.0)
|
|
expect_eq(facts(photo_st)[0].firsts, 0)
|
|
photo_keep(photo_st, "c.png", 2, 8.0)
|
|
photo_keep(photo_st, "d.png", 2, 8.0)
|
|
expect(photo_full(photo_st))
|
|
expect_eq(photo_keep(photo_st, "e.png", 2, 8.0), -1)
|
|
expect_eq(count(facts(photo_st), PHOTO_FULL), 1)
|
|
}
|
|
|
|
test "the first frame of a subject is worth its value on the grade's curve; sold is sold" (photo_st: mut PhotoState, photo_test_st: mut PhotoTestState) {
|
|
fresh(photo_st, photo_test_st)
|
|
photo_add(photo_st, 1, 9.0, 2, 0, false, "fox", "f.png", 60, PHOTO_WHY_NONE)
|
|
photo_add(photo_st, 1, 9.5, 2, 2, false, "fox", "g.png", 95, PHOTO_WHY_FINE)
|
|
photo_add(photo_st, 1, 9.5, 0, 0, false, "the valley", "h.png", 0, PHOTO_WHY_NONE)
|
|
expect_eq(photo_value(photo_st, 0), int(11.0 * 1.5))
|
|
expect_eq(photo_value(photo_st, 1), int(float(11 + 120) * 4.0))
|
|
expect_eq(photo_value(photo_st, 2), 0)
|
|
let total = photo_sell_all(photo_st)
|
|
expect_eq(total, int(11.0 * 1.5) + int(120.0 * 4.0))
|
|
expect_eq(count(facts(photo_st), PHOTO_SOLD), 2)
|
|
expect(photo_sold(photo_st, 0))
|
|
expect_eq(photo_value(photo_st, 0), 0)
|
|
photo_add(photo_st, 1, 10.0, 2, 0, false, "fox", "i.png", 60, PHOTO_WHY_NONE)
|
|
expect_eq(photo_value(photo_st, 3), 0)
|
|
}
|
|
|
|
test "forgetting a frame closes the roll up, moves the cover, and names the file" (photo_st: mut PhotoState, photo_test_st: mut PhotoTestState) {
|
|
fresh(photo_st, photo_test_st)
|
|
photo_add(photo_st, 1, 9.0, 2, 0, false, "a", "a.png", 10, 0)
|
|
photo_add(photo_st, 1, 9.0, 4, 0, false, "b", "b.png", 20, 0)
|
|
photo_add(photo_st, 1, 9.0, 8, 0, false, "c", "c.png", 30, 0)
|
|
photo_cover_set(photo_st, 2)
|
|
photo_remove(photo_st, 0)
|
|
expect_eq(photo_count(photo_st), 2)
|
|
expect(photo_tags(photo_st, 0) == "b")
|
|
expect_eq(photo_grade(photo_st, 1), 30)
|
|
expect_eq(photo_cover(photo_st), 1)
|
|
let fs = facts(photo_st)
|
|
expect(fs[0].file == "a.png")
|
|
expect_eq(photo_species_shot(photo_st), 14)
|
|
}
|
|
|
|
test "the roll in order: newest first, best first, by subject, and a page at a time" (photo_st: mut PhotoState) {
|
|
photo_config(photo_st, 20)
|
|
for i in 0 .. 10 { photo_add(photo_st, 1, 9.0, 1 << (i % 3), 0, false, "x", "x.png", (i * 37) % 100, 0) }
|
|
expect_eq(photo_order(photo_st)[0], 9)
|
|
photo_sort_next(photo_st)
|
|
let best = photo_order(photo_st)
|
|
expect(photo_grade(photo_st, best[0]) >= photo_grade(photo_st, best[1]))
|
|
expect(photo_grade(photo_st, best[1]) >= photo_grade(photo_st, best[9]))
|
|
photo_sort_next(photo_st)
|
|
expect(photo_mask(photo_st, photo_order(photo_st)[0]) <= photo_mask(photo_st, photo_order(photo_st)[9]))
|
|
expect_eq(photo_pages(photo_st), 2)
|
|
expect_eq(len(photo_page_list(photo_st)), 8)
|
|
photo_page_step(photo_st, 5)
|
|
expect_eq(photo_page_now(photo_st), 1)
|
|
expect_eq(len(photo_page_list(photo_st)), 2)
|
|
}
|
|
|
|
test "a file name from the tags" {
|
|
expect(photo_slug("Elk, the Ghost Elk") == "elk-the-ghost-elk")
|
|
expect(photo_slug("") == "photo")
|
|
expect(photo_slug("a very long list of names past twenty") == "a-very-long-list-of-name")
|
|
}
|
|
|
|
test "the roll and what was ever photographed come back from the save" (photo_st: mut PhotoState, photo_test_st: mut PhotoTestState) {
|
|
fresh(photo_st, photo_test_st)
|
|
photo_add(photo_st, 3, 18.25, 2, 2, true, "fox", "f.png", 80, PHOTO_WHY_LIGHT)
|
|
photo_record_set(photo_st, 2 | 64, 2)
|
|
photo_cover_set(photo_st, 0)
|
|
let v = photo_save(photo_st)
|
|
photo_reset(photo_st)
|
|
expect_eq(photo_count(photo_st), 0)
|
|
photo_load(photo_st, v, 1)
|
|
expect_eq(photo_count(photo_st), 1)
|
|
expect_near(photo_hour(photo_st, 0), 18.25, 0.01)
|
|
expect(photo_sold(photo_st, 0))
|
|
expect_eq(photo_why(photo_st, 0), PHOTO_WHY_LIGHT)
|
|
expect_eq(photo_species_shot(photo_st), 66)
|
|
expect_eq(photo_legend_shot(photo_st), 2)
|
|
expect_eq(photo_best(photo_st, 1), 80)
|
|
expect_eq(photo_cover(photo_st), 0)
|
|
}
|
|
}
|