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
Sokoban: Microban's walls as published, a warehouse keeper, brick walls; 50 levels in NumPlay
Mason3639f93b70c0860
diff --git a/games/games.json b/games/games.jsonindex caf1f13b..dc13bddd 100644--- a/games/games.json+++ b/games/games.json@@ -424,7 +424,7 @@"top": "0xC9843F","bottom": "0x2B2730","accent": "0xF2B53C",- "colors": 8,+ "colors": 11,"records": ["sokoban.sav"],diff --git a/games/sokoban/Makefile b/games/sokoban/Makefileindex 0f0f26c6..4d2f3c4d 100644--- a/games/sokoban/Makefile+++ b/games/sokoban/Makefile@@ -15,13 +15,14 @@ NWLINK ?= npx --yes -- [email protected]BUILD_DIR = outputSRC = src/main.cLEVELS = $(BUILD_DIR)/levels.inc-NUMPLAY_LEVELS ?= 60+NUMPLAY_LEVELS ?= 50HEADERS = ../common/epsilon_app.h ../common/epsilon_files.h ../common/np_text.h ../../launcher/src/gfx.h \../../launcher/src/np.h ../../launcher/src/font.h ../../launcher/src/inflate.hCFLAGS = -std=c11 $(shell $(NWLINK) eadk-cflags-device) -I$(BUILD_DIR)CFLAGS += -Os -Wall -Wextra -Wno-unused-parameter -fno-math-errno -fsingle-precision-constantCFLAGS += -fno-tree-loop-distribute-patterns -flto -fno-fat-lto-objects -fwhole-program -fvisibility=internal+CFLAGS += -fno-schedule-insns2 -fno-reorder-blocks -fno-tree-loop-optimize # (smaller)LDFLAGS = -Wl,--relocatable -nostartfiles --specs=nano.specsLDFLAGS += -Wl,-e,main -Wl,-u,eadk_app_name -Wl,-u,eadk_app_icon -Wl,-u,eadk_api_levelLDFLAGS += -Wl,--gc-sections -flinker-output=nolto-reldiff --git a/games/sokoban/docs/shot.png b/games/sokoban/docs/shot.pngindex 7c8069df..b2772c66 100644Binary files a/games/sokoban/docs/shot.png and b/games/sokoban/docs/shot.png differdiff --git a/games/sokoban/lang/fr.txt b/games/sokoban/lang/fr.txtindex 1ae9f27a..f29c2441 100644--- a/games/sokoban/lang/fr.txt+++ b/games/sokoban/lang/fr.txt@@ -9,13 +9,12 @@ No NonYes OuiPaused PauseSolved! Réussi !-Push every box onto a goal: one at a time, and never pulled.\nArrows: walk and push\nBackspace: undo Back: pause Pousse chaque caisse sur une cible : une à la fois, et jamais en tirant.\nFlèches : marcher et pousser\nEffacer : annuler Retour : pause+Push every box onto a goal: they can't be pulled.\nArrows: walk Backspace: undo\nBack: pause Pousse chaque caisse sur une cible : on ne peut pas les tirer.\nFlèches : marcher Effacer : annuler\nRetour : pausePlay JouerNext level Niveau suivantLevel NiveauMoves PasPushes PousséesSolve the levels before it to open it Réussis les niveaux d'avant pour l'ouvrir-Solved in moves: Réussi en pas :Not solved yet Pas encore réussiYour best: Ton record :diff --git a/games/sokoban/lang/zh.txt b/games/sokoban/lang/zh.txtindex bce4c0e8..7618dc78 100644--- a/games/sokoban/lang/zh.txt+++ b/games/sokoban/lang/zh.txt@@ -9,13 +9,12 @@ No 否Yes 是Paused 暂停Solved! 过关!-Push every box onto a goal: one at a time, and never pulled.\nArrows: walk and push\nBackspace: undo Back: pause 把每个箱子推到目标上:一次推一个,不能拉。\n方向键:走路、推箱子\n退格:撤销 返回:暂停+Push every box onto a goal: they can't be pulled.\nArrows: walk Backspace: undo\nBack: pause 把每个箱子推到目标上:箱子不能拉。\n方向键:走路 退格:撤销\n返回:暂停Play 开始Next level 下一关Level 关卡Moves 步数Pushes 推动Solve the levels before it to open it 先过前面的关卡才能打开-Solved in moves: 过关步数:Not solved yet 还没过关Your best: 最佳:diff --git a/games/sokoban/src/main.c b/games/sokoban/src/main.cindex cddd3023..d68a2ff8 100644--- a/games/sokoban/src/main.c+++ b/games/sokoban/src/main.c@@ -5,9 +5,9 @@* boxes one at a time, never pulling them; every step can be undone. A level opens while fewer* than three levels are left unsolved before it, and the fewest moves each was solved in are kept.*- * The levels are packed by tools/levels.py: only the floor, the goals, the boxes and the keeper (the- * walls are the cells around the floor), compressed with DEFLATE and unpacked into the strip buffer- * when a level opens. Only the rows a step changes are drawn again, in the launcher's strips+ * The levels are packed by tools/levels.py as Microban has them, but for the walls around the floor,+ * which the game puts back (the few that differ are written out), compressed with DEFLATE and unpacked+ * into the strip buffer when a level opens. Only the rows a step changes are drawn again, in the launcher's strips* (launcher/src/gfx.c). Inside NumPlay it uses the launcher's shapes, fonts, files and inflater; on* its own it brings them along. */#include <eadk.h>@@ -45,6 +45,7 @@ static uint32_t keys(void) {#define F_GOAL 2#define F_BOX 4#define F_WALL 8+#define F_NONE 16 /* (while a level opens) no wall here, though there is floor next to it */#define WHITE 0xFFFF#define BG HEX(0x2B2730) /* around the warehouse */@@ -66,7 +67,7 @@ static struct {static uint8_t g[MAXW * (MAXH + 2) + 2];#define G (g + MAXW + 1)static const int8_t off[4] = {-MAXW, 1, MAXW, -1}, ddx[4] = {0, 1, 0, -1}, ddy[4] = {-1, 0, 1, 0}; /* up, right... */-static uint8_t hist[HIST]; /* the steps taken: the way, and 4 for a push */+static uint8_t hist[HIST]; /* the steps taken: the way, and 4 for a push */static color_t strip[SCREEN_W * STRIP_H];static int level, rows, size, ox, oy, keeper, face, left, moves, pushes, nh, anim, moved;static int scr, ov, sel, pick, top, dlo, dhi;@@ -106,28 +107,26 @@ static void open_level(int n) {uint32_t tables[816]; /* np_inflate's two Huffman tables, 2 x 1632 bytes */const uint8_t *t = (const uint8_t *)strip;np_inflate((uint8_t *)strip, TEXT_BYTES, levels_z, sizeof levels_z, (np_inflate_tables_t *)(void *)tables);- for (int k = n; k; t++)- if (t[0] == '\n' && t[1] == '\n') k--, t++;+ for (int k = n; k; t++) k -= *t == '|';for (unsigned i = 0; i < sizeof g; i++) g[i] = 0;- int x = 1, y = 1, w = 0;- for (left = 0; *t != '\n' || x > 1; t++) {+ int x = 0, y = 0, w = 0;+ for (left = 0; *t != '|'; t++) {int c = *t, i = y * MAXW + x++;- if (c == '\n') y++, x = 1;- else if (c != ' ') {- for (int k = 0; k < 6; k++) /* floor, goal, box, box on a goal, the keeper, on a goal */- if (c == "-.$*@+"[k]) G[i] = (uint8_t)"\1\3\5\7\1\3"[k], keeper = k > 3 ? i : keeper;- left += c == '$';- }- if (x > w) w = x;+ if (c == '\n') y++, x = 0;+ for (int k = 0; k < 8; k++) /* floor, goal, box, box on a goal, the keeper (on a goal), a wall, no wall */+ if (c == "-.$*@+#_"[k]) G[i] = (uint8_t)"\1\3\5\7\1\3\10\20"[k], keeper = k == 4 || k == 5 ? i : keeper;+ left += c == '$';+ if (x + (G[i] & F_FLOOR) > w) w = x + (G[i] & F_FLOOR); /* (and the wall after the floor) */}rows = y + 1;- for (int i = 0; i < rows * MAXW; i++) /* walls on every cell next to the floor */+ for (int i = 0; i < rows * MAXW; i++) /* walls on every cell next to the floor, but where there are none */for (int d = 0; d < 9; d++)- if (!(G[i] & F_FLOOR) && G[i + (d / 3 - 1) * MAXW + d % 3 - 1] & F_FLOOR) G[i] = F_WALL;- size = (SCREEN_W - 8) / (w + 1);+ if (G[i] == F_NONE) G[i] = 0, d = 9;+ else if (!G[i] && G[i + (d / 3 - 1) * MAXW + d % 3 - 1] & F_FLOOR) G[i] = F_WALL;+ size = (SCREEN_W - 8) / w;if ((SCREEN_H - HDR - 8) / rows < size) size = (SCREEN_H - HDR - 8) / rows;if (size > 24) size = 24;- ox = (SCREEN_W - (w + 1) * size) / 2, oy = HDR + (SCREEN_H - HDR - rows * size) / 2;+ ox = (SCREEN_W - w * size) / 2, oy = HDR + (SCREEN_H - HDR - rows * size) / 2;level = sv.level = (uint8_t)n, moves = pushes = nh = anim = ov = 0, face = 2, scr = 1;mark(0, SCREEN_H);save();@@ -183,7 +182,7 @@ static void overlay(void) {gfx_fill_alpha(0, 0, SCREEN_W, SCREEN_H, 0, 110);gfx_rrect(40, y, 240, h, 12, BAR, 256);gfx_text_center(&np_font_title, 160, y + 32, panels[ov - 1][0], GOLD, 256);- y = gfx_paragraph(&np_font_body, 160, y + 54, 224, 16, ov == OV_HELP ? T("Push every box onto a goal: one at a time, and never pulled.\nArrows: walk and push\nBackspace: undo Back: pause") : ov == OV_DONE ? msg : "", CREAM, 256) - 12;+ y = gfx_paragraph(&np_font_body, 160, y + 54, 224, 16, ov == OV_HELP ? T("Push every box onto a goal: they can't be pulled.\nArrows: walk Backspace: undo\nBack: pause") : ov == OV_DONE ? msg : "", CREAM, 256) - 12;for (int i = 0; i < n; i++, y += 28) {if (sel == i) gfx_rrect(96, y, 128, 24, 12, GOLD, 256);gfx_text_center(&np_font_body, 160, y + 17, panels[ov - 1][i + 1], sel == i ? BAR : CREAM, 256);@@ -196,10 +195,12 @@ static void play_scene(void *ctx) {for (int i = 0; i < rows * MAXW; i++) {int x = ox + i % MAXW * s, y = oy + i / MAXW * s, f = G[i];if (y >= gfx_y1 || y + s <= gfx_y0) continue;- if (f & F_WALL) {- gfx_fill(x, y, s, s, HEX(0x5B3A26));- gfx_fill(x, y, s - 1, s - 1, HEX(0xB57D55));- gfx_fill(x + 1, y + 1, s - 2, s - 2, HEX(0x8C5A3A));+ if (f & F_WALL) { /* bricks, two rows a cell, the joints staggered */+ gfx_fill(x, y, s, s, HEX(0xA4613C));+ gfx_fill(x, y + s / 2 - 1, s, 1, HEX(0x5B3A26));+ gfx_fill(x, y + s - 1, s, 1, HEX(0x5B3A26));+ gfx_fill(x + s / 2, y, 1, s / 2, HEX(0x5B3A26));+ gfx_fill(x, y + s / 2, 1, s - s / 2, HEX(0x5B3A26));} else if (f) {gfx_fill(x, y, s, s, (i ^ i / MAXW) & 1 ? HEX(0xE4D7BC) : HEX(0xDCCDAF));if (f & F_GOAL) gfx_circle(x + s / 2, y + s / 2, s / 5 + 1, HEX(0xD2452F), 256);@@ -207,14 +208,13 @@ static void play_scene(void *ctx) {}}if (anim && moved >= 0) box(moved, ex, ey);- /* the keeper, looking the way he goes */- int cx = ox + keeper % MAXW * s + ex + s / 2, cy = oy + keeper / MAXW * s + ey + s / 2, r = s * 3 / 8;- int lx = ddx[face] * s / 8, ly = ddy[face] * s / 8;- gfx_circle(cx, cy, r, HEX(0x3C7BE8), 256);- for (int e = -s / 7; e <= s / 7; e += 2 * (s / 7)) {- gfx_circle(cx + e + lx, cy - s / 12 + ly, s / 8 + 1, WHITE, 256);- gfx_circle(cx + e + lx * 3 / 2, cy - s / 12 + ly * 3 / 2, s / 16 + 1, BAR, 256);- }+ /* the keeper: a warehouse man in blue overalls and a red cap, looking the way he goes */+ int cx = ox + keeper % MAXW * s + ex + s / 2, cy = oy + keeper / MAXW * s + ey + s / 2;+ gfx_rrect(cx - s * 5 / 16, cy - s / 16, s * 5 / 8, s * 7 / 16, s / 6, HEX(0x2F5FC4), 256);+ gfx_circle(cx, cy - s / 6, s / 4, HEX(0xF2C29B), 256);+ gfx_rrect(cx - s / 4, cy - s * 7 / 16, s / 2, s / 6 + 1, s / 12, HEX(0xC83A2C), 256);+ for (int e = -1; e <= 1 && face; e += 2) /* (from behind, no eyes) */+ gfx_fill(cx + e * s / 10 + ddx[face] * s / 10 - s / 32, cy - s / 7, s / 16 + 1, s / 10 + 1, BAR);gfx_fill(0, 0, SCREEN_W, HDR, BAR);put(line, T("Level "), (uint32_t)level + 1);gfx_text(&np_font_body, 8, 16, line, GOLD, 256);@@ -242,7 +242,7 @@ static void hub_scene(void *ctx) {put(cat(put(line, "", (uint32_t)n), " / "), "", LEVELS);gfx_text_right(&np_font_body, 308, 24, line, CREAM, 256);gfx_fill(0, 214, SCREEN_W, 26, BAR);- put(line, T("Solved in moves: "), sv.best[pick]);+ put(line, T("Your best: "), sv.best[pick]);if (sv.best[pick]) gfx_text_center(&np_font_body, 160, 232, line, CREAM, 256);if (ov) overlay();}diff --git a/games/sokoban/tools/levels.py b/games/sokoban/tools/levels.pyindex df39f707..a928cb34 100644--- a/games/sokoban/tools/levels.py+++ b/games/sokoban/tools/levels.py@@ -1,11 +1,10 @@#!/usr/bin/env python3"""Packs levels/microban.txt into output/levels.inc for the game.-Only what the keeper can reach is kept: the floor ('-'), the goals, the boxes and the keeper, in-the usual letters (. $ * @ +); everything else is a space. The walls are not stored: the game puts-one on every cell next to the floor, which is where they are (decorations that touch no floor-are left out). Rows end with a newline and a level with an empty line. The text is compressed with-raw DEFLATE (zopfli when it is there); the game inflates it when it opens a level.+The levels stay as Microban has them, in the usual letters (. $ * @ +, '-' for the floor), but for the+walls: the game puts one on every cell next to the floor, so only the few others are written ('#'),+and '_' where there is none next to the floor. The rows end with a newline, a level with '|'. The text+is compressed with raw DEFLATE (zopfli when it is there); the game inflates it when it opens a level.python3 tools/levels.py OUTDIR [LEVELS] (the first LEVELS levels; all of them by default)@@ -18,7 +17,7 @@ import zlibHERE = os.path.dirname(os.path.abspath(__file__))SOURCE = os.path.join(HERE, "..", "levels", "microban.txt")-MAXW, MAXH = 32, 18 # with the walls around: what the game's grid holds+MAXW, MAXH = 32, 18 # with the walls around: what the game's grid holds (a column to spare)def read(path=SOURCE):@@ -53,18 +52,28 @@ def reach(rows):def pack(rows):+ """The level's rows as the game reads them: the floor ('-'), the goals, the boxes and the keeper, and+ the walls only where they aren't the cells around the floor: '#' a wall there too, '_' none."""g, inside = reach(rows)- ys = [y for y, _ in inside]- xs = [x for _, x in inside]+ h, w = len(g), len(g[0])+ things = {(y, x) for y in range(h) for x in range(w) if g[y][x] in ".$*@+"}+ floor = inside | things # (boxes on goals walled in out of reach are drawn as Microban has them)+ walls = {(y, x) for y in range(h) for x in range(w) if g[y][x] == "#"}+ around = {(y + dy, x + dx) for y, x in floor for dy in (-1, 0, 1) for dx in (-1, 0, 1)} - floor+ cells = floor | walls | around+ ys, xs = [y for y, _ in cells], [x for _, x in cells]out = []for y in range(min(ys), max(ys) + 1):- r = "".join(("-" if g[y][x] == " " else g[y][x]) if (y, x) in inside else " "- for x in range(min(xs), max(xs) + 1))+ r = ""+ for x in range(min(xs), max(xs) + 1):+ p, c = (y, x), g[y][x] if 0 <= y < h and 0 <= x < w else " "+ r += ("-" if c == " " else c) if p in floor else "#" if p in walls - around else \+ "_" if p in around - walls else " "out.append(r.rstrip())text = "".join(out)assert text.count("$") + text.count("*") == text.count(".") + text.count("+") + text.count("*") > 0assert text.count("$") > 0, "something to push"- assert max(map(len, out)) + 2 <= MAXW and len(out) + 2 <= MAXH, "fits the grid"+ assert max(map(len, out)) + 1 <= MAXW and len(out) <= MAXH, "fits the grid"return out@@ -83,7 +92,8 @@ def main():every = len(levels)if len(sys.argv) > 2:levels = levels[:int(sys.argv[2])]- text = "".join("\n".join(r) + "\n\n" for r in levels).encode()+ text = "".join("\n".join(r) + "|" for r in levels).encode()+ assert len(text) <= 320 * 16 * 2, "fits the strip buffer the game unpacks it into"z = deflate(text)lines = ["/* Generated by tools/levels.py from levels/microban.txt. */",f"#define LEVELS {len(levels)}", f"#define ALL_LEVELS {every}", f"#define TEXT_BYTES {len(text)}",diff --git a/games/sokoban/tools/media.py b/games/sokoban/tools/media.pyindex 16704449..c4907950 100644--- a/games/sokoban/tools/media.py+++ b/games/sokoban/tools/media.py@@ -49,7 +49,7 @@ def gif(path, clips):def main():- for args, name in (([PLAY, "shot", "2", "build/shot.ppm"], "shot.png"), ([PLAY, "hub", "build/hub.ppm", "17"], "levels.png")):+ for args, name in (([PLAY, "shot", "1", "build/shot.ppm"], "shot.png"), ([PLAY, "hub", "build/hub.ppm", "17"], "levels.png")):subprocess.run(args, check=True, cwd=HERE)Image.open(os.path.join(HERE, args[-1] if name == "shot.png" else args[2])).convert("RGB").save(os.path.join(HERE, "docs", name), optimize=True)diff --git a/games/sokoban/tools/solve.py b/games/sokoban/tools/solve.pyindex d1cc6263..2c199794 100644--- a/games/sokoban/tools/solve.py+++ b/games/sokoban/tools/solve.py@@ -56,7 +56,7 @@ def assignment(cost):def solve(rows, limit=3000000):- cells = {(y, x) for y, r in enumerate(rows) for x, c in enumerate(r) if c != " "}+ cells = {(y, x) for y, r in enumerate(rows) for x, c in enumerate(r) if c in "-.$*@+"}at = {(y, x): c for y, r in enumerate(rows) for x, c in enumerate(r)}goals = sorted(p for p in cells if at[p] in ".*+")goal_set = frozenset(goals)