Free games for graphing calculators: NumWorks, TI-Nspire CX, Casio fx-CG50 and soon TI-84 Plus CE. Balatro, Celeste, Hollow Knight, Minecraft and more.
C calculatorcalculator-gamescasiochesscrossy-roaddrive-madfx-cg50gamesgeometry-dashgraphing-calculatorndlessnumworksnumworks-appsnumworks-calculatornumworks-gamenumworks-gamestetristi-84-plus-ceti-nspire
Cookie Clicker: host checks, options and statistics as the game's
Mason36383ba529990d5
diff --git a/games/cookieclicker/src/ascend.c b/games/cookieclicker/src/ascend.cindex 5c6230b9..1990d6d7 100644--- a/games/cookieclicker/src/ascend.c+++ b/games/cookieclicker/src/ascend.c@@ -89,6 +89,7 @@ void ascend_enter(void) {U.asc_x = U.asc_tx, U.asc_y = U.asc_ty;chips_shown = S.heavenly_chips;U.asc_mode = 0;+ U.tip_t = FPS * 5;}static void draw_link(int a, int b, int alpha) {@@ -156,8 +157,8 @@ static void draw_heavens(void) {gfx_text_outline_center(F_SMALL, SCREEN_W / 2, SCREEN_H - 5,S.prestige > 0 ? "EXE buy Back reincarnate shift challenge mode" : "EXE buy Back reincarnate",RGB(170, 170, 170), 256);- /* the tooltip of the upgrade chosen */- if (sel_u >= 0) {+ /* the tooltip of the upgrade chosen (a while after it is chosen) */+ if (sel_u >= 0 && U.tip_t > 0) {int w = 200, pad = 5;int h = crate_tip(0, sel_u, CTX_ASCEND, 0, 0, w - 2 * pad, false) + 2 * pad;int slot = permanent_slot_of(sel_u);@@ -249,6 +250,7 @@ void draw_ascend(void) {}void ascend_tick(void) {+ if (U.tip_t > 0) U.tip_t--;U.asc_x += (U.asc_tx - U.asc_x) * 0.5f;U.asc_y += (U.asc_ty - U.asc_y) * 0.5f;chips_shown += (S.heavenly_chips - chips_shown) * 0.4;@@ -275,9 +277,11 @@ void ascend_keys(uint32_t p) {if (score < best) best = score, found = u;}if (found >= 0) sel_u = found, focus();+ U.tip_t = FPS * 5;}if (p & K_SHIFT && S.prestige > 0) U.asc_mode ^= 1;if (p & (K_EXE | K_OK) && sel_u >= 0) {+ U.tip_t = FPS * 5;if (!bit_get(S.upgrades_bought, sel_u)) {if (heavenly_can_be_purchased(sel_u) && upgrade_buy(sel_u, true)) build();} else if (permanent_slot_of(sel_u) >= 0) {diff --git a/games/cookieclicker/src/grimoire.c b/games/cookieclicker/src/grimoire.cindex a6c0a3a8..a16415a4 100644--- a/games/cookieclicker/src/grimoire.c+++ b/games/cookieclicker/src/grimoire.c@@ -362,7 +362,7 @@ void grimoire_draw(void) {/* the magic meter, its lump refill at its left */int bw = (int)(magic_max * 1.5f), bx, by = NEWS_H + 118;if (bw > GW - 40) bw = GW - 40;- if (bw < 20) bw = 20;+ if (bw < 100) bw = 100;bx = GX + (GW - bw) / 2 + 10;gfx_icon_scaled(ICON(29, 14), bx - 22, by - 3, 18, can_lumps() ? 256 : 120);if (sel == N_SPELLS) gfx_rect(bx - 23, by - 4, 20, 20, WHITE, 256);@@ -408,15 +408,17 @@ int grimoire_tip(int x, int y, int w, bool draw) {if (draw) gfx_text_outline(F_NAME, x + 27, yy + 11, s->name, WHITE, 256);int cost = spell_cost(sel);snprintf(c, sizeof c, "%d", cost);- char cb[64] = "";- if (s->cost_percent) snprintf(cb, sizeof cb, " (%d magic +%d%% of max magic)", s->cost_min, (int)ceilf(s->cost_percent * 100));if (draw) {int tx = x + 27;tx = gfx_text(F_SMALL, tx, yy + 22, "Magic cost: ", RGB(204, 204, 204), 256);- tx = gfx_text(F_BOLD, tx, yy + 22, c, cost <= S.grimoire_magic ? RGB(102, 255, 102) : RGB(255, 102, 102), 256);- gfx_text(F_SMALL, tx, yy + 22, cb, RGB(170, 170, 170), 256);+ gfx_text(F_BOLD, tx, yy + 22, c, cost <= S.grimoire_magic ? RGB(102, 255, 102) : RGB(255, 102, 102), 256);}yy += 26;+ if (s->cost_percent) {+ snprintf(l, sizeof l, "(%d magic +%d%% of max magic)", s->cost_min, (int)ceilf(s->cost_percent * 100));+ if (draw) gfx_text(F_SMALL, x + 27, yy + 6, l, RGB(170, 170, 170), 256);+ yy += 10;+ }if (s->fail_desc) {snprintf(l, sizeof l, "Chance to backfire: %d%%", (int)ceil(100 * fail_chance(sel)));if (draw) gfx_text(F_SMALL, x + 27, yy + 6, l, RGB(255, 102, 102), 256);diff --git a/games/cookieclicker/src/lumps.c b/games/cookieclicker/src/lumps.cindex 4660702e..d5e55935 100644--- a/games/cookieclicker/src/lumps.c+++ b/games/cookieclicker/src/lumps.c@@ -132,7 +132,7 @@ void do_lumps(void) {S.lump_t = lump_now(), S.lumps_total = 0, S.lumps = 0;compute_lump_type();notify("Sugar lumps!",- "Because you've baked a \x01billion cookies\x02 in total, you are now attracting \x01sugar lumps\x02. "+ "Because you've baked a \x01" "billion cookies\x02 in total, you are now attracting \x01" "sugar lumps\x02. ""They coalesce quietly near the top of your screen.\nYou will be able to harvest them when they're ""ripe, after which you may spend them on all sorts of things!",ICON(23, 14), 0);diff --git a/games/cookieclicker/src/menus.c b/games/cookieclicker/src/menus.cindex ff0d94d9..6aae17e9 100644--- a/games/cookieclicker/src/menus.c+++ b/games/cookieclicker/src/menus.c@@ -110,49 +110,68 @@ static Opt opts[] = {};#define N_OPTS (int)(sizeof opts / sizeof opts[0])+/* where each option is (from the top of the page's content), and its label's lines */+static int opt_y[N_OPTS + 1];+static void options_layout(void) {+ int y = 16;+ for (int i = 0; i < N_OPTS; i++) {+ if (i == O_FIRST_PREF) y += 20;+ opt_y[i] = y;+ char t[64], l[96];+ snprintf(t, sizeof t, "%s OFF", opts[i].name);+ int lx = PAD + gfx_text_width(F_NAME_SMALL, t) + 20;+ int h = 15;+ if (opts[i].label) {+ snprintf(l, sizeof l, "(%s)", opts[i].label);+ int lh = gfx_para(&PS_SMALL, lx, 0, SCREEN_W - lx - 6, l, false);+ if (lh + 2 > h) h = lh + 2;+ }+ y += h + 4;+ }+ opt_y[N_OPTS] = y;+}+static void draw_options(void) {panel("Options");- int y = PANEL_Y + 30 - U.list_top;+ options_layout();+ int top = PANEL_Y + 30 - U.list_top;gfx_clip(0, PANEL_Y + 26, SCREEN_W, PANEL_H - 28);- gfx_text_outline(F_NAME, PAD, y + 10, "General", RGB(246, 218, 184), 256);- y += 16;+ gfx_text_outline(F_NAME, PAD, top + 10, "General", RGB(246, 218, 184), 256);+ gfx_text_outline(F_NAME, PAD, top + opt_y[O_FIRST_PREF] - 6, "Settings", RGB(246, 218, 184), 256);for (int i = 0; i < N_OPTS; i++) {- if (i == O_FIRST_PREF) {- y += 4;- gfx_text_outline(F_NAME, PAD, y + 10, "Settings", RGB(246, 218, 184), 256);- y += 16;- }- char t[64];+ int y = top + opt_y[i];+ char t[64], w[64];bool on = true;if (opts[i].pref) {on = (*opts[i].pref != 0) != opts[i].invert;snprintf(t, sizeof t, "%s %s", opts[i].name, on ? "ON" : "OFF");} elsesnprintf(t, sizeof t, "%s", opts[i].name);- int bw = gfx_text_width(F_NAME_SMALL, t) + 14;- if (gfx_visible(0, y - 2, SCREEN_W, 20)) {- button(PAD, y, bw, t, U.list_sel == i, on);- if (opts[i].label) {- char l[96];- snprintf(l, sizeof l, "(%s)", opts[i].label);- int lx = PAD + bw + 6;- if (gfx_text_width(F_SMALL, l) > SCREEN_W - lx - 4) gfx_para(&PS_SMALL, lx, y - 3, SCREEN_W - lx - 4, l, true);- else gfx_text(F_SMALL, lx, y + 11, l, RGB(180, 180, 180), 256);- }+ snprintf(w, sizeof w, "%s OFF", opts[i].name);+ int bw = gfx_text_width(F_NAME_SMALL, opts[i].pref ? w : t) + 14;+ if (!gfx_visible(0, y - 2, SCREEN_W, opt_y[i + 1] - opt_y[i] + 4)) continue;+ button(PAD, y, bw, t, U.list_sel == i, on);+ if (opts[i].label) {+ char l[96];+ snprintf(l, sizeof l, "(%s)", opts[i].label);+ int lx = PAD + gfx_text_width(F_NAME_SMALL, w) + 20;+ ParaStyle st = PS_SMALL;+ st.color = RGB(180, 180, 180);+ int lh = gfx_para(&st, lx, 0, SCREEN_W - lx - 6, l, false);+ gfx_para(&st, lx, y + (15 - lh) / 2 - (lh > 15 ? 0 : 1), SCREEN_W - lx - 6, l, true);}- y += 19;}gfx_unclip();}-static int options_y(int i) { return 46 + i * 19 + (i >= O_FIRST_PREF ? 20 : 0); }-static void options_keys(uint32_t p) {if (p & K_UP && U.list_sel > 0) U.list_sel--;if (p & K_DOWN && U.list_sel < N_OPTS - 1) U.list_sel++;- int y = options_y(U.list_sel), view = PANEL_H - 30;- if (y - U.list_top > view - 20) U.list_top = y - view + 20;- if (y - U.list_top < 30) U.list_top = y - 30 < 0 ? 0 : y - 30;+ options_layout();+ int y = opt_y[U.list_sel], view = PANEL_H - 30;+ if (y - U.list_top > view - 26) U.list_top = y - view + 26;+ if (y - U.list_top < 20) U.list_top = y - 20 < 0 ? 0 : y - 20;+ if (U.list_sel == 0) U.list_top = 0;if (p & (K_OK | K_EXE)) {Opt *o = &opts[U.list_sel];if (U.list_sel == O_SAVE) {@@ -416,14 +435,18 @@ static void draw_grid(int tab) {}if (!gfx_visible(x, y0 + y, CRATE, CRATE)) continue;bool sel = U.list_sel == i;+ /* (as the game's statistics show them: the icons alone, the heavenly ones in their slots) */+ int icon;if (tab == TAB_UPGRADES) {const UpgradeRec *r = upgrade_rec(grid[i]);- draw_crate(r->icon, x, y0 + y, sel ? 1 : 0, false);+ icon = r->icon;+ if (r->pool == POOL_PRESTIGE) gfx_image_scaled(IM_ASCEND_SLOT0, x - 3, y0 + y - 3, 35, 35, 256);} else {int a = grid[i];- bool won = has_achiev(a);- draw_crate(won ? achiev_rec(a)->icon : ICON(0, 7), x, y0 + y, sel ? 1 : won ? 0 : 2, false);+ icon = has_achiev(a) ? achiev_rec(a)->icon : ICON(0, 7);}+ gfx_icon(icon, x + 2, y0 + y + 2 - sel, tab == TAB_ACHIEVS && !has_achiev(grid[i]) ? 140 : 256);+ if (sel) gfx_rect(x, y0 + y, CRATE - 1, CRATE - 1, WHITE, 200);}}diff --git a/games/cookieclicker/src/ui.c b/games/cookieclicker/src/ui.cindex 9c15d224..2341fe7d 100644--- a/games/cookieclicker/src/ui.c+++ b/games/cookieclicker/src/ui.c@@ -115,7 +115,7 @@ void prompt_text(char *title, int ts, char *body, int bs, const char **yes, consbreak;case PROMPT_REINCARNATE:snprintf(title, ts, "Reincarnate");- snprintf(body, bs, arg == 1 ? "Are you ready to return to the mortal world?\nYou will be \x01Born again\x02: "+ snprintf(body, bs, arg == 1 ? "Are you ready to return to the mortal world?\nYou will be \x01" "Born again\x02: ""your heavenly upgrades and prestige will not count this run.": "Are you ready to return to the mortal world?");*yes = "Reincarnate";diff --git a/games/cookieclicker/src/ui_store.c b/games/cookieclicker/src/ui_store.cindex c966996a..c3f9352d 100644--- a/games/cookieclicker/src/ui_store.c+++ b/games/cookieclicker/src/ui_store.c@@ -353,18 +353,6 @@ static int tooltip_body(int x, int y, int w, bool draw) {floor(m->total_cookies) == 1 ? "cookie" : "cookies", res_text(r->action));yy += gfx_para(&PS_SMALL, x, yy, w, line, draw) + 2;}- {- if (can_lumps()) {- if (draw) {- gfx_hgrad(x, yy, w / 2, 1, BLACK, 0, 110);- gfx_hgrad(x + w / 2, yy, w - w / 2, 1, BLACK, 110, 0);- }- yy += 3;- snprintf(line, sizeof line, "\x01Level %d %s\x02 (+%d%% CpS). [toolbox] levels up for %d sugar lump%s.",- m->level, res_text(r->plural), m->level, m->level + 1, m->level ? "s" : "");- yy += gfx_para(&PS_SMALL, x, yy, w, line, draw) + 2;- }- }return yy - y;}return 0;diff --git a/games/cookieclicker/tests/check.py b/games/cookieclicker/tests/check.pynew file mode 100644index 00000000..48c967fb--- /dev/null+++ b/games/cookieclicker/tests/check.py@@ -0,0 +1,136 @@+#!/usr/bin/env python3+"""Checks of Cookie Clicker on a computer (make test): the host build, with AddressSanitizer and UBSan,+through the first start, the bakery kept by Home and brought back, the save coming back from+cookieclicker_saves.py, every screen pressed through (the store, the menus, statistics, the buildings' rows,+the Grimoire, golden and wrath cookies, wrinklers, Santa and the dragon), an ascension from the Legacy+prompt to the heavens and back, and half an hour of play by a robot (tests/play.c --bot).++ python3 tests/check.py build/play [--quick]++--quick plays five minutes instead of half an hour."""+import os+import re+import shutil+import subprocess+import sys+import tempfile++PLAY = sys.argv[1] if len(sys.argv) > 1 else "build/play"+QUICK = "--quick" in sys.argv+ENV = dict(os.environ, ASAN_OPTIONS="detect_leaks=0", UBSAN_OPTIONS="halt_on_error=1:print_stacktrace=1")+failures = []+++def check(cond, msg):+ if not cond:+ failures.append(msg)+++def run(args, what, timeout=1200):+ p = subprocess.run([PLAY] + args, capture_output=True, text=True, env=ENV, timeout=timeout)+ if p.returncode != 0 or "runtime error" in p.stderr or "AddressSanitizer" in p.stderr:+ failures.append(f"{what}: crashed or a sanitizer error\n{p.stderr[-2000:]}")+ return None+ return p.stdout+++def end_state(out, what):+ m = re.search(r"frames (\d+) cookies (\d+) earned (\d+) cps ([\d.]+) clicks (\d+) buildings (\d+) upgrades (\d+) "+ r"achievements (\d+) prestige (\d+) chips (\d+) golden (\d+) ascending (\d+) running (\d+)", out or "")+ if not m:+ failures.append(f"{what}: no end state\n{(out or '')[-500:]}")+ return None+ keys = ("frames", "cookies", "earned", "cps", "clicks", "buildings", "upgrades", "achievements", "prestige",+ "chips", "golden", "ascending", "running")+ return {k: float(v) if k == "cps" else int(v) for k, v in zip(keys, m.groups())}+++def play(saves, keys, frames, what, extra=()):+ shots = tempfile.mkdtemp(prefix="cc_shots_")+ out = run(["--saves", saves, "--out", shots, "--frames", str(frames), "--keys", keys, "--quiet"] + list(extra), what)+ shutil.rmtree(shots, ignore_errors=True)+ return end_state(out, what)+++def presses(start, key, n, gap=3):+ return ",".join(f"{start + i * gap}:{key}" for i in range(n))+++saves = tempfile.mkdtemp(prefix="cc_check_")+try:+ # the first start: the keys, then 20 clicks; a cursor bought (EXE on the store's first building); Home+ s = play(saves, "10:ok," + presses(20, "ok", 20) + ",100:exe,130:home", 200, "first start")+ if s:+ check(s["running"] == 0, "Home did not quit")+ check(s["clicks"] == 20 and s["buildings"] == 1, f"20 clicks and a cursor expected: {s}")+ for f in ("cookieclicker.sav", "cookieclicker_saves.py"):+ check(os.path.exists(os.path.join(saves, f)), f"{f} not written by Home")+ kept = tempfile.mkdtemp(prefix="cc_copy_")+ for f in os.listdir(saves):+ shutil.copy(os.path.join(saves, f), kept)++ # next time: no keys sheet, the bakery as it was; the cursor bakes+ s = play(saves, presses(10, "ok", 5) + ",400:home", 500, "continue")+ if s:+ check(s["clicks"] == 25 and s["buildings"] == 1 and s["earned"] >= 25, f"the bakery did not go on: {s}")++ # installing apps again erases everything but scripts: the save comes back from cookieclicker_saves.py+ for f in os.listdir(kept):+ if not f.endswith(".py"):+ os.remove(os.path.join(kept, f))+ s = play(kept, presses(10, "ok", 2) + ",60:home", 100, "from the copy")+ if s:+ check(s["clicks"] == 22 and s["buildings"] == 1, f"the copy did not bring the bakery back: {s}")++ # every screen: the store (arrows, bulk, sell), the menu and its pages, statistics' tabs, the rows+ keys = ",".join([+ presses(10, "down", 6, 4), "40:exe", "45:mul", "50:exe", "55:mul", "60:div", "65:exe", "70:div", "75:mul",+ presses(80, "up", 8, 4), presses(115, "right", 3, 4), "130:exe",+ "150:back", "160:down", "170:ok", presses(180, "down", 8, 4), "215:ok", "225:ok", "235:back", # options+ "245:down", "250:ok", presses(260, "right", 4, 5), presses(285, "down", 3, 5), "300:left", "310:back",+ "320:down", "325:ok", "335:down", "340:back", # info+ "350:back", "360:toolbox", presses(370, "right", 2, 6), presses(385, "down", 4, 4), "405:back",+ "420:alpha", presses(430, "down", 5, 4), "455:exe", "465:down", "470:back", "480:up", "485:exe", "495:ok",+ "510:alpha", "520:del", "525:del", "530:xnt", "540:var", "550:shift"])+ for preset in ("early", "mid", "late"):+ s = play(saves, keys, 600, f"screens ({preset})", ["--preset", preset])+ if s:+ check(s["running"] == 1, f"screens ({preset}): quit")+ # golden and wrath cookies clicked, wrinklers popped+ s = play(saves, "20:shift,40:shift", 60, "golden", ["--preset", "golden"])+ if s:+ check(s["golden"] >= 1, f"the golden cookie was not clicked: {s}")+ play(saves, "20:shift,40:shift", 60, "wrath", ["--preset", "wrath"])+ s = play(saves, presses(20, "var", 30, 2), 200, "wrinklers", ["--preset", "wrinklers"])+ # the Grimoire: every spell cast, the lump refill+ keys = ",".join([f"{20 + 30 * i}:{i + 1}" for i in range(9)] + ["300:down", "310:down", "320:exe", "330:back"])+ play(saves, keys, 400, "grimoire", ["--preset", "grimoire"])+ # an ascension: the Legacy prompt, the cookie bursting, the heavens (a heavenly upgrade bought, the arrows),+ # then reincarnated+ keys = ",".join(["10:back", "20:down", "25:down", "30:down", "40:ok", "50:ok", # Legacy, Ascend+ presses(260, "right", 3, 8), "300:exe", presses(310, "up", 3, 8), "340:exe", "350:shift",+ "360:shift", "380:back", "390:ok"])+ s = play(saves, keys, 480, "ascension", ["--preset", "late"])+ if s:+ check(s["ascending"] == 0 and s["prestige"] > 0 and s["cookies"] < 1e6, f"not ascended and back: {s}")+ s = play(saves, "10:back,20:down,25:down,30:down,40:ok,50:ok,400:home", 500, "quit while ascending",+ ["--preset", "late"])+ s = play(saves, "", 30, "back on the heavens")+ if s:+ check(s["ascending"] == 1, f"quitting while ascending did not come back to the heavens: {s}")++ # a robot plays (half an hour, or five minutes)+ robot = tempfile.mkdtemp(prefix="cc_robot_")+ frames = 9000 if QUICK else 54000+ s = play(robot, "10:ok", frames, "robot", ["--bot"])+ if s:+ check(s["buildings"] >= (40 if QUICK else 150) and s["cps"] > (20 if QUICK else 1000),+ f"the robot's bakery did not grow: {s}")+ shutil.rmtree(robot, ignore_errors=True)+finally:+ shutil.rmtree(saves, ignore_errors=True)++for f in failures:+ print("FAIL", f)+print("cookieclicker host checks:", "ok" if not failures else f"{len(failures)} failed")+sys.exit(1 if failures else 0)diff --git a/games/cookieclicker/tests/play.c b/games/cookieclicker/tests/play.cindex 57c0f0b4..dc4d76fa 100644--- a/games/cookieclicker/tests/play.c+++ b/games/cookieclicker/tests/play.c@@ -121,10 +121,13 @@ static void preset(const char *name) {S.lumps = 7, S.lumps_total = 9, S.lump_t = S.play_time - 1000;for (int a = 0; a < 60; a++) win(a);game_recount();- if (!strcmp(name, "golden")) shimmer_new(SHIMMER_GOLDEN, GC_NONE, false);+ if (!strcmp(name, "golden")) { /* (as one comes by itself) */+ Shimmer *m = shimmer_new(SHIMMER_GOLDEN, GC_NONE, false);+ if (m) m->spawn_lead = 1;+ }if (!strcmp(name, "wrath")) {Shimmer *m = shimmer_new(SHIMMER_GOLDEN, GC_NONE, false);- if (m) m->wrath = 1;+ if (m) m->wrath = 1, m->spawn_lead = 1;S.elder_wrath = 3;}if (!strcmp(name, "wrinklers")) {@@ -150,6 +153,10 @@ static void preset(const char *name) {}buy_upgrades(1e21);S.cookies = 7.7e20;+ bit_set(S.upgrades_bought, U_A_FESTIVE_HAT, true), bit_set(S.upgrades_bought, U_A_CRUMBLY_EGG, true);+ bit_set(S.upgrades_unlocked, U_A_FESTIVE_HAT, true), bit_set(S.upgrades_unlocked, U_A_CRUMBLY_EGG, true);+ S.santa_level = 6, S.dragon_level = 12, S.dragon_aura = AURA_DRAGON_CURSOR;+ S.buildings[B_WIZARD_TOWER].level = 3, S.buildings[B_GRANDMA].level = 5;S.lumps = 41, S.lumps_total = 60;for (int a = 0; a < 300; a++) win(a);game_recount();