code wiki / _hdl_build / nx_rewards_gate.nx
nx_rewards_gate.nx source
↩ module page · 124 lines · 9202 B
1// nx_rewards_gate.nx -- GATE: REAL-reward gamification. T1 a VALUE reward is REAL money, GROUNDED in actual
2// store prices (not an invented number) -- the herb basket from nx_price IS the reward. T2 a CAPABILITY reward
3// unlocks a real ability the ecosystem honors (rw_can flips). T3 a PROVISION reward grants a real good + value.
4// T4 ANTI-DUMB: an achievement with no real backing is REFUSED by construction (no cosmetic points possible).
5// T5 idempotent (no double-pay). T6 the real-rewards page renders sovereign + ships. license_tier: ORIGINAL
6import "nx_rewards.nx"
7import "nx_price.nx"
8import "nx_publisher.nx"
9import "nx_seg_store.nx"
10import "nx_syscalls.nx"
11import "nx_gate_verdict.nx"
12
13const RG_REWARD: *u8 = "knowledge/store/reward-"
14const RG_PRICE: *u8 = "knowledge/store/price-"
15const RG_STAGE_FILE: *u8 = "knowledge/staging/reward/rewards.html"
16const RG_LIVE_FILE: *u8 = "knowledge/publish/reward-live/rewards.html"
17
18func g_p(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
19func g_i(v: i64) -> i64 {
20 let bb: *u8 = sys_mmap(28); var m: i64 = v
21 if m < 0 { sys_write(1, "-" as *u8, 1); m = 0 - m }
22 let t: *u8 = sys_mmap(28); var k: i64 = 0
23 if m == 0 { t[0] = 48 as u8; k = 1 }
24 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 }
25 var i: i64 = 0; while i < k { bb[i] = t[k - 1 - i]; i = i + 1 } sys_write(1, bb, k); return 0
26}
27func g_exists(path: *u8) -> i64 { let fd: i64 = sys_openat_rd(path); if fd < 0 { return 0 } sys_close(fd); return 1 }
28
29func main() -> i64 {
30 g_p("=== nx_rewards_gate (REAL rewards: value + capabilities, not dumb points) ===\n" as *u8)
31
32 // ground the VALUE reward in REAL store prices: what those 5 herbs would cost at the store
33 pr_add_store(RG_PRICE, "herbmart_atx" as *u8, "Herb Mart" as *u8, "Herb Mart" as *u8, "TX-Austin" as *u8, "TX" as *u8, "receipt" as *u8)
34 pr_set_price(RG_PRICE, "herbmart_atx" as *u8, "basil" as *u8, 300, "2025-06-20" as *u8, "plant" as *u8, "receipt" as *u8)
35 pr_set_price(RG_PRICE, "herbmart_atx" as *u8, "rosemary" as *u8, 320, "2025-06-20" as *u8, "plant" as *u8, "receipt" as *u8)
36 pr_set_price(RG_PRICE, "herbmart_atx" as *u8, "thyme" as *u8, 280, "2025-06-20" as *u8, "plant" as *u8, "receipt" as *u8)
37 pr_set_price(RG_PRICE, "herbmart_atx" as *u8, "oregano" as *u8, 260, "2025-06-20" as *u8, "plant" as *u8, "receipt" as *u8)
38 pr_set_price(RG_PRICE, "herbmart_atx" as *u8, "sage" as *u8, 300, "2025-06-20" as *u8, "plant" as *u8, "receipt" as *u8)
39 let items: *i64 = sys_mmap(8 * 8) as *i64
40 items[0] = "basil" as *u8 as i64; items[1] = "rosemary" as *u8 as i64; items[2] = "thyme" as *u8 as i64; items[3] = "oregano" as *u8 as i64; items[4] = "sage" as *u8 as i64
41 let basket: i64 = pr_basket(RG_PRICE, "herbmart_atx" as *u8, items, 5)
42 g_p("real herb basket (store price) = " as *u8); g_i(basket); g_p("c\n" as *u8)
43
44 // define REAL achievements (the basket IS the value of the herb-self-sufficiency reward)
45 let d1: i64 = rw_def_achievement(RG_REWARD, "herb_selfsuff" as *u8, "Herb self-sufficient" as *u8, "garden" as *u8, "VALUE" as *u8, basket, "-" as *u8, "price observations" as *u8)
46 let d2: i64 = rw_def_achievement(RG_REWARD, "master_propagator" as *u8, "Master Propagator" as *u8, "swap" as *u8, "CAPABILITY" as *u8, 0, "host_seed_library" as *u8, "10 successful swaps" as *u8)
47 let d3: i64 = rw_def_achievement(RG_REWARD, "rare_grower" as *u8, "Rare Grower" as *u8, "garden" as *u8, "PROVISION" as *u8, 1200, "saffron_corm_pack" as *u8, "grew a rare species" as *u8)
48
49 var pass: i64 = 0
50 var tot: i64 = 0
51
52 // T1 VALUE reward grounded in real prices
53 rw_grant(RG_REWARD, "bob" as *u8, "herb_selfsuff" as *u8, 200)
54 let vt: i64 = rw_value_total(RG_REWARD, "bob" as *u8)
55 g_p("after herb_selfsuff: bob value=" as *u8); g_i(vt); g_p("c (def=" as *u8); g_i(d1); g_p(")\n" as *u8)
56 tot = tot + 1
57 var ok1: i64 = 1
58 if d1 != 1 { ok1 = 0 }
59 if basket != 1460 { ok1 = 0 }
60 if vt != basket { ok1 = 0 } // the reward IS the real measured price, not an invented number
61 if ok1 == 1 { pass = pass + 1; g_p("PASS T1 VALUE reward is REAL money grounded in store prices ($14.60 herb basket = the reward)\n" as *u8) } else { g_p("FAIL T1\n" as *u8) }
62
63 // T2 CAPABILITY reward unlocks a real ability
64 let before: i64 = rw_can(RG_REWARD, "bob" as *u8, "host_seed_library" as *u8)
65 rw_grant(RG_REWARD, "bob" as *u8, "master_propagator" as *u8, 201)
66 let after: i64 = rw_can(RG_REWARD, "bob" as *u8, "host_seed_library" as *u8)
67 g_p("host_seed_library: before=" as *u8); g_i(before); g_p(" after=" as *u8); g_i(after); g_p("\n" as *u8)
68 tot = tot + 1
69 if d2 == 1 { if before == 0 { if after == 1 { pass = pass + 1; g_p("PASS T2 CAPABILITY reward unlocks a REAL ability (host_seed_library) the ecosystem honors\n" as *u8) } else { g_p("FAIL T2 not unlocked\n" as *u8) } } else { g_p("FAIL T2 already had it\n" as *u8) } } else { g_p("FAIL T2 def\n" as *u8) }
70
71 // T3 PROVISION reward = a real good + its worth
72 rw_grant(RG_REWARD, "bob" as *u8, "rare_grower" as *u8, 202)
73 let vt2: i64 = rw_value_total(RG_REWARD, "bob" as *u8)
74 let cap3: i64 = rw_can(RG_REWARD, "bob" as *u8, "saffron_corm_pack" as *u8)
75 g_p("after rare_grower: bob value=" as *u8); g_i(vt2); g_p("c saffron-pack=" as *u8); g_i(cap3); g_p("\n" as *u8)
76 tot = tot + 1
77 if d3 == 1 { if vt2 == 2660 { if cap3 == 1 { pass = pass + 1; g_p("PASS T3 PROVISION reward = a real good (saffron pack) + its worth (total now $26.60)\n" as *u8) } else { g_p("FAIL T3 good\n" as *u8) } } else { g_p("FAIL T3 value=" as *u8); g_i(vt2); g_p("\n" as *u8) } } else { g_p("FAIL T3 def\n" as *u8) }
78
79 // T4 ANTI-DUMB: a reward with no real backing is REFUSED
80 let dumb: i64 = rw_def_achievement(RG_REWARD, "shiny_star" as *u8, "Shiny Star" as *u8, "swap" as *u8, "VALUE" as *u8, 0, "-" as *u8, "-" as *u8)
81 g_p("dumb-reward def attempt returned=" as *u8); g_i(dumb); g_p(" defined=" as *u8); g_i(rw_ach_defined(RG_REWARD, "shiny_star" as *u8)); g_p("\n" as *u8)
82 tot = tot + 1
83 if dumb == 0 { if rw_ach_defined(RG_REWARD, "shiny_star" as *u8) == 0 { pass = pass + 1; g_p("PASS T4 anti-dumb: a reward with no real backing (0 value, no capability) is REFUSED by construction\n" as *u8) } else { g_p("FAIL T4 got defined\n" as *u8) } } else { g_p("FAIL T4 not refused\n" as *u8) }
84
85 // T5 idempotent: no double-pay
86 let regrant: i64 = rw_grant(RG_REWARD, "bob" as *u8, "herb_selfsuff" as *u8, 203)
87 let vt3: i64 = rw_value_total(RG_REWARD, "bob" as *u8)
88 g_p("re-grant herb_selfsuff returned=" as *u8); g_i(regrant); g_p(" value(still)=" as *u8); g_i(vt3); g_p("\n" as *u8)
89 tot = tot + 1
90 if regrant == 0 { if vt3 == 2660 { pass = pass + 1; g_p("PASS T5 idempotent: earning the same reward twice does NOT double-pay (value stays $26.60)\n" as *u8) } else { g_p("FAIL T5 doubled\n" as *u8) } } else { g_p("FAIL T5 re-granted\n" as *u8) }
91
92 // T6 render + ship
93 let page: *u8 = sys_mmap(65536)
94 let np: i64 = rw_render_rewards(RG_REWARD, "bob" as *u8, page)
95 g_p("rewards page = " as *u8); g_i(np); g_p(" bytes\n" as *u8)
96 tot = tot + 1
97 var ok6: i64 = 1
98 if as_has_thirdparty_js(page, np) != 0 { ok6 = 0 }
99 if as_contains(page, np, "$26.60" as *u8) != 1 { ok6 = 0 }
100 if as_contains(page, np, "Herb self-sufficient" as *u8) != 1 { ok6 = 0 }
101 if as_contains(page, np, "host_seed_library" as *u8) != 1 { ok6 = 0 }
102 if as_contains(page, np, "No cosmetic points" as *u8) != 1 { ok6 = 0 }
103 sys_mkdir("knowledge/staging" as *u8, 0x1ed)
104 sys_mkdir("knowledge/staging/reward" as *u8, 0x1ed)
105 let sfd: i64 = sys_openat_wr(RG_STAGE_FILE, 420); if sfd >= 0 { sys_write(sfd, page, np); sys_close(sfd) }
106 pub_init()
107 sys_mkdir("knowledge/publish/reward-stage" as *u8, 0x1ed)
108 sys_mkdir("knowledge/publish/reward-live" as *u8, 0x1ed)
109 pub_submit_to("knowledge/publish/reward-queue.tsv" as *u8, RG_STAGE_FILE, "rewards.html" as *u8, "nishifoodfamily" as *u8, "nishi-reward" as *u8, "internal" as *u8)
110 pub_run_full("knowledge/publish/reward-queue.tsv" as *u8, "knowledge/publish/reward-ledger.tsv" as *u8, "knowledge/publish/reward-stage" as *u8, "knowledge/publish/reward-live" as *u8, "publish:reward" as *u8)
111 if g_exists(RG_LIVE_FILE) != 1 { ok6 = 0 }
112 if ok6 == 1 { pass = pass + 1; g_p("PASS T6 real-rewards page (money saved + capabilities unlocked) renders sovereign + ships\n" as *u8) } else { g_p("FAIL T6\n" as *u8) }
113
114 g_p("nx_rewards_gate pass=" as *u8); g_i(pass); g_p("/" as *u8); g_i(tot)
115 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check
116 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled
117 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify.
118 let ctr__dry: *i64 = gv_ctr()
119 ctr__dry[0] = pass
120 ctr__dry[1] = tot
121 let rc__dry: i64 = gv_verdict("REWARDS-GATE" as *u8, ctr__dry, "gamification that pays in real value + real capabilities; dumb rewards impossible)" as *u8)
122 sys_exit(rc__dry)
123 return rc__dry
124}