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
Sudoku: four levels of puzzles made on the calculator, notes, undo and hints
Mason363b73a98d5c895
diff --git a/docs/media/gallery/sudoku.gif b/docs/media/gallery/sudoku.gifnew file mode 100644index 00000000..3dcd3a7eBinary files /dev/null and b/docs/media/gallery/sudoku.gif differdiff --git a/docs/media/sudoku.gif b/docs/media/sudoku.gifnew file mode 100644index 00000000..bae6fc00Binary files /dev/null and b/docs/media/sudoku.gif differdiff --git a/docs/media/thumb_sudoku.png b/docs/media/thumb_sudoku.pngnew file mode 100644index 00000000..3ebbcb0aBinary files /dev/null and b/docs/media/thumb_sudoku.png differdiff --git a/games/games.json b/games/games.jsonindex b58c2c41..c9eda7d2 100644--- a/games/games.json+++ b/games/games.json@@ -398,6 +398,24 @@"app": "SpaceInvaders.nwa","repo": "https://github.com/Mason363/NumPlay/tree/main/games/invaders"},+ {+ "id": "sudoku",+ "title": "Sudoku",+ "tagline": "Fill the grid, 1 to 9",+ "credit": null,+ "top": "0x3F67B5",+ "bottom": "0x18243A",+ "accent": "0x8EC5FF",+ "colors": 3,+ "records": [+ "sudoku.sav"+ ],+ "shots": [+ "docs/card.png"+ ],+ "app": "Sudoku.nwa",+ "repo": "https://github.com/Mason363/NumPlay/tree/main/games/sudoku"+ },{"id": "numvisuals","title": "NumVisuals",diff --git a/games/sudoku/.gitignore b/games/sudoku/.gitignorenew file mode 100644index 00000000..342d9dda--- /dev/null+++ b/games/sudoku/.gitignore@@ -0,0 +1,2 @@+output/+build/diff --git a/games/sudoku/Makefile b/games/sudoku/Makefilenew file mode 100644index 00000000..d346745c--- /dev/null+++ b/games/sudoku/Makefile@@ -0,0 +1,86 @@+# Sudoku — fill the grid so every row, column and box holds 1 to 9 once.+# make build output/sudoku.nwa+# make check link the app like the calculator does (output/sudoku.bin)+# make host build/play: the game's rules on a computer+# make test every level's puzzles made and checked on a computer (one solution, the right level)+#+# In NumPlay the game draws with the launcher's strips, shapes and fonts and saves through its+# file functions (module.o leaves them to the launcher); on its own it brings them along.+Q ?= @+CC = arm-none-eabi-gcc+NWLINK ?= npx --yes -- [email protected]+BUILD_DIR = output+SRC = src/main.c+HEADERS = ../common/epsilon_app.h ../common/epsilon_files.h ../common/np_text.h ../../launcher/src/gfx.h \+ ../../launcher/src/np.h ../../launcher/src/font.h++CFLAGS = -std=c11 $(shell $(NWLINK) eadk-cflags-device)+CFLAGS += -Os -Wall -Wextra -Wno-unused-parameter -fno-math-errno -fsingle-precision-constant+# (smaller still: NumPlay has little room left)+CFLAGS += -fno-schedule-insns2 -fno-reorder-blocks -fno-tree-loop-optimize+CFLAGS += -fno-tree-loop-distribute-patterns -flto -fno-fat-lto-objects -fwhole-program -fvisibility=internal+LDFLAGS = -Wl,--relocatable -nostartfiles --specs=nano.specs+LDFLAGS += -Wl,-e,main -Wl,-u,eadk_app_name -Wl,-u,eadk_app_icon -Wl,-u,eadk_api_level+LDFLAGS += -Wl,--gc-sections -flinker-output=nolto-rel++.PHONY: build check clean host test+build: $(BUILD_DIR)/sudoku.nwa++check: $(BUILD_DIR)/sudoku.nwa+ $(Q) $(NWLINK) nwa-bin $< $(BUILD_DIR)/sudoku.bin+ @echo "BIN $(BUILD_DIR)/sudoku.bin: $$(wc -c < $(BUILD_DIR)/sudoku.bin) bytes"++# compiled, then linked (the link options would upset the compiler)+$(BUILD_DIR)/main.o: $(SRC) $(HEADERS) | $(BUILD_DIR)+ @echo "CC $<"+ $(Q) $(CC) $(CFLAGS) -c $(SRC) -o $@+$(BUILD_DIR)/gfx.o: ../../launcher/src/gfx.c $(HEADERS) | $(BUILD_DIR)+ $(Q) $(CC) $(CFLAGS) -c $< -o $@+$(BUILD_DIR)/font_data.o: ../../launcher/src/font_data.c ../../launcher/src/font.h | $(BUILD_DIR)+ $(Q) $(CC) $(CFLAGS) -c $< -o $@+$(BUILD_DIR)/xfont.o: ../../launcher/src/xfont.c ../../launcher/src/np_xfont.h $(HEADERS) | $(BUILD_DIR)+ $(Q) $(CC) $(CFLAGS) -c $< -o $@++$(BUILD_DIR)/sudoku.nwa: $(BUILD_DIR)/main.o $(BUILD_DIR)/gfx.o $(BUILD_DIR)/font_data.o $(BUILD_DIR)/xfont.o \+ $(BUILD_DIR)/icon.o+ @echo "LD $@"+ $(Q) $(CC) $(CFLAGS) $(LDFLAGS) $^ -o $@+ $(Q) arm-none-eabi-strip --strip-unneeded $@++$(BUILD_DIR)/icon.o: src/icon.png | $(BUILD_DIR)+ @echo "ICON $<"+ $(Q) $(NWLINK) png-icon-o $< $@++$(BUILD_DIR):+ $(Q) mkdir -p $@++clean:+ $(Q) rm -rf $(BUILD_DIR) build++# on a computer: tests/play.c makes puzzles and checks them, plays a game and draws its screens+HOST_FLAGS = -std=gnu11 -O1 -g -Wall -Wextra -Wno-unused-parameter -DPLATFORM_DEVICE=1 -DHOST \+ $(shell $(NWLINK) eadk-cflags-simulator) -fsanitize=address,undefined -fno-sanitize-recover=undefined+host: build/play+build/play: $(SRC) tests/play.c $(HEADERS)+ $(Q) mkdir -p build+ $(Q) cc $(HOST_FLAGS) tests/play.c ../../launcher/src/gfx.c ../../launcher/src/font_data.c \+ ../../launcher/src/xfont.c -lm -o $@+ @echo "HOST $@"+test: build/play+ build/play check++# NumPlay launcher: the app as a module (see ../../tools/npmodule.py) for the+# calculator, and as a relocatable object for the simulator build.+.PHONY: module sim-module+module: $(BUILD_DIR)/module.o+$(BUILD_DIR)/module-main.o: $(SRC) $(HEADERS) | $(BUILD_DIR)+ $(Q) $(CC) $(CFLAGS) -DNP_MODULE=1 -c $(SRC) -o $@+$(BUILD_DIR)/module.o: $(BUILD_DIR)/module-main.o+ $(Q) $(CC) $(CFLAGS) -Wl,--relocatable -nostartfiles -nostdlib -Wl,-e,main -flinker-output=nolto-rel $< -o $@++sim-module: $(BUILD_DIR)/sim-module.o+$(BUILD_DIR)/sim-module.o: $(SRC) $(HEADERS) | $(BUILD_DIR)+ $(Q) mkdir -p $(BUILD_DIR)/sim+ $(Q) cc -std=c11 -O2 -fPIC $(shell $(NWLINK) eadk-cflags-simulator) -DNP_MODULE=1 -Dmain=np_sudoku_main \+ -c $(SRC) -o $(BUILD_DIR)/sim/main.o+ $(Q) ld -r $(BUILD_DIR)/sim/main.o -exported_symbol _np_sudoku_main -o $@diff --git a/games/sudoku/README.md b/games/sudoku/README.mdnew file mode 100644index 00000000..d45cc275--- /dev/null+++ b/games/sudoku/README.md@@ -0,0 +1,39 @@+# Sudoku++Fill the grid so every row, column and 3×3 box holds the digits 1 to 9 once. Sudoku on the NumWorks calculator, played like the phone apps: a clean grid, the cell's row, column and box lit up, notes, undo and hints, and the calculator's own number keys to write with.++<img src="docs/shot.png" width="320" alt="A Medium game: the cell picked lights up its row, column and box, and every 4 on the grid">++- **Endless puzzles at four levels**, each made on the calculator in a fraction of a second, with one solution and the clues set symmetrically:+ - **Easy** and **Medium** can be solved with singles alone (a cell with one digit left, or a digit with one place left in a row, column or box), Medium with fewer clues;+ - **Hard** needs pointing: a digit that, in a box, can only go in one of its rows or columns, so it goes nowhere else in that row or column (or the other way round);+ - **Expert** needs more than that.+- **The usual highlights:** the row, column and box of the cell picked, and every cell with the same digit. Wrong digits turn red and count as mistakes.+- **Notes:** OK switches to pencil marks, small digits in the corners of a cell. Writing a digit takes its note off every cell it sees.+- **Undo** every move (notes included), **erase**, and **hints** that fill the cell picked, or the next one that isn't right yet.+- The digits on the right are laid out as on the keypad; the ones placed nine times fade.+- A clock, a mistake counter and the **best time** of each level. The game in progress is kept when you leave.++<img src="docs/notes.png" width="320" alt="Notes in two cells of the same box">++## Controls++| Key | Action |+| --- | --- |+| Arrows | Pick a cell (around the edges too) |+| 1 to 9 | Write that digit, or a note in notes mode |+| OK or EXE | Notes on and off |+| 0 | Erase the cell |+| ⌫ (DEL) | Undo |+| shift | Hint |+| Back | Menu: Resume, New game, How to play, Quit game |++## Credits++Sudoku is the number place puzzle, first published by Dell Magazines in 1979 and named in Japan by Nikoli. This version is written in C for NumPlay; its look and its controls follow the phone apps everyone knows. No puzzle is stored: a solver fills a grid at random and clues are taken out while one solution is left, then graded the way a player would solve them.++Inside NumPlay it draws with the launcher's own shapes and fonts and saves through its file functions, so the game is about 5 KB.++It comes inside [NumPlay](https://github.com/Mason363/NumPlay), or on its own as `Sudoku.nwa` from the [latest release](https://github.com/Mason363/NumPlay/releases/latest).++Build: `make` (needs `arm-none-eabi-gcc` and Node.js for nwlink). `make test` makes puzzles of every level on a computer and checks them.diff --git a/games/sudoku/docs/card.png b/games/sudoku/docs/card.pngnew file mode 100644index 00000000..c3eaaba4Binary files /dev/null and b/games/sudoku/docs/card.png differdiff --git a/games/sudoku/docs/levels.png b/games/sudoku/docs/levels.pngnew file mode 100644index 00000000..dc5eee2fBinary files /dev/null and b/games/sudoku/docs/levels.png differdiff --git a/games/sudoku/docs/notes.png b/games/sudoku/docs/notes.pngnew file mode 100644index 00000000..e97dba22Binary files /dev/null and b/games/sudoku/docs/notes.png differdiff --git a/games/sudoku/docs/shot.png b/games/sudoku/docs/shot.pngnew file mode 100644index 00000000..572c3223Binary files /dev/null and b/games/sudoku/docs/shot.png differdiff --git a/games/sudoku/lang/fr.txt b/games/sudoku/lang/fr.txtnew file mode 100644index 00000000..d2af14f9--- /dev/null+++ b/games/sudoku/lang/fr.txt@@ -0,0 +1,22 @@+# Sudoku in French: the English text as in the source, a tab, the translation (see tools/lang.py).+Paused Pause+Resume Reprendre+New game Nouvelle partie+How to play Comment jouer+Quit game Quitter la partie+OK again to quit OK encore pour quitter+Easy Facile+Medium Moyen+Hard Difficile+Expert Expert+Play Jouer+Solved! Résolu !+Making a puzzle... Création de la grille...+Fill the grid: every row, column and 3 x 3 box holds 1 to 9 once. Remplis la grille : chaque ligne, colonne et carré de 3 x 3 contient une fois les chiffres de 1 à 9.+New best! Record !+Mistakes: Erreurs :+OK notes OK notes+0 erase 0 effacer+DEL undo DEL annuler+shift hint shift indice+Back menu Back menudiff --git a/games/sudoku/lang/zh.txt b/games/sudoku/lang/zh.txtnew file mode 100644index 00000000..e63a2150--- /dev/null+++ b/games/sudoku/lang/zh.txt@@ -0,0 +1,22 @@+# Sudoku in Chinese: the English text as in the source, a tab, the translation (see tools/lang.py).+Paused 暂停+Resume 继续+New game 新游戏+How to play 玩法+Quit game 退出游戏+OK again to quit 再按 OK 退出+Easy 简单+Medium 中等+Hard 困难+Expert 专家+Play 开始+Solved! 完成!+Making a puzzle... 正在生成谜题……+Fill the grid: every row, column and 3 x 3 box holds 1 to 9 once. 填满格子:每一行、每一列和每个 3 x 3 宫都恰好包含 1 到 9。+New best! 新纪录!+Mistakes: 错误:+OK notes OK 笔记+0 erase 0 擦除+DEL undo DEL 撤销+shift hint shift 提示+Back menu Back 菜单diff --git a/games/sudoku/src/icon.png b/games/sudoku/src/icon.pngnew file mode 100644index 00000000..5bcff872Binary files /dev/null and b/games/sudoku/src/icon.png differdiff --git a/games/sudoku/src/main.c b/games/sudoku/src/main.cnew file mode 100644index 00000000..e6d9a45e--- /dev/null+++ b/games/sudoku/src/main.c@@ -0,0 +1,432 @@+/* Sudoku: fill the grid so every row, column and 3 x 3 box holds 1 to 9 once.+ *+ * Played like the phone apps: the number keys write a digit in the cell picked with the arrows,+ * OK switches to notes (small pencil digits), 0 erases, the backspace undoes, shift gives a hint.+ * The row, column and box of the cell light up, and so does every cell with its digit; a digit+ * placed takes its notes off the cells it sees. Wrong digits turn red and count as mistakes.+ *+ * Every puzzle is made on the calculator: a full grid solved at random, then clues taken out in+ * pairs facing each other (the grid stays symmetric) as long as one solution is left. Easy and+ * Medium can be solved with singles alone (a cell with one digit left, a digit with one place left+ * in a row, column or box), Medium with fewer clues; Hard needs more: a digit that in a box can+ * only go in one of its rows or columns (pointing), or the other way round; Expert needs more still.+ *+ * Inside NumPlay it draws with the launcher's strips, shapes and fonts (launcher/src/gfx.c) and+ * saves through its file functions; on its own (Sudoku.nwa) it brings them along. */+#include <eadk.h>+#include "../../../launcher/src/gfx.h"+#include "../../common/np_text.h"++#if NP_MODULE /* (np_file_read and np_file_write: NumPlay's, launcher/src/np.h) */+#define np_app_begin()+#define np_app_end() 0+#else+#include "../../common/epsilon_app.h"+#include "../../common/epsilon_files.h"+#define np_file_read ef_read+#define np_file_write ef_write+const char eadk_app_name[] __attribute__((section(".rodata.eadk_app_name"))) = "Sudoku";+const uint32_t eadk_api_level __attribute__((section(".rodata.eadk_api_level"))) = 0;+void np_push(int x, int y, int w, int h, const color_t *px) {+ eadk_display_push_rect((eadk_rect_t){(uint16_t)x, (uint16_t)y, (uint16_t)w, (uint16_t)h}, px);+}+#endif++/* the keys used, in 32 bits: the number pad's 9, 4 to 6, 1 to 3, 0 and EXE come down from the high word */+#define KEY(k) (1u << ((k) < 32 ? (k) : (k) - 23))+static uint32_t keys(void) {+ uint64_t s = eadk_keyboard_scan();+ return ((uint32_t)s & 0xC00211FFu) | ((uint32_t)(s >> 32) & 0x00111C71u) << 9;+}+static const uint8_t digit_key[9] = {19, 20, 21, 13, 14, 15, 30, 31, 9}; /* the bits of keys 1 to 9 */+#define PC 280 /* the middle of the panel right of the grid */+#define WHITE 0xFFFF+#define NAVY HEX(0x344861) /* the thick lines, the clues */+#define BLUE HEX(0x325AAF) /* the digits written, the buttons */+#define GREY HEX(0x6E7C8C) /* notes, labels */+#define LINE HEX(0xBEC6D4) /* the thin lines */+#define RED HEX(0xE55C6C)+#define PALE HEX(0xE2EBF3) /* the row, column and box of the cell picked */+#define SAME HEX(0xC3D7EA) /* the cells with its digit */+#define PICK HEX(0xBBDEFB) /* the cell picked */+#define TILE HEX(0xEAEEF4)++/* sudoku.sav: the game in progress and the best times */+static struct {+ uint8_t magic, version, flags, diff; /* flags: 1 a game to continue, 2 the guide was read */+ uint8_t sel, mistakes, pad[2];+ uint32_t secs, best[4]; /* seconds played; the best time of each level, 0 for none */+ uint8_t sol[81]; /* the solution */+ uint8_t val[81]; /* the digit in each cell, 0 for none; a clue's with 16 added */+ uint16_t notes[81]; /* the notes in each cell, bit d for digit d */+} sv;+#define SAVE_NAME "sudoku.sav"++static color_t strip[SCREEN_W * STRIP_H];+static uint32_t seed;+static int ov, sel, menu, quit_ok, notes, best_new; /* sel: the cell picked; menu: the button picked on a card */++static uint32_t rnd(void) {+ seed ^= seed << 13;+ seed ^= seed >> 17;+ return seed ^= seed << 5;+}++/* ------------------------------------------------------------ the rules */+/* units: rows 0-8, columns 9-17, boxes 18-26 */+static uint8_t unit[81][3], cells[27][9]; /* each cell's row, column and box; each unit's cells, in order */+static void units(void) {+ uint8_t n[27] = {0};+ for (int c = 0; c < 81; c++) {+ unit[c][0] = (uint8_t)(c / 9), unit[c][1] = (uint8_t)(9 + c % 9), unit[c][2] = (uint8_t)(18 + c / 27 * 3 + c % 9 / 3);+ for (int j = 0; j < 3; j++) cells[unit[c][j]][n[unit[c][j]]++] = (uint8_t)c;+ }+}+static bool in(int u, int c) { return unit[c][0] == u || unit[c][1] == u || unit[c][2] == u; }+static bool sees(int a, int b) { return unit[a][0] == unit[b][0] || unit[a][1] == unit[b][1] || unit[a][2] == unit[b][2]; }+#define at(u, i) cells[u][i]++static uint8_t g[81]; /* the grid being solved */+static uint16_t used[27]; /* the digits already in each row, column and box */+static uint16_t cand[81]; /* the digits each cell can still take */+static int nsol, wild; /* solutions found; wild: digits tried in a random order */++static void mark(int c, int d) {+ for (int j = 0; j < 3; j++) used[unit[c][j]] ^= (uint16_t)(1 << d);+}+static uint16_t free_at(int c) { return ~(used[unit[c][0]] | used[unit[c][1]] | used[unit[c][2]]) & 0x3FE; }+static void load_grid(const uint8_t *p) {+ for (int u = 0; u < 27; u++) used[u] = 0;+ for (int c = 0; c < 81; c++)+ if ((g[c] = p ? p[c] : 0)) mark(c, g[c]);+}++/* Counts the solutions, up to two, filling first the cell with fewest digits left; with wild,+ the first one goes in sv.sol. */+static bool search(void) {+ int best = -1, bn = 10;+ for (int c = 0; c < 81; c++)+ if (!g[c]) {+ int n = __builtin_popcount(free_at(c));+ if (n < bn) bn = n, best = c;+ }+ if (best < 0) {+ if (!nsol++ && wild)+ for (int c = 0; c < 81; c++) sv.sol[c] = g[c];+ return nsol > 1;+ }+ uint16_t m = free_at(best);+ int r = wild ? (int)(rnd() % 9) : 0;+ for (int i = 0; i < 9; i++) {+ int d = 1 + (i + r) % 9;+ if (!(m >> d & 1)) continue;+ g[best] = (uint8_t)d, mark(best, d);+ bool stop = search();+ g[best] = 0, mark(best, d);+ if (stop) return true;+ }+ return false;+}++/* How a player would solve it: 1 with singles alone, 2 with pointing too, 3 not with these. */+static int logic(const uint8_t *p) {+ int level = 1;+ load_grid(p);+ for (int c = 0; c < 81; c++) cand[c] = g[c] ? 0 : free_at(c);+ for (;;) {+ int left = 0, c = -1, u, d;+ for (int k = 0; k < 81; k++) /* a cell with one digit left */+ if (!g[k]) {+ left++;+ if (__builtin_popcount(cand[k]) == 1) c = k;+ }+ if (!left) return level;+ for (u = 0; u < 27 && c < 0; u++) /* a digit with one place left in a unit */+ for (d = 1; d <= 9; d++) {+ int n = 0, one = 0;+ for (int i = 0; i < 9; i++)+ if (cand[at(u, i)] >> d & 1) n++, one = at(u, i);+ if (n == 1) {+ cand[c = one] = (uint16_t)(1 << d);+ break;+ }+ }+ if (c >= 0) {+ d = __builtin_ctz(cand[c]);+ g[c] = (uint8_t)d;+ for (int k = 0; k < 81; k++)+ if (sees(c, k)) cand[k] &= (uint16_t)~(1 << d);+ continue;+ }+ /* a digit that, in a box, a row or a column, can only go where it meets another of them: it+ goes nowhere else in that other one */+ for (u = 0; u < 27; u++)+ for (int v = 0; v < 27; v++)+ for (d = 1; d <= 9 && (u < 18) != (v < 18); d++) {+ int n = 0, out = 0, gone = 0;+ for (int i = 0; i < 9; i++)+ if (cand[at(u, i)] >> d & 1) n++, out |= !in(v, at(u, i));+ for (int i = 0; i < 9 && n && !out; i++) {+ c = at(v, i);+ if (!in(u, c) && cand[c] >> d & 1) cand[c] ^= (uint16_t)(1 << d), gone = 1;+ }+ if (gone) goto harder;+ }+ return 3;+ harder:+ level = 2;+ }+}++static int solutions(const uint8_t *p) {+ load_grid(p);+ nsol = wild = 0;+ search();+ return nsol;+}++/* A new puzzle of level sv.diff (0-3) in sv.val, its solution in sv.sol. The pairs of clues are+ tried in a random order: a random start and step around the 41 pairs (41 is prime). */+static void generate(void) {+ static const uint8_t clues[4] = {36, 30, 0, 0};+ uint8_t p[81];+ int diff = sv.diff;+ for (int tries = 0;; tries++) {+ load_grid(0);+ nsol = 0, wild = 1;+ search();+ for (int c = 0; c < 81; c++) p[c] = sv.sol[c];+ int left = 81, at0 = (int)(rnd() % 41), step = 1 + (int)(rnd() % 40);+ for (int i = 0; i < 41; i++) {+ int c = (at0 + i * step) % 41, n = c == 40 ? 1 : 2;+ if (left - n < clues[diff]) continue;+ p[c] = p[80 - c] = 0;+ if (solutions(p) != 1 || (diff < 3 && logic(p) > (diff < 2 ? 1 : 2))) p[c] = sv.sol[c], p[80 - c] = sv.sol[80 - c];+ else left -= n;+ }+ if (diff < 2 || logic(p) == diff || tries > 80) break; /* (a Hard try ends Hard about 1 time in 10) */+ }+ for (int c = 0; c < 81; c++) sv.val[c] = (uint8_t)(p[c] ? p[c] + 16 : 0), sv.notes[c] = 0;+}++/* ------------------------------------------------------------ playing */+static uint32_t undo[256]; /* each change: the cell, its digit and notes before, and whether a move starts there */+static uint8_t utop, ucount;++static void set(int c, int v, int nt, int first) {+ undo[utop++] = (uint32_t)c | (uint32_t)sv.val[c] << 7 | (uint32_t)sv.notes[c] << 12 | (uint32_t)first << 31;+ if (ucount < 255) ucount++;+ sv.val[c] = (uint8_t)v, sv.notes[c] = (uint16_t)nt;+}++/* digit d in cell c: its notes go, and the cells it sees lose that note */+static void write(int c, int d) {+ if (sv.val[c] > 15 || sv.val[c] == d) return;+ set(c, d, 0, 1);+ sv.mistakes += d != sv.sol[c];+ int right = 0;+ for (int k = 0; k < 81; k++) {+ if (k != c && sees(c, k) && sv.notes[k] >> d & 1) set(k, sv.val[k], sv.notes[k] ^ 1 << d, 0);+ right += (sv.val[k] & 15) == sv.sol[k];+ }+ if (right == 81) { /* solved */+ sv.flags &= (uint8_t)~1, ov = 4, menu = 0; /* (OV_WON) */+ best_new = !sv.best[sv.diff] || sv.secs < sv.best[sv.diff];+ if (best_new) sv.best[sv.diff] = sv.secs;+ }+}++static void undo_move(void) {+ while (ucount) {+ uint32_t e = undo[--utop];+ ucount--;+ sv.val[e & 127] = (uint8_t)(e >> 7 & 31), sv.notes[e & 127] = (uint16_t)(e >> 12 & 0x3FE);+ if (e >> 31) break;+ }+}++/* a hint: the cell picked if it isn't right yet, otherwise the next one that isn't */+static void hint(void) {+ for (int i = 0; i < 81; i++) {+ int c = (sel + i) % 81;+ if ((sv.val[c] & 15) != sv.sol[c]) {+ write(sel = c, sv.sol[c]);+ return;+ }+ }+}++/* ------------------------------------------------------------ drawing */+static int cell_at(int i) { return 7 + 25 * i + i / 3; } /* the left (or top) of column (or row) i */++static char *num(char *o, uint32_t v) { /* v in o; the end of it */+ char t[10];+ int n = 0;+ do t[n++] = (char)('0' + v % 10); while (v /= 10);+ while (n) *o++ = t[--n];+ *o = 0;+ return o;+}+static char *clock_text(char *o, uint32_t s) { /* 4:05 */+ char *e = num(o, s / 60);+ *e++ = ':', *e++ = (char)('0' + s % 60 / 10), *e++ = (char)('0' + s % 10), *e = 0;+ return o;+}+static void say(const np_font_t *f, int x, int y, const char *s, color_t c) { gfx_text_center(f, x, y, s, c, 256); }+static void say_digit(const np_font_t *f, int x, int y, int d, color_t c) {+ char s[2] = {(char)('0' + d), 0};+ say(f, x, y, s, c);+}++enum { OV_NONE, OV_MENU, OV_LEVEL, OV_HELP, OV_WON };+/* each card: its title, then its buttons; what each button leads to (QUIT, NEW: a new game, made in+ a fraction of a second) */+static const char *const cards[5][5] = {+ {0},+ {T("Paused"), T("Resume"), T("New game"), T("How to play"), T("Quit game")},+ {T("New game"), T("Easy"), T("Medium"), T("Hard"), T("Expert")},+ {T("How to play"), T("Play")},+ {T("Solved!"), T("New game"), T("Quit game")},+};+#define QUIT 6+#define NEW 7+static const uint8_t buttons[5] = {0, 4, 4, 1, 2}, leads[5][4] = {+ {0}, {OV_NONE, OV_LEVEL, OV_HELP, QUIT}, {NEW, NEW, NEW, NEW}, {OV_NONE}, {OV_LEVEL, QUIT}};+#define LEVEL(i) cards[OV_LEVEL][1 + (i)]++static void overlay(void) {+ char s[16];+ int n = buttons[ov], extra = ov == OV_HELP || ov == OV_WON ? 56 : 0, y = (SCREEN_H - 54 - extra - 32 * n) / 2;+ gfx_fill_alpha(0, 0, SCREEN_W, SCREEN_H, NAVY, 110);+ gfx_rrect(60, y, 200, 54 + extra + 32 * n, 14, WHITE, 256);+ say(&np_font_title, 160, y + 34, cards[ov][0], NAVY);+ y += 48;+ if (ov == OV_HELP)+ gfx_paragraph(&np_font_body, 160, y + 12, 176, 15, T("Every row, column and box holds 1 to 9 once."), NAVY, 256);+ if (ov == OV_WON) {+ say(&np_font_title, 160, y + 16, clock_text(s, sv.secs), BLUE);+ say(&np_font_body, 160, y + 38, best_new ? T("New best!") : LEVEL(sv.diff), GREY);+ }+ y += extra;+ for (int i = 0; i < n; i++, y += 32) {+ color_t c = menu == i ? WHITE : NAVY;+ gfx_rrect(80, y, 160, 26, 13, menu == i ? BLUE : TILE, 256);+ say(&np_font_body, 160, y + 18, ov == OV_MENU && i == 3 && quit_ok ? T("OK again to quit") : cards[ov][i + 1], c);+ if (ov == OV_LEVEL && sv.best[i]) gfx_text_right(&np_font_small, 232, y + 17, clock_text(s, sv.best[i]), c, 256);+ }+}++static void scene(void *ctx) {+ static const char *const keys[] = {T("OK notes"), T("0 erase"), T("DEL undo"), T("shift hint"), T("Back menu")};+ char s[16];+ int pick = sv.val[sel] & 15, placed[10] = {0};+ gfx_fill(0, 0, SCREEN_W, SCREEN_H, WHITE);+ /* the grid: thin lines, the thick ones around the boxes, then the cells */+ gfx_fill(5, 5, 230, 230, LINE);+ for (int i = 0; i < 4; i++) gfx_fill(5 + 76 * i, 5, 2, 230, NAVY), gfx_fill(5, 5 + 76 * i, 230, 2, NAVY);+ for (int c = 0; c < 81; c++) {+ int x = cell_at(c % 9), y = cell_at(c / 9), v = sv.val[c] & 15;+ placed[v]++;+ gfx_fill(x, y, 24, 24, c == sel ? PICK : pick && v == pick ? SAME : sees(c, sel) ? PALE : WHITE);+ if (v) say_digit(&np_font_title, x + 12, y + 20, v, sv.val[c] > 15 ? NAVY : v != sv.sol[c] ? RED : BLUE);+ for (int d = 0; d < 9; d++)+ if (sv.notes[c] >> (d + 1) & 1) say_digit(&np_font_small, x + 4 + d % 3 * 8, y + 8 + d / 3 * 8, d + 1, GREY);+ }+ /* the panel: the level, the clock and the mistakes; the digits laid out as on the keypad, faded once+ all nine are placed; the keys, OK's lit while it writes notes */+ say(&np_font_body, PC, 17, LEVEL(sv.diff), GREY);+ say(&np_font_title, PC, 42, clock_text(s, sv.secs), NAVY);+ char *e = s;+ for (const char *m = T("Mistakes: "); *m;) *e++ = *m++;+ num(e, sv.mistakes);+ say(&np_font_small, PC, 56, s, sv.mistakes ? RED : GREY);+ for (int d = 0; d < 9; d++) {+ int x = 242 + d % 3 * 26, y = 124 - d / 3 * 28, on = d + 1 == pick;+ gfx_rrect(x, y, 24, 24, 5, on ? BLUE : TILE, 256);+ say_digit(&np_font_title, x + 12, y + 20, d + 1, on ? WHITE : placed[d + 1] < 9 ? NAVY : LINE);+ }+ if (notes) gfx_rrect(242, 152, 76, 20, 10, BLUE, 256);+ for (int i = 0; i < 5; i++) say(&np_font_small, PC, 166 + 15 * i, keys[i], i || !notes ? GREY : WHITE);+ if (ov) overlay();+}++static void draw(void) {+ eadk_display_wait_for_vblank();+ gfx_render(scene, 0, 0, SCREEN_H);+}++/* ------------------------------------------------------------ the game */+static void save(void) {+ sv.magic = 'S', sv.version = 1, sv.sel = (uint8_t)sel;+ np_file_write(SAVE_NAME, &sv, sizeof sv);+}++int main(void) {+ np_app_begin();+ color_t *their_strip = gfx_buf;+ gfx_buf = strip;+ units();+ uint32_t now = (uint32_t)eadk_timing_millis(), tick = now, repeat_at = 0, shown = ~0u, len = 0;+ seed = eadk_random() ^ now;+ if (!seed) seed = 1;+ /* the save; whatever it holds, a game this one could have saved */+ const uint8_t *d = np_file_read(SAVE_NAME, &len);+ bool ok = d && len == sizeof sv && d[0] == 'S' && d[1] == 1;+ for (uint32_t i = 0; i < sizeof sv; i++) ((uint8_t *)&sv)[i] = ok ? d[i] : 0;+ for (int c = 0; c < 81; c++)+ if (sv.sol[c] - 1u > 8 || (sv.val[c] & 15) > 9) sv.flags &= (uint8_t)~1;+ sel = sv.sel % 81, sv.diff &= 3;+ if (!(sv.flags & 2)) ov = OV_HELP, sv.flags |= 2;+ uint32_t held = keys(), stale = held; /* keys still down from the launcher wait to be let go */+ for (;;) {+ now = (uint32_t)eadk_timing_millis();+ uint32_t k = keys(), hit = k & ~held, arrows = k & 15 & ~(stale &= k);+ if (hit & 15) repeat_at = now + 250; /* an arrow held repeats */+ else if (arrows && (int32_t)(now - repeat_at) >= 0) hit |= arrows, repeat_at = now + 80;+ held = k;+ if (k & (KEY(eadk_key_home) | KEY(eadk_key_on_off))) break;+ int dx = !!(hit & KEY(eadk_key_right)) - !!(hit & KEY(eadk_key_left));+ int dy = !!(hit & KEY(eadk_key_down)) - !!(hit & KEY(eadk_key_up));+ ok = hit & (KEY(eadk_key_ok) | KEY(eadk_key_exe));+ if (ov) {+ int i = menu = (menu + dy) & (buttons[ov] - 1), to = ok ? leads[ov][i] : ov; /* (1, 2 or 4 buttons) */+ if (dy) quit_ok = 0;+ if (hit & KEY(eadk_key_back)) {+ if (ov == OV_LEVEL && !(sv.flags & 1)) break; /* nothing to go back to */+ if (ov != OV_WON) to = OV_NONE;+ }+ if (to == QUIT && (ov == OV_WON || quit_ok)) break;+ if (to == QUIT) to = OV_MENU, quit_ok = 1; /* Quit game asks first */+ if (to != ov) menu = to == OV_LEVEL ? sv.diff : 0;+ if (to == NEW) {+ sv.diff = (uint8_t)i, sv.secs = sv.mistakes = 0, sv.flags |= 1, ucount = 0, sel = 40;+ generate();+ to = OV_NONE;+ }+ ov = to;+ } else if (hit & KEY(eadk_key_back)) {+ ov = OV_MENU, menu = quit_ok = 0;+ } else if (hit) {+ int c = sel = (unit[sel][0] + dy + 9) % 9 * 9 + (unit[sel][1] + dx) % 9; /* (around the edges) */+ notes ^= ok;+ for (int d = 1; d <= 9; d++)+ if (hit >> digit_key[d - 1] & 1) {+ if (!notes) write(c, d);+ else if (!sv.val[c]) set(c, 0, sv.notes[c] ^ 1 << d, 1);+ }+ if (hit & KEY(eadk_key_zero) && sv.val[c] < 16) set(c, 0, 0, 1);+ if (hit & KEY(eadk_key_backspace)) undo_move();+ if (hit & KEY(eadk_key_shift)) hint();+ }+ if (!ov && !(sv.flags & 1)) ov = OV_LEVEL, menu = sv.diff; /* no game: choose one */+ if (hit) save();+ /* the clock runs while a game is played */+ if (!ov) sv.secs += (now - tick) / 1000, tick += (now - tick) / 1000 * 1000;+ else tick = now;+ if (hit || sv.secs != shown) shown = sv.secs, draw();+ eadk_timing_msleep(20);+ }+ save();+ gfx_buf = their_strip;+ return np_app_end();+}diff --git a/games/sudoku/tests/play.c b/games/sudoku/tests/play.cnew file mode 100644index 00000000..47fc7493--- /dev/null+++ b/games/sudoku/tests/play.c@@ -0,0 +1,247 @@+/* Sudoku on a computer, for tests and pictures (make host, make test).+ *+ * play check puzzles of every level made and checked: one solution, symmetric, the+ * right number of clues, solvable the way the level says; then a game played+ * with notes, mistakes, undo and hints, through to the end+ * play film DIR a game played with the keys, the screen saved as it goes (DIR/f_NNNN.ppm),+ * and the screens of the docs (DIR/shot_*.ppm)+ */+#define main sudoku_main+#include "../src/main.c"+#undef main+#include <stdio.h>+#include <stdlib.h>+#include <string.h>+#include <time.h>++static uint16_t fb[SCREEN_H][SCREEN_W];+void eadk_display_push_rect(eadk_rect_t r, const eadk_color_t *p) {+ for (int j = 0; j < r.height; j++)+ for (int i = 0; i < r.width; i++) fb[r.y + j][r.x + i] = p[j * r.width + i];+}+void eadk_display_push_rect_uniform(eadk_rect_t r, eadk_color_t c) {+ for (int j = 0; j < r.height; j++)+ for (int i = 0; i < r.width; i++) fb[r.y + j][r.x + i] = c;+}+bool eadk_display_wait_for_vblank(void) { return true; }+void *np_alloc(uint32_t size) { return malloc(size); }++/* the keys: a script of presses ("t key", one a line), each held 60 ms; the clock moves on as the+ game sleeps */+static uint64_t clock_ms;+static struct { uint64_t t; int key; } script[512];+static int nscript, nshots, frame;+static uint64_t shots[64];+static const char *dir;+uint64_t eadk_timing_millis(void) { return clock_ms; }+uint32_t eadk_random(void) { return 0x9E3779B9u; }+static void ppm(const char *path) {+ FILE *f = fopen(path, "wb");+ if (!f) return;+ fprintf(f, "P6 %d %d 255\n", SCREEN_W, SCREEN_H);+ for (int y = 0; y < SCREEN_H; y++)+ for (int x = 0; x < SCREEN_W; x++) {+ uint16_t c = fb[y][x];+ fputc((c >> 11) * 255 / 31, f), fputc((c >> 5 & 63) * 255 / 63, f), fputc((c & 31) * 255 / 31, f);+ }+ fclose(f);+}+void eadk_timing_msleep(uint32_t ms) {+ for (uint32_t i = 0; i < ms; i++) {+ clock_ms++;+ char path[512];+ for (int s = 0; s < nshots; s++)+ if (shots[s] == clock_ms) snprintf(path, sizeof path, "%s/shot_%d.ppm", dir, s), ppm(path);+ if (dir && clock_ms % 40 == 0) snprintf(path, sizeof path, "%s/f_%04d.ppm", dir, frame++), ppm(path);+ }+}+uint64_t eadk_keyboard_scan(void) {+ uint64_t k = 0;+ for (int i = 0; i < nscript; i++)+ if (clock_ms >= script[i].t && clock_ms < script[i].t + 60) k |= 1ull << script[i].key;+ return k;+}++static int fails;+#define CHECK(c, ...) do { if (!(c) && fails++ < 12) { printf("FAIL: " __VA_ARGS__); printf("\n"); } } while (0)++static bool valid_solution(const uint8_t *s) {+ for (int u = 0; u < 27; u++) {+ int m = 0;+ for (int i = 0; i < 9; i++) m |= 1 << s[at(u, i)];+ if (m != 0x3FE) return false;+ }+ return true;+}++static void check_puzzles(void) {+ static const int count[4] = {40, 40, 20, 12};+ for (int diff = 0; diff < 4; diff++) {+ int lo = 81, hi = 0, levels_seen[4] = {0};+ clock_t t0 = clock();+ for (int n = 0; n < count[diff]; n++) {+ seed = 0x1234567u * (uint32_t)(n + 1) + (uint32_t)diff * 7919u;+ sv.diff = (uint8_t)diff;+ generate();+ uint8_t p[81];+ int clues = 0;+ for (int c = 0; c < 81; c++) {+ p[c] = sv.val[c] & 15;+ clues += p[c] != 0;+ CHECK(!p[c] || sv.val[c] > 15, "a clue not marked as one");+ CHECK(!p[c] || p[c] == sv.sol[c], "a clue that isn't the solution's");+ }+ for (int c = 0; c < 81; c++) CHECK(!p[c] == !p[80 - c], "not symmetric (level %d, puzzle %d)", diff, n);+ CHECK(valid_solution(sv.sol), "the solution isn't one");+ CHECK(solutions(p) == 1, "not one solution (level %d, puzzle %d)", diff, n);+ int lv = logic(p);+ levels_seen[lv]++;+ if (diff < 2) CHECK(lv == 1, "level %d puzzle %d needs more than singles", diff, n);+ if (diff == 0) CHECK(clues >= 36, "too few clues for Easy (%d)", clues);+ if (diff == 2) CHECK(lv == 2, "Hard puzzle %d isn't Hard (%d)", n, lv);+ lo = clues < lo ? clues : lo, hi = clues > hi ? clues : hi;+ }+ printf("%-6s %2d puzzles, %d to %d clues, by singles %d, with pointing %d, beyond %d, %.0f ms each\n",+ LEVEL(diff), count[diff], lo, hi, levels_seen[1], levels_seen[2], levels_seen[3],+ (double)(clock() - t0) * 1000 / CLOCKS_PER_SEC / count[diff]);+ if (diff == 3) CHECK(levels_seen[3] * 2 >= count[3], "most Expert puzzles should need more than pointing");+ }+}++/* a game: notes, a mistake, undo, then hints to the end */+static void check_play(void) {+ seed = 99, sv.diff = 1, sv.flags = 1, ucount = 0, sel = 0;+ generate();+ int c = 0;+ while (sv.val[c]) c++;+ int wrong = sv.sol[c] % 9 + 1, other = 80;+ while (sv.val[other] || !sees(c, other) || other == c) other--;+ sv.notes[other] = (uint16_t)(1 << wrong | 1 << sv.sol[c]);+ write(c, wrong);+ CHECK(sv.val[c] == wrong && sv.mistakes == 1, "a wrong digit isn't counted");+ CHECK(!(sv.notes[other] >> wrong & 1), "the digit's note stays in a cell that sees it");+ undo_move();+ CHECK(sv.val[c] == 0 && sv.notes[other] >> wrong & 1, "undo doesn't bring back the cell and the note");+ sel = c;+ for (int i = 0; i < 81 && (sv.flags & 1); i++) hint();+ int right = 0;+ for (int k = 0; k < 81; k++) right += (sv.val[k] & 15) == sv.sol[k];+ CHECK(right == 81 && !(sv.flags & 1) && ov == 4, "hints don't finish the game");+ CHECK(sv.best[1] == sv.secs, "the best time isn't kept");+}++/* A film of a game: how to play, the levels, then a Medium game played with the keys: notes in+ two cells, a digit that takes a note away, a mistake undone, hints, the menu. The puzzle is the+ one the game will make (the same seed), so the keys can go where they need to. */+static uint64_t ft;+static int fsel;+static void press(int key, int wait) { script[nscript].t = ft, script[nscript++].key = key, ft += (uint64_t)wait; }+static int digit_code(int d) { return 42 - 6 * ((d - 1) / 3) + (d - 1) % 3; }+static void go(int c) { /* the arrows to cell c */+ while (fsel % 9 < c % 9) press(eadk_key_right, 160), fsel++;+ while (fsel % 9 > c % 9) press(eadk_key_left, 160), fsel--;+ while (fsel / 9 < c / 9) press(eadk_key_down, 160), fsel += 9;+ while (fsel / 9 > c / 9) press(eadk_key_up, 160), fsel -= 9;+ ft += 200;+}+static void film(void) {+ seed = 0x9E3779B9u, sv.diff = 1;+ generate();+ uint8_t sol[81], val[81];+ memcpy(sol, sv.sol, 81), memcpy(val, sv.val, 81);+ memset(&sv, 0, sizeof sv);+ /* two empty cells in the same box, near the middle */+ int a = -1, b = -1;+ for (int i = 0; i < 81 && b < 0; i++) {+ int c = (40 + i) % 81;+ if (val[c]) continue;+ if (a < 0) a = c;+ else if (unit[c][2] == unit[a][2] && sol[c] != sol[a]) b = c;+ }+ int other = sol[a] % 9 + 1 == sol[b] ? (sol[a] + 1) % 9 + 1 : sol[a] % 9 + 1; /* a note that isn't b's */+ ft = 1500, fsel = 40;+ shots[nshots++] = 1400; /* how to play */+ press(eadk_key_ok, 400);+ press(eadk_key_down, 300);+ shots[nshots++] = ft; /* the levels */+ press(eadk_key_ok, 900);+ go(a);+ press(eadk_key_ok, 300); /* notes */+ press(digit_code(sol[a]), 250), press(digit_code(other), 250), press(digit_code(sol[b]), 300);+ go(b);+ press(digit_code(sol[a]), 250), press(digit_code(sol[b]), 300);+ press(eadk_key_ok, 400); /* notes off */+ shots[nshots++] = ft; /* notes */+ press(digit_code(sol[b] % 9 + 1), 900); /* a mistake */+ shots[nshots++] = ft - 200;+ press(eadk_key_backspace, 500); /* undone */+ press(digit_code(sol[b]), 900); /* right: b's digit leaves a's notes */+ go(a);+ press(eadk_key_shift, 700); /* a hint */+ press(eadk_key_shift, 900);+ shots[nshots++] = ft - 200; /* the game */+ press(eadk_key_back, 1200);+ shots[nshots++] = ft - 300; /* the menu */+ press(eadk_key_back, 800);+ press(eadk_key_home, 300);+ sudoku_main();+}++/* The launcher's card (192 x 144): the game's screen drawn small and sharp rather than shrunk, so+ it packs into little flash: a game of the level asked as it starts, a cell picked. */+static int card_at(int i) { return 3 + 2 + 15 * i + i / 3; }+static int card_pad = 1; /* the keypad's digits on the card too */+static void card_scene(void *ctx) {+ char s[8];+ int pick = sel < 0 ? 0 : sv.val[sel] & 15;+ gfx_fill(0, 0, SCREEN_W, SCREEN_H, WHITE);+ gfx_fill(3, 3, 140, 140, NAVY);+ for (int b = 0; b < 9; b++) gfx_fill(card_at(b % 3 * 3), card_at(b / 3 * 3), 44, 44, HEX(0xBEC6D4));+ for (int c = 0; c < 81; c++) {+ int x = card_at(c % 9), y = card_at(c / 9), v = sv.val[c] & 15;+ gfx_fill(x, y, 14, 14, sel < 0 ? WHITE : c == sel ? PICK : pick && v == pick ? SAME : sees(c, sel) ? PALE : WHITE);+ if (v) s[0] = (char)('0' + v), s[1] = 0, gfx_text_center(&np_font_body, x + 7, y + 12, s, sv.val[c] > 15 ? NAVY : BLUE, 256);+ }+ gfx_text_center(&np_font_small, 168, 14, LEVEL(sv.diff), GREY, 256);+ gfx_text_center(&np_font_body, 168, 30, "4:05", NAVY, 256);+ for (int d = 1; d <= 9 && card_pad; d++) {+ int x = 148 + (d - 1) % 3 * 14, y = 40 + (2 - (d - 1) / 3) * 16;+ gfx_rrect(x, y, 13, 15, 3, d == pick ? BLUE : TILE, 256);+ s[0] = (char)('0' + d), s[1] = 0;+ gfx_text_center(&np_font_small, x + 7, y + 11, s, d == pick ? WHITE : NAVY, 256);+ }+}+static void card(const char *path, int diff, int pick, int written, uint32_t from) {+ seed = from, sv.diff = (uint8_t)diff, sv.flags = 1 | 2, sv.secs = 0, sel = pick, card_pad = !(written & 2);+ generate();+ for (int c = 0; c < 81 && written & 1; c++) /* a few digits already written */+ if (!sv.val[c] && (c * 7) % 5 == 0) sv.val[c] = sv.sol[c];+ gfx_buf = strip;+ gfx_render(card_scene, 0, 0, SCREEN_H);+ FILE *f = fopen(path, "wb");+ if (!f) return;+ fprintf(f, "P6 192 144 255\n");+ for (int y = 0; y < 144; y++)+ for (int x = 0; x < 192; x++) {+ uint16_t c = fb[y][x];+ fputc((c >> 11) * 255 / 31, f), fputc((c >> 5 & 63) * 255 / 63, f), fputc((c & 31) * 255 / 31, f);+ }+ fclose(f);+}++int main(int argc, char **argv) {+ units();+ if (argc > 5 && !strcmp(argv[1], "card")) { /* card PATH LEVEL CELL FLAGS [SEED] */+ card(argv[2], atoi(argv[3]), atoi(argv[4]), atoi(argv[5]), argc > 6 ? (uint32_t)atol(argv[6]) : 4242);+ return 0;+ }+ if (argc > 2 && !strcmp(argv[1], "film")) {+ dir = argv[2];+ film();+ return 0;+ }+ check_puzzles();+ check_play();+ printf(fails ? "%d checks failed\n" : "all checks passed\n", fails);+ return fails != 0;+}diff --git a/launcher/lang/fr.txt b/launcher/lang/fr.txtindex f4239505..bd8a8922 100644--- a/launcher/lang/fr.txt+++ b/launcher/lang/fr.txt@@ -97,6 +97,9 @@ Block Breaker Casse-briquesBreak every brick Casse toutes les briques2 Players 2 joueursPong and more, side by side Pong et plus, côte à côte+Cookie Clicker Cookie Clicker+Click the cookie, bake billions Clique le cookie, cuis des milliards+Fill the grid, 1 to 9 Remplis la grille, de 1 à 9Backgrounds, clocks, timers Fonds, horloges, minuteursReach the door, trust nothing Atteins la porte, ne te fie à rienStop the invasion, one cannon Arrête l'invasion avec un seul canon@@ -108,6 +111,7 @@ NumDrive NumDriveNumVisuals NumVisualsLevel Devil Level DevilSpace Invaders Space Invaders+Sudoku Sudoku# the games' creditsInspired by Minecraft, not affiliated with Mojang Inspiré de Minecraft, sans lien avec MojangBy Tatone26, from All the Apps Par Tatone26, tiré d'All the Appsdiff --git a/launcher/lang/zh.txt b/launcher/lang/zh.txtindex 36870f70..50857471 100644--- a/launcher/lang/zh.txt+++ b/launcher/lang/zh.txt@@ -96,6 +96,10 @@ Block Breaker 打砖块Break every brick 打碎每一块砖2 Players 双人对战Pong and more, side by side Pong 等游戏,两人并肩玩+Cookie Clicker Cookie Clicker+Click the cookie, bake billions 点击饼干,烤出亿万饼干+Sudoku 数独+Fill the grid, 1 to 9 填满九宫格,1 到 9Backgrounds, clocks, timers 背景、时钟、计时器Reach the door, trust nothing 走到门口,什么都别相信Space Invaders 太空侵略者diff --git a/tests/test_games.py b/tests/test_games.pyindex e80bce2c..a0616e5f 100644--- a/tests/test_games.py+++ b/tests/test_games.py@@ -119,6 +119,9 @@ GAMES = {presses((1500, "ok"), (2600, "right", 700), (3500, "ok"), (4100, "ok"), (4700, "ok"), (5300, "ok")), 6000,presses((1500, "ok"), (2600, "right", 700), (3500, "ok"), (4100, "ok"), (4700, "ok"), (5300, "ok"),(5900, "ok")), 6500),+ # past how to play, an Easy puzzle made, two hints; next time the game goes on: one more+ "sudoku": ("Sudoku.nwa", "sudoku.sav", presses((1500, "ok"), (2000, "ok"), (3500, "shift"), (4000, "shift")), 5500,+ presses((1500, "shift")), 3000),# the intro film is skipped (seen), Lucky walks up the dock and talks to the# guardians; next time the game starts where it was left"championisland": ("ChampionIsland.nwa", "champion.sav",@@ -309,6 +312,9 @@ CHECKS = {# Air Hockey and the easy computer chosen; then the normal computer and Tanks, the tallies kept"twoplayer": (lambda v: len(v) == 36 and v[:4] == b"P\1\1\1",lambda v: len(v) == 36 and v[:4] == b"P\1\2\2"),+ # a game kept (Easy, the guide read) with the two digits the hints wrote (the digits at 109); then three+ "sudoku": (lambda v: len(v) == 352 and v[:4] == b"S\1\3\0" and sum(1 <= b <= 9 for b in v[109:190]) == 2,+ lambda v: v[2] & 1 and sum(1 <= b <= 9 for b in v[109:190]) == 3),}