code wiki / _hdl_build / nx_rewards_gate.nx
nx_rewards_gate.nx source
↩ module page · 117 lines · 8806 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"
11
12const RG_REWARD: *u8 = "knowledge/store/reward-"
13const RG_PRICE: *u8 = "knowledge/store/price-"
14const RG_STAGE_FILE: *u8 = "knowledge/staging/reward/rewards.html"
15const RG_LIVE_FILE: *u8 = "knowledge/publish/reward-live/rewards.html"
16
17func 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 }
18func g_i(v: i64) -> i64 {
19 let bb: *u8 = sys_mmap(28); var m: i64 = v
20 if m < 0 { sys_write(1, "-" as *u8, 1); m = 0 - m }
21 let t: *u8 = sys_mmap(28); var k: i64 = 0
22 if m == 0 { t[0] = 48 as u8; k = 1 }
23 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 }
24 var i: i64 = 0; while i < k { bb[i] = t[k - 1 - i]; i = i + 1 } sys_write(1, bb, k); return 0
25}
26func g_exists(path: *u8) -> i64 { let fd: i64 = sys_openat_rd(path); if fd < 0 { return 0 } sys_close(fd); return 1 }
27
28func main() -> i64 {
29 g_p("=== nx_rewards_gate (REAL rewards: value + capabilities, not dumb points) ===\n" as *u8)
30
31 // ground the VALUE reward in REAL store prices: what those 5 herbs would cost at the store
32 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)
33 pr_set_price(RG_PRICE, "herbmart_atx" as *u8, "basil" as *u8, 300, "2025-06-20" as *u8, "plant" as *u8, "receipt" as *u8)
34 pr_set_price(RG_PRICE, "herbmart_atx" as *u8, "rosemary" as *u8, 320, "2025-06-20" as *u8, "plant" as *u8, "receipt" as *u8)
35 pr_set_price(RG_PRICE, "herbmart_atx" as *u8, "thyme" as *u8, 280, "2025-06-20" as *u8, "plant" as *u8, "receipt" as *u8)
36 pr_set_price(RG_PRICE, "herbmart_atx" as *u8, "oregano" as *u8, 260, "2025-06-20" as *u8, "plant" as *u8, "receipt" as *u8)
37 pr_set_price(RG_PRICE, "herbmart_atx" as *u8, "sage" as *u8, 300, "2025-06-20" as *u8, "plant" as *u8, "receipt" as *u8)
38 let items: *i64 = sys_mmap(8 * 8) as *i64
39 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
40 let basket: i64 = pr_basket(RG_PRICE, "herbmart_atx" as *u8, items, 5)
41 g_p("real herb basket (store price) = " as *u8); g_i(basket); g_p("c\n" as *u8)
42
43 // define REAL achievements (the basket IS the value of the herb-self-sufficiency reward)
44 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)
45 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)
46 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)
47
48 var pass: i64 = 0
49 var tot: i64 = 0
50
51 // T1 VALUE reward grounded in real prices
52 rw_grant(RG_REWARD, "bob" as *u8, "herb_selfsuff" as *u8, 200)
53 let vt: i64 = rw_value_total(RG_REWARD, "bob" as *u8)
54 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)
55 tot = tot + 1
56 var ok1: i64 = 1
57 if d1 != 1 { ok1 = 0 }
58 if basket != 1460 { ok1 = 0 }
59 if vt != basket { ok1 = 0 } // the reward IS the real measured price, not an invented number
60 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) }
61
62 // T2 CAPABILITY reward unlocks a real ability
63 let before: i64 = rw_can(RG_REWARD, "bob" as *u8, "host_seed_library" as *u8)
64 rw_grant(RG_REWARD, "bob" as *u8, "master_propagator" as *u8, 201)
65 let after: i64 = rw_can(RG_REWARD, "bob" as *u8, "host_seed_library" as *u8)
66 g_p("host_seed_library: before=" as *u8); g_i(before); g_p(" after=" as *u8); g_i(after); g_p("\n" as *u8)
67 tot = tot + 1
68 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) }
69
70 // T3 PROVISION reward = a real good + its worth
71 rw_grant(RG_REWARD, "bob" as *u8, "rare_grower" as *u8, 202)
72 let vt2: i64 = rw_value_total(RG_REWARD, "bob" as *u8)
73 let cap3: i64 = rw_can(RG_REWARD, "bob" as *u8, "saffron_corm_pack" as *u8)
74 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)
75 tot = tot + 1
76 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) }
77
78 // T4 ANTI-DUMB: a reward with no real backing is REFUSED
79 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)
80 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)
81 tot = tot + 1
82 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) }
83
84 // T5 idempotent: no double-pay
85 let regrant: i64 = rw_grant(RG_REWARD, "bob" as *u8, "herb_selfsuff" as *u8, 203)
86 let vt3: i64 = rw_value_total(RG_REWARD, "bob" as *u8)
87 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)
88 tot = tot + 1
89 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) }
90
91 // T6 render + ship
92 let page: *u8 = sys_mmap(65536)
93 let np: i64 = rw_render_rewards(RG_REWARD, "bob" as *u8, page)
94 g_p("rewards page = " as *u8); g_i(np); g_p(" bytes\n" as *u8)
95 tot = tot + 1
96 var ok6: i64 = 1
97 if as_has_thirdparty_js(page, np) != 0 { ok6 = 0 }
98 if as_contains(page, np, "$26.60" as *u8) != 1 { ok6 = 0 }
99 if as_contains(page, np, "Herb self-sufficient" as *u8) != 1 { ok6 = 0 }
100 if as_contains(page, np, "host_seed_library" as *u8) != 1 { ok6 = 0 }
101 if as_contains(page, np, "No cosmetic points" as *u8) != 1 { ok6 = 0 }
102 sys_mkdir("knowledge/staging" as *u8, 0x1ed)
103 sys_mkdir("knowledge/staging/reward" as *u8, 0x1ed)
104 let sfd: i64 = sys_openat_wr(RG_STAGE_FILE, 420); if sfd >= 0 { sys_write(sfd, page, np); sys_close(sfd) }
105 pub_init()
106 sys_mkdir("knowledge/publish/reward-stage" as *u8, 0x1ed)
107 sys_mkdir("knowledge/publish/reward-live" as *u8, 0x1ed)
108 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)
109 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)
110 if g_exists(RG_LIVE_FILE) != 1 { ok6 = 0 }
111 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) }
112
113 g_p("nx_rewards_gate pass=" as *u8); g_i(pass); g_p("/" as *u8); g_i(tot)
114 if pass == tot { g_p(" verdict=GREEN (gamification that pays in real value + real capabilities; dumb rewards impossible)\n" as *u8); return 0 }
115 g_p(" verdict=RED\n" as *u8)
116 return 1
117}