Skip to content

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.

Meowdoku: Oakever Games' cat puzzle, with its own puzzles in its order

Mason363212a1cc3a9e4
diff --git a/Makefile b/Makefile
index 75495277..da11e98d 100644
--- a/Makefile
+++ b/Makefile
@@ -18,7 +18,7 @@ PY ?= python3
CARGO ?= cargo
B = build/data
# Conventional games honor a configurable output directory; special layouts are kept local.
-GAMES_REDIRECT = angrybirds badtime balatro blockblast breakout buckshot celeste championisland chess connectfour cookieclicker coreball dinorun donkeykong doodlejump doom dune finalearth2 flappybird flappydunk fnaf fnf g2048 hillclimb hollowknight invaders isaac jetpackjoyride leveldevil minesweeper monkeymart numblocks numpowder numvisuals pacman paperclips polytrack portal pvz snake sokoban solitaire sonic stickmanhook subway sudoku suika tombofthemask towerblock turborush twoplayer undertale uno uttt
+GAMES_REDIRECT = angrybirds badtime balatro blockblast breakout buckshot celeste championisland chess connectfour cookieclicker coreball dinorun donkeykong doodlejump doom dune finalearth2 flappybird flappydunk fnaf fnf g2048 hillclimb hollowknight invaders isaac jetpackjoyride leveldevil meowdoku minesweeper monkeymart numblocks numpowder numvisuals pacman paperclips polytrack portal pvz snake sokoban solitaire sonic stickmanhook subway sudoku suika tombofthemask towerblock turborush twoplayer undertale uno uttt
GAMES_OUT = dinorun
GAME_REDIRECT_ARG = $(if $(filter $(1),$(GAMES_OUT)),OUT=../../$(B)/games/$(1),BUILD_DIR=../../$(B)/games/$(1))
# the RAM the oldest calculator software that runs apps gives them (23.2: 148928 bytes; 25.2 gives 153676).
diff --git a/README.md b/README.md
index d18d9568..4ad4ee1a 100644
--- a/README.md
+++ b/README.md
@@ -89,6 +89,8 @@ Want just one game? Each one also comes as its own file on the [downloads page](
**NumVisuals**, moving backgrounds with a clock, a stopwatch, a timer or a counter on top, comes on its own: [download NumVisuals.nwa](https://github.com/Mason363/NumPlay/releases/latest/download/NumVisuals.nwa), or add it to NumPlay in [NumPlay Studio](https://mason363.github.io/NumPlay/customize/). Its backgrounds are also in NumPlay: press ⌫ on the home screen.
+**Meowdoku**, Oakever Games' cat puzzle (one cat in every row, column and color), comes on its own too: [download Meowdoku.nwa](https://github.com/Mason363/NumPlay/releases/latest/download/Meowdoku.nwa), or add it to NumPlay in [NumPlay Studio](https://mason363.github.io/NumPlay/customize/).
+
## Big games, installed on their own
These are too big to fit next to NumPlay, so each one is its own app. Install it without NumPlay.
@@ -292,6 +294,7 @@ Read **[Make your own NumWorks game](docs/make-a-game.md)** to go from there, an
- [x] [NumPlay Studio](https://mason363.github.io/NumPlay/customize/), the website where you pick the games in your NumPlay, with Enlarged Extra Apps to fit several big games
- [x] Universal Paperclips
- [x] Bad Time Simulator: the Sans fight
+- [x] Meowdoku
- [ ] Full Minecraft 1.18.2 as a standalone app
- [ ] Among Us, against bots
- [ ] Cat Ninja
@@ -314,7 +317,6 @@ Read **[Make your own NumWorks game](docs/make-a-game.md)** to go from there, an
- [ ] Hungry Shark Evolution and Hungry Shark World
- [ ] Castle Crashers
- [ ] Hotline Miami
-- [ ] Meowdoku
- [ ] More of Retro-Go: Game & Watch, SNES, Mega Drive, SG-1000 and ColecoVision
- [ ] Five Nights at Freddy's 2, 3, 4 and FNAF World
- [ ] Brawl Stars, against bots
@@ -378,6 +380,7 @@ NumPlay is a fan project, made out of love for these games and for the NumWorks
- **[Cookie Clicker](https://orteil.dashnet.org/cookieclicker/)** by Orteil and Opti (DashNet) inspired NumPlay's Cookie Clicker, which uses the game's own pictures, texts and numbers (version 2.058, from its public mirror [ozh/cookieclicker](https://github.com/ozh/cookieclicker)) and the **Merriweather**, **Kavoon** and **Noto Sans** fonts (SIL Open Font License: [Merriweather](LICENSES/OFL-1.1-Merriweather.txt), [Kavoon](LICENSES/OFL-1.1-Kavoon.txt), [Noto Sans](LICENSES/OFL-1.1-NotoSans.txt)). Not affiliated with Orteil or DashNet.
- **Space Invaders** by Tomohiro Nishikado and Taito (1978, Midway in America) inspired NumPlay's Space Invaders, written in C for NumPlay from the arcade's rules with its pictures redrawn from the arcade's, under the Midway cabinet's coloured film.
- **Sokoban** by Hiroyuki Imabayashi (Thinking Rabbit, 1982) inspired NumPlay's Sokoban, written in C for NumPlay with no code or art from any Sokoban. Its levels are **Microban** by David W. Skinner (2000), used with credit to him.
+- **Meowdoku** by [Oakever Games](https://play.google.com/store/apps/details?id=com.oakever.meowdoku) inspired NumPlay's Meowdoku, which uses the game's own puzzles, cats, fish, lamp and colors from its Android package (version 1.23.0), and the **Nunito** font. Not affiliated with Oakever Games.
- **Sudoku**, the number place puzzle (Dell Magazines, 1979; named by Nikoli), is written in C for NumPlay: its puzzles are made on the calculator, and its look and controls follow the phone apps.
- **Ultimate tic-tac-toe** is a folk game, made widely known by [Ben Orlin's 2013 article](https://mathwithbaddrawings.com/2013/06/16/ultimate-tic-tac-toe/); NumPlay's is written in C for it.
@@ -400,7 +403,7 @@ NumPlay is a fan project, made out of love for these games and for the NumWorks
NumPlay is licensed under the [GNU General Public License v3.0](LICENSE). Copyright (c) 2026 Mason Chen. Code and fonts from others keep their own licenses: the `UNLICENSE` files in the games' folders and the [LICENSES](LICENSES) folder. The names, artwork and music of the games NumPlay is inspired by belong to their makers and are not covered by it.
-<sub>Unofficial fan games, not affiliated with NumWorks, RobTop Games (Geometry Dash), Hipster Whale (Crossy Road), the makers of Drive Mad, LocalThunk or Playstack (Balatro), Mike Klubnika or Critical Reflex (Buckshot Roulette), Hungry Studio (Block Blast!), Aladdin X (Suika Game), Voodoo (Flappy Dunk), Lima Sky (Doodle Jump), Mojang or Microsoft (Minecraft), Maddy Makes Games (Celeste), Team Cherry (Hollow Knight), Toby Fox (Undertale), jcw87 (Bad Time Simulator), id Software (Doom), Edmund McMillen, Florian Himsl or Nicalis (The Binding of Isaac), PopCap Games or Electronic Arts (Plants vs. Zombies), Scott Cawthon (Five Nights at Freddy's), SEGA (Sonic the Hedgehog, Master System, Game Gear), SYBO or Kiloo (Subway Surfers), Fingersoft (Hill Climb Racing), Unept (Level Devil), Halfbrick (Jetpack Joyride), Madbox (Stickman Hook), Nintendo (Donkey Kong, Game Boy, NES), Team Lava (Dune!), Inlogic Software (Dune Rider), TinyDobbins (Monkey Mart), Playgendary (Tomb of the Mask), Mattel (UNO), the Funkin' Crew (Friday Night Funkin'), W Production (Turbo Rush), Rovio Entertainment (Angry Birds), Kodub (PolyTrack), Frank Lantz or Everybody House Games (Universal Paperclips), Atari (Pong), Disney (Tron), Orteil or DashNet (Cookie Clicker), Taito or Midway (Space Invaders), Thinking Rabbit or Falcon (Sokoban), Florian van Strien (The Final Earth 2), The Powder Toy's developers (The Powder Toy), MateoConLechuga (Portal Returns), Valve (Portal), .GEARS (Flappy Bird), Bandai Namco (Pac-Man), Hasbro (Connect Four), Google (Snake, Solitaire, Block Breaker, Chrome Dino, Doodle Champion Island Games), STUDIO4°C or Microsoft (Minesweeper), ducalex (Retro-Go). Tetris is a trademark of The Tetris Company, Chrome of Google LLC, Minecraft of Mojang Synergies AB, Pac-Man of Bandai Namco, Connect Four of Hasbro, DOOM of ZeniMax Media, Sonic the Hedgehog, Master System and Game Gear of SEGA, Space Invaders of Taito, UNO of Mattel, Angry Birds of Rovio Entertainment, and Donkey Kong, Game Boy, Game Boy Color and NES of Nintendo.</sub>
+<sub>Unofficial fan games, not affiliated with NumWorks, RobTop Games (Geometry Dash), Hipster Whale (Crossy Road), the makers of Drive Mad, LocalThunk or Playstack (Balatro), Mike Klubnika or Critical Reflex (Buckshot Roulette), Hungry Studio (Block Blast!), Aladdin X (Suika Game), Voodoo (Flappy Dunk), Lima Sky (Doodle Jump), Mojang or Microsoft (Minecraft), Maddy Makes Games (Celeste), Team Cherry (Hollow Knight), Toby Fox (Undertale), jcw87 (Bad Time Simulator), id Software (Doom), Edmund McMillen, Florian Himsl or Nicalis (The Binding of Isaac), PopCap Games or Electronic Arts (Plants vs. Zombies), Scott Cawthon (Five Nights at Freddy's), SEGA (Sonic the Hedgehog, Master System, Game Gear), SYBO or Kiloo (Subway Surfers), Fingersoft (Hill Climb Racing), Unept (Level Devil), Halfbrick (Jetpack Joyride), Madbox (Stickman Hook), Nintendo (Donkey Kong, Game Boy, NES), Team Lava (Dune!), Inlogic Software (Dune Rider), TinyDobbins (Monkey Mart), Playgendary (Tomb of the Mask), Mattel (UNO), the Funkin' Crew (Friday Night Funkin'), W Production (Turbo Rush), Rovio Entertainment (Angry Birds), Kodub (PolyTrack), Frank Lantz or Everybody House Games (Universal Paperclips), Atari (Pong), Disney (Tron), Orteil or DashNet (Cookie Clicker), Taito or Midway (Space Invaders), Thinking Rabbit or Falcon (Sokoban), Oakever Games (Meowdoku), Florian van Strien (The Final Earth 2), The Powder Toy's developers (The Powder Toy), MateoConLechuga (Portal Returns), Valve (Portal), .GEARS (Flappy Bird), Bandai Namco (Pac-Man), Hasbro (Connect Four), Google (Snake, Solitaire, Block Breaker, Chrome Dino, Doodle Champion Island Games), STUDIO4°C or Microsoft (Minesweeper), ducalex (Retro-Go). Tetris is a trademark of The Tetris Company, Chrome of Google LLC, Minecraft of Mojang Synergies AB, Pac-Man of Bandai Namco, Connect Four of Hasbro, DOOM of ZeniMax Media, Sonic the Hedgehog, Master System and Game Gear of SEGA, Space Invaders of Taito, UNO of Mattel, Angry Birds of Rovio Entertainment, and Donkey Kong, Game Boy, Game Boy Color and NES of Nintendo.</sub>
## Gallery
@@ -471,33 +474,36 @@ NumPlay is licensed under the [GNU General Public License v3.0](LICENSE). Copyri
<td align="center"><img src="docs/media/gallery/sokoban.gif" alt="Sokoban: Microban's ninth level, pushed through to its goals"><br><a href="games/sokoban/README.md"><b>Sokoban</b></a></td>
</tr>
<tr>
+ <td align="center"><img src="docs/media/gallery/meowdoku.gif" alt="Meowdoku: a wrong cat costs a fish, the lamp crosses out what a cat rules out, the winking cat finds one more"><br><a href="games/meowdoku/README.md"><b>Meowdoku</b></a></td>
<td align="center"><img src="docs/media/gallery/retrogo.gif" alt="Retro-Go: from the Game Boy tab to the NES list, then Thwaite, a homebrew game, starts and fireworks stop the missiles"><br><a href="games/retrogo/README.md"><b>Retro-Go</b></a></td>
<td align="center"><img src="docs/media/gallery/flappydunk.gif" alt="Flappy Dunk: swishes in a row, the ball on fire"><br><a href="games/flappydunk/README.md"><b>Flappy Dunk</b></a></td>
- <td align="center"><img src="docs/media/gallery/towerblock.gif" alt="Tower Blocks: blocks dropped on the tower, the overhangs falling away"><br><a href="games/towerblock/README.md"><b>Tower Blocks</b></a></td>
</tr>
<tr>
+ <td align="center"><img src="docs/media/gallery/towerblock.gif" alt="Tower Blocks: blocks dropped on the tower, the overhangs falling away"><br><a href="games/towerblock/README.md"><b>Tower Blocks</b></a></td>
<td align="center"><img src="docs/media/gallery/coreball.gif" alt="Core Ball: every ball shot onto the spinning core, level 3 and level 4 cleared"><br><a href="games/coreball/README.md"><b>Core Ball</b></a></td>
<td align="center"><img src="docs/media/gallery/doodlejump.gif" alt="Doodle Jump: the doodler climbs past blue platforms and a monster"><br><a href="games/doodlejump/README.md"><b>Doodle Jump</b></a></td>
- <td align="center"><img src="docs/media/jetpackjoyride.gif" alt="Jetpack Joyride: Barry grabs coins and rides the Profit Bird until it hits a zapper, then flies on past a missile"><br><a href="games/jetpackjoyride/README.md"><b>Jetpack Joyride</b></a></td>
</tr>
<tr>
+ <td align="center"><img src="docs/media/jetpackjoyride.gif" alt="Jetpack Joyride: Barry grabs coins and rides the Profit Bird until it hits a zapper, then flies on past a missile"><br><a href="games/jetpackjoyride/README.md"><b>Jetpack Joyride</b></a></td>
<td align="center"><img src="docs/media/stickmanhook.gif" alt="Stickman Hook: two levels swung from hook to hook, each over the finish line"><br><a href="games/stickmanhook/README.md"><b>Stickman Hook</b></a></td>
<td align="center"><img src="docs/media/donkeykong.gif" alt="Donkey Kong: Mario climbs the 25m girders past rolling barrels to Pauline"><br><a href="games/donkeykong/README.md"><b>Donkey Kong</b></a></td>
- <td align="center"><img src="docs/media/dune.gif" alt="Dune: the ball rolls down the dunes, flies over the line for coins and lands Perfect Slides"><br><a href="games/dune/README.md"><b>Dune</b></a></td>
</tr>
<tr>
+ <td align="center"><img src="docs/media/dune.gif" alt="Dune: the ball rolls down the dunes, flies over the line for coins and lands Perfect Slides"><br><a href="games/dune/README.md"><b>Dune</b></a></td>
<td align="center"><img src="docs/media/monkeymart.gif" alt="Monkey Mart: the monkey carries bananas and milk to the shelves while the customers shop"><br><a href="games/monkeymart/README.md"><b>Monkey Mart</b></a></td>
<td align="center"><img src="docs/media/tombofthemask.gif" alt="Tomb of the Mask: dashing up the tomb ahead of the rising flood"><br><a href="games/tombofthemask/README.md"><b>Tomb of the Mask</b></a></td>
- <td align="center"><img src="docs/media/uno.gif" alt="UNO: a hand against three bots, a Draw Two and a colour called"><br><a href="games/uno/README.md"><b>UNO</b></a></td>
</tr>
<tr>
+ <td align="center"><img src="docs/media/uno.gif" alt="UNO: a hand against three bots, a Draw Two and a colour called"><br><a href="games/uno/README.md"><b>UNO</b></a></td>
<td align="center"><img src="docs/media/fnf.gif" alt="Friday Night Funkin': Ready, Set, Go, then the first notes of a song"><br><a href="games/fnf/README.md"><b>Friday Night Funkin'</b></a></td>
<td align="center"><img src="docs/media/turborush.gif" alt="Turbo Rush: racing along Sunset Coast, passing rivals before a bend"><br><a href="games/turborush/README.md"><b>Turbo Rush</b></a></td>
- <td align="center"><img src="docs/media/angrybirds.gif" alt="Angry Birds: the first level, aimed, fired and knocked down with one bird"><br><a href="games/angrybirds/README.md"><b>Angry Birds</b></a></td>
</tr>
<tr>
+ <td align="center"><img src="docs/media/angrybirds.gif" alt="Angry Birds: the first level, aimed, fired and knocked down with one bird"><br><a href="games/angrybirds/README.md"><b>Angry Birds</b></a></td>
<td align="center"><img src="docs/media/gallery/polytrack.gif" alt="PolyTrack: Desert 4, through the tube and on to the finish"><br><a href="games/polytrack/README.md"><b>PolyTrack</b></a></td>
<td align="center"><img src="docs/media/gallery/paperclips.gif" alt="Universal Paperclips: the first clips, a strategy tournament, the HypnoDrones, a battle against the drifters and the last clips"><br><a href="games/paperclips/README.md"><b>Universal Paperclips</b></a></td>
+ </tr>
+ <tr>
<td align="center"><img src="docs/media/gallery/badtime.gif" alt="Bad Time Simulator: Sans slams the blue heart into bones, then Gaster Blasters fire across the box"><br><a href="games/badtime/README.md"><b>Bad Time Simulator</b></a></td>
</tr>
</table>
diff --git a/_config.yml b/_config.yml
index 49e0feb6..c459a34f 100644
--- a/_config.yml
+++ b/_config.yml
@@ -1,5 +1,5 @@
title: NumPlay
-description: "29 games for the NumWorks calculator in one app: NumDash, Crossy Road, NumBlocks, NumDrive, Balatro, Buckshot Roulette, Block Blast, Suika Game, Portal Returns, Tetris, Chrome Dino, Chess, Space Invaders, Sudoku and more. And Doom, Sonic, Plants vs. Zombies, Cookie Clicker and more on their own. Free and open source, with a kit to make your own NumWorks games in C."
+description: "29 games for the NumWorks calculator in one app: NumDash, Crossy Road, NumBlocks, NumDrive, Balatro, Buckshot Roulette, Block Blast, Suika Game, Portal Returns, Tetris, Chrome Dino, Chess, Space Invaders, Sudoku and more. And Doom, Sonic, Plants vs. Zombies, Cookie Clicker, Meowdoku and more on their own. Free and open source, with a kit to make your own NumWorks games in C."
url: https://mason363.github.io
baseurl: /NumPlay
theme: jekyll-theme-cayman
diff --git a/docs/media/gallery/meowdoku.gif b/docs/media/gallery/meowdoku.gif
new file mode 100644
index 00000000..b4f9d38b
Binary files /dev/null and b/docs/media/gallery/meowdoku.gif differ
diff --git a/docs/media/meowdoku.gif b/docs/media/meowdoku.gif
new file mode 100644
index 00000000..4819cb34
Binary files /dev/null and b/docs/media/meowdoku.gif differ
diff --git a/docs/media/thumb_meowdoku.png b/docs/media/thumb_meowdoku.png
new file mode 100644
index 00000000..ee73ccf3
Binary files /dev/null and b/docs/media/thumb_meowdoku.png differ
diff --git a/docs/play.md b/docs/play.md
index cf52f6e7..af415d67 100644
--- a/docs/play.md
+++ b/docs/play.md
@@ -988,6 +988,24 @@ Push every crate onto a goal: the keeper pushes one at a time and can't pull, so
<br clear="right">
+## Meowdoku
+
+<img src="media/meowdoku.gif" width="320" align="right" alt="Meowdoku: level 1 won with the keys, then a 10×10 level: a wrong cat costs a fish, the lamp crosses out what a cat rules out, the winking cat finds one more">
+
+| Key | What it does |
+| --- | --- |
+| **Arrows** | Move on the board |
+| **OK** | Put an X, or take it off; hold OK and move to put X's along the way |
+| **OK twice** or **EXE** | Place a cat |
+| **shift** | Hint: shows the next step, OK does it |
+| **alpha** | Find a cat |
+| **⌫** | Take back X's |
+| **Back** | Pause: Resume, How to play, Quit game |
+
+Put one cat in every row, every column and every color, and never two cats touching, not even at a corner. A cat in the wrong cell turns into an X and costs a fish; with all three fish gone the level starts over. The boards grow from 4×4 to 10×10, every tenth level is hard, and the game gets harder while you win without hints or mistakes. Add it in NumPlay Studio, or get Meowdoku.nwa.
+
+<br clear="right">
+
## NumVisuals
<img src="media/numvisuals.gif" width="320" align="right" alt="NumVisuals: picking a background, then a clock">
diff --git a/games/games.json b/games/games.json
index 65f808d5..73c5a84b 100644
--- a/games/games.json
+++ b/games/games.json
@@ -570,6 +570,26 @@
"app": "Sokoban.nwa",
"repo": "https://github.com/Mason363/NumPlay/tree/main/games/sokoban"
},
+ {
+ "id": "meowdoku",
+ "rank": 28,
+ "title": "Meowdoku",
+ "tagline": "One cat per row, column and color",
+ "credit": "Based on Meowdoku by Oakever Games",
+ "top": "0xF7A23B",
+ "bottom": "0x6B3E1E",
+ "accent": "0xFFD43B",
+ "colors": 16,
+ "records": [
+ "meowdoku.sav"
+ ],
+ "shots": [
+ "docs/shot.png"
+ ],
+ "app": "Meowdoku.nwa",
+ "repo": "https://github.com/Mason363/NumPlay/tree/main/games/meowdoku",
+ "default": false
+ },
{
"id": "retrogo",
"rank": 30,
diff --git a/games/meowdoku/.gitignore b/games/meowdoku/.gitignore
new file mode 100644
index 00000000..342d9dda
--- /dev/null
+++ b/games/meowdoku/.gitignore
@@ -0,0 +1,2 @@
+output/
+build/
diff --git a/games/meowdoku/Makefile b/games/meowdoku/Makefile
new file mode 100644
index 00000000..b0558897
--- /dev/null
+++ b/games/meowdoku/Makefile
@@ -0,0 +1,84 @@
+# Meowdoku: one cat in every row, column and colour, and no two cats touching.
+# make build output/meowdoku.nwa
+# make check link the app like the calculator does (output/meowdoku.bin)
+# make host build/play: the game's rules on a computer
+# make test every puzzle checked (one solution, in all 8 turns), the dealing, a played game, random keys
+#
+# 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 = src/levels.h src/art.h ../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
+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)/meowdoku.nwa
+
+check: $(BUILD_DIR)/meowdoku.nwa
+ $(Q) $(NWLINK) nwa-bin $< $(BUILD_DIR)/meowdoku.bin
+ @echo "BIN $(BUILD_DIR)/meowdoku.bin: $$(wc -c < $(BUILD_DIR)/meowdoku.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)/meowdoku.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 checks the puzzles and the rules, plays games and draws their 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_meowdoku_main \
+ -c $(SRC) -o $(BUILD_DIR)/sim/main.o
+ $(Q) ld -r $(BUILD_DIR)/sim/main.o -exported_symbol _np_meowdoku_main -o $@
diff --git a/games/meowdoku/README.md b/games/meowdoku/README.md
new file mode 100644
index 00000000..7fa25040
--- /dev/null
+++ b/games/meowdoku/README.md
@@ -0,0 +1,38 @@
+# Meowdoku
+
+Put one cat in every row, every column and every color, and never two cats side by side, not even at a corner. Oakever Games' cat puzzle for the NumWorks calculator, with its own puzzles, cats and colors.
+
+<img src="docs/shot.png" width="320" alt="A 10×10 Meowdoku level part way: four cats found, X's on the cells they rule out, one fish lost">
+
+- **The game's own puzzles**, from its level banks, every one with exactly one solution, dealt the way the game deals them: 4×4 at level 1, then 5×5 up to 10×10 boards, a hard level every tenth, and the picture levels (a 1 at level 10, a 30 at level 30...) at the same numbers as on the phone.
+- **The difficulty follows you**: it climbs while you win without help or mistakes and comes down after you fail, with the game's own rules.
+- **Three fish**: a cat in the wrong cell turns into an X and costs a fish. Lose all three and the level starts over.
+- **The lamp** shows the next step you can work out (the X's a cat rules out, a row with one place left, a color held in one line...) and does it on OK. **The winking cat** finds one cat for you. Both count as help.
+- Levels 1 to 10 start with one cat in, as in the game. Your level and board are saved, so you can stop and carry on later.
+
+## Controls
+
+| Key | Action |
+| --- | --- |
+| Arrows | Move on the board |
+| OK | Put an X, or take it off; hold OK and move to put X's along the way |
+| OK twice, or EXE | Place a cat |
+| shift | Hint (the lamp) |
+| alpha | Find a cat (the winking cat) |
+| ⌫ | Take back X's |
+| Back | Menu: Resume, How to play, Quit game |
+
+## Good to know
+
+- The game has thousands of puzzles; this keeps the first ones of each of its puzzle pools (309 in all, the ones a player meets in the first few hundred levels). When a pool runs out, its puzzles come back turned and mirrored, as the game does with its own.
+- Ads, purchases, daily challenges, leaderboards and the online level picks are left out. Hints and Find are free: in the game they run out and come back with ads.
+
+## Credits
+
+Meowdoku is **[Oakever Games](https://play.google.com/store/apps/details?id=com.oakever.meowdoku)**' game. Its puzzles, cats, fish, lamp, colors and rules come from its Android package (version 1.23.0). Not affiliated with Oakever Games.
+
+Made by Mason Chen as part of NumPlay. Lettered in the **Nunito** font, and **Fusion Pixel** for Chinese (SIL Open Font License).
+
+It isn't in the default NumPlay.nwa: add it in [NumPlay Studio](https://mason363.github.io/NumPlay/customize/), or get it on its own as `Meowdoku.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` checks every puzzle, the hints and the dealing on a computer.
diff --git a/games/meowdoku/docs/hint.png b/games/meowdoku/docs/hint.png
new file mode 100644
index 00000000..785ec24c
Binary files /dev/null and b/games/meowdoku/docs/hint.png differ
diff --git a/games/meowdoku/docs/shot.png b/games/meowdoku/docs/shot.png
new file mode 100644
index 00000000..2c7782e8
Binary files /dev/null and b/games/meowdoku/docs/shot.png differ
diff --git a/games/meowdoku/docs/start.png b/games/meowdoku/docs/start.png
new file mode 100644
index 00000000..75084b3f
Binary files /dev/null and b/games/meowdoku/docs/start.png differ
diff --git a/games/meowdoku/lang/fr.txt b/games/meowdoku/lang/fr.txt
new file mode 100644
index 00000000..b4634420
--- /dev/null
+++ b/games/meowdoku/lang/fr.txt
@@ -0,0 +1,33 @@
+# Meowdoku in French: the English text as in the source, a tab, the translation (see tools/lang.py).
+A cat goes in this cell: take the X off. Un chat va dans cette case : enlevez le X.
+A cat here would leave a row, column or color with no room. Un chat ici laisserait une ligne, une colonne ou une couleur sans place.
+Back close Back fermer
+Clear! Réussi !
+Hard Difficile
+How to play Comment jouer
+Level Niveau
+Level Niveau
+Next level Niveau suivant
+OK X OK OK cat DEL undo Back menu OK X OK OK chat DEL annuler Back menu
+OK apply OK appliquer
+OK again to quit OK encore pour quitter
+OK marks an X. OK twice (or EXE) places a cat. A wrong cat costs a fish; with all 3 gone, try again. OK met un X. OK deux fois (ou EXE) place un chat. Un mauvais chat coûte un poisson ; sans les 3, on recommence.
+One cat in each row, each column and each color. Cats can't touch, not even at the corners. Un chat dans chaque ligne, chaque colonne et chaque couleur. Les chats ne se touchent pas, même par un coin.
+Only one cell in this column can take a cat. Une seule case de cette colonne peut recevoir un chat.
+Only one cell in this row can take a cat. Une seule case de cette ligne peut recevoir un chat.
+Only one cell of this color can take a cat. Une seule case de cette couleur peut recevoir un chat.
+Out of fish Plus de poissons
+Paused Pause
+Perfect! Parfait !
+Play Jouer
+Quit game Quitter la partie
+Resume Reprendre
+These colors fill these lines between them, so nothing else in the lines can have a cat. Ces couleurs remplissent ces rangées à elles seules : rien d'autre dans ces rangées n'a de chat.
+This cat rules out its row, its column and the cells around it. Ce chat exclut sa ligne, sa colonne et les cases autour.
+This color's cat must be in this line, so the rest of the line can't have one. Le chat de cette couleur est dans cette rangée : le reste de la rangée n'en a pas.
+This line's cat must be in this color, so the rest of the color can't have one. Le chat de cette rangée est dans cette couleur : le reste de la couleur n'en a pas.
+Try again Réessayer
+alpha alpha
+find trouver
+hint indice
+shift shift
diff --git a/games/meowdoku/lang/zh.txt b/games/meowdoku/lang/zh.txt
new file mode 100644
index 00000000..ce821535
--- /dev/null
+++ b/games/meowdoku/lang/zh.txt
@@ -0,0 +1,33 @@
+# Meowdoku in Chinese: the English text as in the source, a tab, the translation (see tools/lang.py).
+A cat goes in this cell: take the X off. 这一格有猫:把 X 去掉。
+A cat here would leave a row, column or color with no room. 猫放在这里,会让某一行、列或颜色没有位置。
+Back close Back 关闭
+Clear! 过关!
+Hard 困难
+How to play 玩法
+Level 关卡
+Level 关卡
+Next level 下一关
+OK X OK OK cat DEL undo Back menu OK X OK OK 放猫 DEL 撤销 Back 菜单
+OK apply OK 执行
+OK again to quit 再按 OK 退出
+OK marks an X. OK twice (or EXE) places a cat. A wrong cat costs a fish; with all 3 gone, try again. OK 画一个 X。按两次 OK(或 EXE)放猫。放错猫会失去一条鱼,3 条都没了就重来。
+One cat in each row, each column and each color. Cats can't touch, not even at the corners. 每行、每列、每种颜色各放一只猫。猫不能相邻,斜角也不行。
+Only one cell in this column can take a cat. 这一列只剩一格能放猫。
+Only one cell in this row can take a cat. 这一行只剩一格能放猫。
+Only one cell of this color can take a cat. 这种颜色只剩一格能放猫。
+Out of fish 小鱼用完了
+Paused 暂停
+Perfect! 完美!
+Play 开始
+Quit game 退出游戏
+Resume 继续
+These colors fill these lines between them, so nothing else in the lines can have a cat. 这些颜色占满了这些线,所以这些线上的其他格子没有猫。
+This cat rules out its row, its column and the cells around it. 这只猫排除了它所在的行、列和周围的格子。
+This color's cat must be in this line, so the rest of the line can't have one. 这种颜色的猫一定在这条线上,所以这条线的其他格子没有猫。
+This line's cat must be in this color, so the rest of the color can't have one. 这条线的猫一定在这种颜色里,所以这种颜色的其他格子没有猫。
+Try again 再试一次
+alpha alpha
+find 找猫
+hint 提示
+shift shift
diff --git a/games/meowdoku/src/art.h b/games/meowdoku/src/art.h
new file mode 100644
index 00000000..acb01410
--- /dev/null
+++ b/games/meowdoku/src/art.h
@@ -0,0 +1,25 @@
+/* Made by tools/art.py from Meowdoku's own pictures. */
+static const uint16_t cat_pal[16] = {0x7B6D,0x2924,0xEF1C,0x628A,0xA4F3,0xDEBA,0x49A6,0x2125,0x5ACB,0x2125,0xDD55,0xDE99,0x2988,0xBDB6,0x4A07,0xDEBA};
+static const uint8_t cat_alpha[16] = {13,252,254,253,255,19,254,158,12,97,255,85,244,14,255,150};
+static const uint8_t cat_px[880] = {0,0,0,0,9,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,80,17,16,0,0,0,0,0,0,0,0,0,0,128,151,23,0,0,0,0,0,0,9,17,17,144,0,0,0,0,0,0,0,0,0,7,17,17,0,0,0,0,0,0,7,16,17,25,0,0,0,0,0,0,0,0,0,113,22,17,144,0,0,0,0,0,1,19,49,97,144,0,0,0,0,0,0,0,7,17,19,49,112,0,0,0,0,0,129,99,48,22,25,0,0,0,0,0,0,136,113,17,51,49,16,0,0,0,0,0,145,99,51,17,97,0,0,0,0,0,0,7,17,22,51,49,16,0,0,0,0,0,145,51,51,49,17,16,0,0,0,0,0,145,17,30,227,54,16,0,0,0,0,0,113,51,51,49,17,17,0,8,128,0,9,17,17,102,51,54,16,0,0,0,0,0,113,51,51,1,17,17,17,17,17,17,113,17,17,102,99,54,16,0,0,0,0,0,113,51,48,17,17,17,17,17,17,17,17,17,17,22,99,54,16,0,0,0,0,0,113,51,1,17,17,17,17,17,17,17,17,17,17,17,102,54,16,0,0,0,0,0,17,51,17,17,17,17,17,17,17,17,17,17,17,17,22,54,16,0,0,0,0,0,17,1,17,17,17,17,17,52,1,17,17,17,17,17,17,102,16,0,0,0,0,0,17,193,17,17,17,17,19,34,36,17,17,17,17,17,17,17,16,0,0,0,0,0,17,193,17,17,17,17,18,34,34,49,17,17,17,17,17,17,16,0,0,0,0,0,124,17,17,17,17,17,50,34,34,65,17,17,17,17,17,17,16,0,0,0,0,0,193,17,17,51,49,17,50,34,34,49,17,52,14,17,17,17,16,0,0,0,0,9,193,17,20,34,34,49,18,34,34,225,18,34,34,65,17,17,16,8,0,0,0,1,17,17,66,35,20,33,18,34,34,17,164,17,66,35,17,17,23,136,0,0,0,113,17,19,34,49,19,67,18,34,34,30,33,19,66,34,17,17,17,0,0,0,8,17,17,19,34,17,17,52,18,34,34,16,65,17,20,34,49,17,17,117,0,0,9,17,17,19,34,97,17,52,18,34,34,20,65,17,20,34,97,17,17,16,0,0,7,204,17,17,34,161,19,35,226,34,34,22,35,17,50,36,17,17,17,24,0,0,0,193,17,17,58,34,162,49,34,34,34,65,50,74,34,65,17,17,17,25,0,0,140,193,17,17,17,17,17,20,32,170,2,35,17,110,17,17,17,17,17,25,0,0,129,17,17,52,34,64,48,34,42,170,2,34,67,99,48,3,17,17,17,25,80,128,0,51,52,34,34,34,34,34,34,170,34,34,34,34,34,34,36,51,51,57,0,13,176,51,66,34,34,34,34,34,34,34,34,34,34,34,34,34,34,49,19,48,189,0,89,17,34,34,34,34,34,34,34,36,34,34,34,34,34,34,34,35,17,24,93,208,8,52,34,34,34,34,34,34,34,14,162,34,34,34,34,34,34,34,51,112,0,0,139,51,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,19,5,5,5,5,3,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,103,208,80,5,80,0,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,32,112,0,0,8,8,0,242,34,34,34,34,34,34,34,34,34,34,34,34,34,34,32,5,0,0,0,80,8,11,34,34,34,34,34,34,34,34,34,34,34,34,34,34,176,0,0,0,0,0,0,80,95,34,34,34,34,34,34,34,34,34,34,34,34,240,0,0,0,0,0,0,0,5,0,91,34,34,34,34,34,34,34,34,34,34,5,0,80,0,0,0,0,0,0,0,85,0,85,255,34,34,34,34,34,2,240,80,0,213,0,0,0,0,0,0,0,0,0,141,0,0,85,91,187,187,181,13,0,0,5,0,0,0,0,0};
+static const sprite_t spr_cat = {44, 40, cat_pal, cat_alpha, cat_px};
+static const uint16_t fish_pal[16] = {0xECE4,0x0000,0xFE45,0xFF0B,0xE50A,0xD3C4,0xFEEC,0xDC66,0xFEEB,0xE4A5,0xFEA5,0xED07,0xD3A4,0xBBC4,0xF800,0xFF70};
+static const uint8_t fish_alpha[16] = {231,0,251,250,14,240,31,91,92,154,7,18,10,3,1,254};
+static const uint8_t fish_px[200] = {20,17,104,136,96,17,193,17,17,17,97,96,51,51,51,128,28,17,17,17,24,51,255,243,51,34,97,1,17,17,130,35,0,51,50,34,38,202,17,17,2,34,80,34,34,2,41,27,17,17,2,34,34,34,32,2,0,65,225,17,0,0,34,2,0,0,0,180,107,186,0,0,0,0,0,0,0,113,17,17,0,0,0,0,0,0,0,150,128,10,0,0,0,0,0,0,0,3,50,32,64,0,0,0,0,80,0,0,0,0,25,0,0,0,0,0,0,0,0,7,4,0,0,0,0,0,0,0,0,113,161,73,0,0,0,80,0,5,116,29,26,17,121,5,80,80,0,7,17,1,17,160,17,17,17,0,0,4,77,17,17,17,189,161,208,144,0,0,225,17,17,17,17,17,193,144,0,113,209,17,17,17,17,17,193,181,80,64,17,17,17,17,17,17,30,28,112,30,17,17};
+static const sprite_t spr_fish = {20, 20, fish_pal, fish_alpha, fish_px};
+static const uint16_t fish_dim_pal[16] = {0xFEAB,0xECE5,0xF58A,0xFF10,0xF800,0xE71C,0xFE87,0xAAA0,0x7BE0,0xFD55,0xFBE7,0x0000,0xFDA5,0xF523,0xFE26,0xECA3};
+static const uint8_t fish_dim_alpha[16] = {40,42,27,30,1,1,13,3,2,3,4,0,50,50,50,50};
+static const uint8_t fish_dim_px[200] = {187,179,48,0,3,91,187,187,187,187,181,0,3,48,0,0,180,187,187,187,176,0,51,51,0,224,11,187,187,187,0,96,204,0,0,238,3,187,187,187,14,238,220,14,238,238,224,180,187,187,12,238,0,238,236,238,194,155,187,187,44,204,204,204,204,12,204,36,102,107,44,204,204,204,238,204,204,43,187,187,33,204,204,205,204,204,204,3,48,0,33,221,221,209,204,220,204,224,0,2,33,221,221,220,29,28,220,206,236,204,178,31,241,221,209,205,220,204,221,16,65,17,255,255,221,253,221,223,241,43,187,17,255,255,255,253,221,209,35,187,187,184,17,241,17,253,221,18,187,187,187,187,187,162,113,253,221,37,187,187,187,187,75,187,181,29,223,43,187,187,187,187,187,187,75,31,241,43,75,187,187,187,187,187,75,31,18,91,187,187,187,187,187,187,187,33,32,187,187,187};
+static const sprite_t spr_fish_dim = {20, 20, fish_dim_pal, fish_dim_alpha, fish_dim_px};
+static const uint16_t lamp_pal[16] = {0xC46E,0xFD23,0xFE65,0xFF83,0xFD45,0xFF4A,0xFF4C,0x72B3,0xFD8B,0xFF51,0x8B54,0xB354,0x69AA,0xFF49,0xAC17,0xDCCD};
+static const uint8_t lamp_alpha[16] = {14,252,253,3,20,251,21,252,8,252,253,6,28,153,250,254};
+static const uint8_t lamp_px[242] = {0,0,0,54,0,0,0,67,0,0,0,0,0,3,0,96,221,6,0,48,0,0,0,0,51,13,85,34,34,0,3,0,0,0,0,96,213,153,34,33,32,131,0,0,0,4,0,89,149,34,33,17,0,128,0,0,51,5,89,149,34,17,17,24,3,0,0,96,101,85,34,33,17,31,20,4,0,0,96,101,82,34,17,17,17,20,4,0,0,96,98,34,33,17,17,17,20,4,0,0,48,2,33,17,17,17,17,20,3,0,0,4,0,33,17,17,17,17,0,64,0,0,3,8,17,17,17,17,17,131,0,0,0,0,48,65,17,17,17,16,8,0,0,0,0,4,0,33,17,17,0,64,0,0,0,0,6,3,34,17,17,64,128,0,0,0,0,0,0,15,255,0,0,176,0,0,0,0,11,0,0,167,119,0,0,0,0,0,0,0,0,238,170,119,0,0,0,0,0,0,0,0,238,167,119,176,0,0,0,0,0,0,0,10,167,112,0,0,0,0,0,0,0,11,12,0,192,192,0,0,0,0,0,0,0,176,204,0,0,0,0,0};
+static const sprite_t spr_lamp = {22, 22, lamp_pal, lamp_alpha, lamp_px};
+static const uint16_t locate_pal[16] = {0x7A8B,0x2104,0xEF1B,0x62CB,0x5165,0xA4F3,0xE6FB,0x18E4,0xD576,0x2104,0x4A4A,0x39C8,0xE6DB,0xE6FB,0x49E8,0x8B6D};
+static const uint8_t locate_alpha[16] = {19,250,250,251,253,254,5,94,253,162,13,27,161,92,254,252};
+static const uint8_t locate_px[242] = {0,0,0,0,0,0,0,0,0,0,0,0,7,0,0,0,0,0,0,0,0,0,0,145,23,0,0,170,187,0,9,154,0,0,20,17,144,0,0,0,7,20,64,0,0,20,65,17,0,187,186,145,31,71,0,0,20,65,17,17,17,16,62,67,71,0,0,20,17,17,17,17,17,16,227,71,0,11,17,17,17,17,21,37,17,20,231,0,0,17,17,19,241,18,34,17,17,48,0,0,145,17,50,88,21,34,17,51,16,10,0,17,17,35,16,53,37,19,51,17,160,7,17,17,85,21,53,34,17,17,17,0,7,17,17,19,51,50,130,81,17,17,48,9,17,17,85,136,34,130,34,34,84,0,9,17,24,34,34,34,130,34,34,37,22,7,17,82,34,34,83,20,242,34,34,0,10,19,34,34,34,68,68,66,34,34,0,0,115,34,34,34,80,0,82,34,44,6,6,0,34,34,34,40,8,34,34,198,102,0,160,108,34,34,34,130,34,45,0,96,0,0,0,13,204,34,34,205,96,102,0,0,0,102,0,0,102,0,0,6,0,0};
+static const sprite_t spr_locate = {22, 22, locate_pal, locate_alpha, locate_px};
+static const uint16_t flame_pal[16] = {0x92CB,0xA32C,0x92CB,0x7AAA,0x7800,0x92CB,0x0000,0x92CB,0x9B0C,0x79E7,0x92CB,0x92CB,0x8AAA,0xAAAA,0x92CB,0x7BEF};
+static const uint8_t flame_alpha[16] = {33,255,80,6,2,249,0,108,250,5,179,208,18,3,153,2};
+static const uint8_t flame_px[96] = {102,150,120,38,246,102,102,159,113,80,109,214,102,6,165,138,100,102,105,103,85,91,220,115,214,117,85,91,110,86,98,133,85,85,117,92,5,85,85,85,133,87,229,85,91,165,85,91,85,85,176,33,85,85,85,85,6,202,133,85,85,142,99,108,181,85,181,87,217,150,117,90,37,135,105,150,120,80,110,21,6,108,81,118,246,117,90,165,87,109,111,108,126,231,198,246};
+static const sprite_t spr_flame = {12, 16, flame_pal, flame_alpha, flame_px};
diff --git a/games/meowdoku/src/icon.png b/games/meowdoku/src/icon.png
new file mode 100644
index 00000000..71a53e02
Binary files /dev/null and b/games/meowdoku/src/icon.png differ
diff --git a/games/meowdoku/src/levels.h b/games/meowdoku/src/levels.h
new file mode 100644
index 00000000..35c34184
--- /dev/null
+++ b/games/meowdoku/src/levels.h
@@ -0,0 +1,306 @@
+/* Made by tools/levels.py from Meowdoku's own level banks: 309 puzzles, 7078 bytes. */
+static const uint8_t lv_data[7078] = {
+ 32,15,14,14,176,240,8,99,177,40,99,224,32,116,48,119,176,32,7,216,106,62,44,96,
+ 193,92,62,31,39,128,15,8,104,137,21,10,171,240,15,10,16,104,42,195,241,44,28,17,
+ 161,252,33,34,125,192,14,30,15,133,67,69,135,73,106,46,42,1,125,196,4,88,144,226,
+ 97,201,236,94,128,2,15,221,4,144,131,190,139,138,169,126,8,69,150,236,24,75,12,47,
+ 69,136,240,176,15,155,8,22,194,181,22,36,55,18,40,216,200,205,55,224,14,105,32,186,
+ 212,42,140,84,109,44,104,171,245,198,240,12,94,18,137,6,247,161,239,98,113,99,94,55,
+ 40,33,147,7,176,113,173,13,68,195,141,113,84,72,216,222,15,240,144,80,88,160,250,28,
+ 60,12,70,129,199,22,163,108,61,237,176,15,240,144,134,130,139,160,241,16,221,163,221,209,
+ 110,125,27,255,64,15,135,132,131,197,161,238,30,15,188,70,28,94,53,163,215,22,139,128,
+ 9,130,47,26,236,208,112,178,56,98,219,23,10,104,177,219,199,217,254,192,49,0,92,55,
+ 7,237,136,240,98,126,233,81,145,62,227,223,212,15,225,232,247,10,220,40,136,240,227,84,
+ 86,104,190,232,214,254,60,32,127,176,208,112,55,98,87,118,131,197,110,150,58,196,24,251,
+ 224,1,7,226,208,222,43,116,180,60,28,42,39,238,227,135,24,76,244,111,56,49,112,48,
+ 160,187,127,246,42,35,11,71,93,218,56,216,255,128,47,7,13,13,5,18,171,91,226,122,
+ 40,159,177,216,194,227,211,71,244,15,199,7,182,22,238,131,16,60,44,77,162,137,15,42,
+ 214,55,163,224,44,48,112,123,15,186,197,195,251,98,49,122,187,29,70,139,30,224,15,195,
+ 131,160,196,238,61,12,28,124,60,84,71,21,81,241,125,27,143,208,64,97,240,155,143,96,
+ 195,94,135,88,206,173,14,43,78,142,227,255,192,28,31,17,208,155,64,168,237,169,68,245,
+ 232,213,237,113,221,192,12,126,31,220,32,245,232,170,196,139,115,11,255,163,190,45,96,31,
+ 128,69,13,13,11,171,17,222,163,99,162,86,61,140,186,220,253,224,44,28,126,10,28,168,
+ 168,23,218,35,19,237,21,27,106,52,112,255,88,0,254,36,36,49,126,168,110,32,206,234,
+ 139,158,53,216,221,23,253,72,34,132,112,33,65,176,150,31,113,119,104,124,106,221,168,121,
+ 218,232,31,193,14,192,232,58,19,104,91,26,196,83,138,137,216,218,51,223,64,17,197,131,
+ 119,149,133,247,68,232,161,118,163,68,251,163,71,27,224,12,94,23,237,133,240,223,78,226,
+ 109,23,108,94,140,39,220,60,144,120,40,16,146,182,173,30,198,99,196,215,81,213,143,215,
+ 239,8,131,226,225,220,90,59,75,29,80,103,85,98,87,141,180,111,247,32,127,13,6,140,
+ 212,48,43,122,232,188,70,238,208,133,143,122,63,40,60,113,65,14,135,161,248,133,209,145,
+ 49,186,143,199,99,207,90,255,192,28,31,17,160,132,208,221,107,217,56,77,197,11,226,198,
+ 236,118,133,128,8,127,161,220,78,196,148,62,43,237,113,218,179,234,163,119,80,64,226,7,
+ 97,111,68,121,220,104,110,51,69,99,90,239,163,125,192,15,240,88,91,94,235,13,181,14,
+ 37,46,141,88,200,219,59,196,192,15,195,10,15,220,59,208,225,56,143,164,198,71,139,25,
+ 81,157,246,12,94,27,238,133,66,195,111,162,162,136,51,184,214,58,62,167,251,15,139,7,
+ 237,136,133,209,49,144,195,181,197,18,53,30,182,182,227,192,32,67,201,66,162,45,67,85,
+ 170,37,123,120,161,244,107,137,165,232,234,32,113,240,126,251,184,128,195,245,26,43,19,107,
+ 25,181,55,139,28,62,14,38,4,52,27,67,196,31,137,199,22,36,89,245,22,52,95,27,
+ 247,30,1,112,188,57,108,106,63,161,216,154,143,218,140,196,141,210,70,143,192,15,28,34,
+ 68,208,116,38,191,90,84,81,55,246,196,248,209,209,188,15,225,10,194,176,222,4,113,17,
+ 26,123,192,196,141,69,110,192,251,160,31,128,81,24,94,161,98,181,67,84,144,241,120,200,
+ 191,71,71,216,252,92,28,28,66,184,74,87,254,26,24,137,208,251,188,78,143,18,51,254,
+ 14,34,225,133,191,187,136,24,200,178,99,69,227,98,199,123,30,227,252,28,28,113,16,168,
+ 114,66,208,158,246,43,97,234,20,62,232,200,197,142,220,44,31,129,7,126,129,195,244,158,
+ 51,138,141,218,232,124,113,188,8,127,14,38,132,146,161,3,99,85,180,157,243,97,98,211,
+ 190,133,228,86,228,109,64,16,127,236,42,23,66,252,54,29,145,107,182,226,133,184,216,237,
+ 27,31,110,145,10,15,248,93,6,138,40,60,14,220,54,35,97,219,107,146,48,136,239,234,
+ 138,228,95,24,192,88,177,173,10,67,197,213,141,181,216,149,186,139,169,150,58,21,168,249,
+ 11,217,28,8,255,134,10,18,21,31,126,37,69,98,209,127,46,63,25,142,163,121,235,114,
+ 60,108,136,63,7,144,140,208,81,43,168,136,168,136,156,90,227,52,111,186,66,61,99,81,
+ 241,63,120,60,60,24,62,47,67,23,132,214,140,175,22,136,44,237,162,198,184,239,177,247,
+ 242,58,16,113,125,133,240,208,162,34,53,174,218,223,177,95,2,38,51,3,30,53,220,139,
+ 30,8,98,200,106,22,69,237,30,27,72,45,15,10,122,164,40,209,110,55,186,232,251,128,
+ 76,18,139,130,4,94,192,139,26,27,23,26,31,70,254,200,100,36,82,61,104,244,109,228,
+ 124,15,241,32,241,45,68,168,24,48,213,122,189,200,70,69,178,42,7,209,177,200,100,127,
+ 15,226,131,112,148,48,33,107,135,191,212,76,161,247,27,216,216,252,108,116,94,143,31,193,
+ 133,195,113,68,67,253,68,69,113,58,140,147,23,169,238,141,118,45,201,139,164,32,15,248,
+ 62,194,36,60,118,195,140,168,94,143,99,150,168,17,241,182,221,186,200,111,128,63,224,32,
+ 0,208,171,80,245,110,133,189,122,84,15,252,100,107,34,52,118,221,240,40,193,14,72,127,
+ 94,139,108,61,137,209,133,216,181,223,33,33,237,29,69,232,239,128,30,40,56,150,233,32,
+ 195,118,12,62,190,132,169,80,247,122,20,101,142,227,86,70,23,128,104,161,131,133,7,219,
+ 245,232,125,137,127,118,45,237,120,152,184,239,200,224,14,17,248,62,133,244,61,198,172,89,
+ 148,69,218,162,209,117,107,122,59,84,15,238,12,60,84,3,200,81,63,10,142,142,22,38,
+ 69,163,216,203,69,90,222,245,137,200,226,112,15,143,132,135,80,117,171,30,135,227,232,212,
+ 100,68,90,42,37,141,251,72,164,15,155,126,15,248,91,130,222,221,12,14,136,80,244,49,
+ 58,43,255,216,209,228,84,111,67,232,64,193,251,191,96,97,33,104,117,88,106,5,239,197,
+ 209,133,253,123,30,69,23,30,25,0,79,26,225,92,72,107,253,236,78,45,75,241,233,146,
+ 35,168,91,93,200,237,128,12,127,11,161,104,35,7,67,17,141,186,209,92,74,93,32,72,
+ 248,219,108,132,136,145,247,218,31,7,38,43,20,44,117,244,246,195,139,18,51,242,42,66,
+ 67,70,145,86,250,189,244,14,47,11,251,197,194,225,187,101,81,20,47,251,66,67,11,26,
+ 168,253,248,220,15,248,116,36,20,26,5,184,250,12,36,132,55,182,138,131,198,87,178,52,
+ 127,162,252,15,248,58,28,36,49,26,21,137,67,214,58,241,72,186,50,186,13,145,143,72,
+ 118,71,240,9,240,248,84,30,28,85,136,219,170,35,117,218,58,227,53,81,148,138,238,151,
+ 180,136,48,120,186,26,15,122,133,224,43,200,189,17,104,104,171,99,42,138,70,171,142,242,
+ 62,15,248,72,40,148,74,173,237,15,177,180,79,213,22,198,234,39,30,173,55,169,8,62,
+ 14,40,61,11,232,23,193,232,140,24,158,250,44,47,19,68,26,58,142,237,228,35,64,15,
+ 197,132,132,194,130,47,193,195,160,241,7,226,120,187,26,208,250,38,142,43,144,222,145,128,
+ 31,7,194,187,48,93,218,29,215,19,218,17,104,237,177,253,180,135,126,131,128,16,66,76,
+ 191,186,45,19,23,31,13,179,198,68,222,209,182,54,164,11,238,180,127,128,15,240,250,21,
+ 40,148,13,218,134,221,170,20,234,5,93,97,194,141,215,104,189,160,16,122,63,13,188,64,
+ 157,149,84,101,212,59,182,58,145,234,53,25,143,221,250,70,14,28,100,132,131,135,110,235,
+ 209,208,232,144,168,158,163,209,135,23,181,89,13,251,119,30,15,192,196,9,145,196,182,136,
+ 161,160,107,239,197,236,100,118,7,85,233,186,68,8,15,248,128,176,168,246,22,26,208,163,
+ 135,182,63,227,40,194,221,227,250,7,223,200,192,64,224,254,250,39,97,174,208,224,123,64,
+ 203,70,90,28,42,222,232,113,212,97,246,15,248,59,244,0,208,191,81,54,54,36,101,162,
+ 99,98,223,30,70,144,200,83,111,192,32,193,251,162,33,186,5,89,171,91,3,161,244,74,
+ 197,122,162,211,215,172,142,139,128,64,127,162,4,24,59,85,223,98,34,167,190,244,93,70,
+ 209,238,254,248,190,66,15,248,72,80,193,234,135,162,221,215,16,60,92,138,197,198,238,141,
+ 143,162,210,52,111,64,30,60,24,79,109,195,106,40,183,177,2,104,171,200,122,100,141,221,
+ 2,61,81,191,28,64,248,95,112,244,54,247,64,153,19,64,237,14,43,236,91,66,36,112,
+ 27,143,188,88,63,236,29,192,131,18,20,61,18,23,168,111,220,107,15,27,19,142,209,253,
+ 242,16,78,48,120,72,125,4,86,48,171,137,26,163,166,70,139,175,22,66,178,22,213,17,
+ 100,71,145,255,15,227,18,10,10,26,239,86,12,63,197,98,162,91,198,174,69,106,132,117,
+ 161,253,232,14,47,136,130,131,117,112,186,161,139,182,180,46,135,23,154,139,143,199,71,122,
+ 135,248,32,7,39,197,189,239,163,186,48,146,162,245,27,199,94,63,26,62,145,121,8,255,
+ 140,25,69,129,138,11,104,194,214,198,208,235,68,189,181,142,22,139,222,164,90,47,238,15,
+ 240,161,125,189,17,104,117,64,246,39,232,145,105,171,162,80,197,69,142,247,19,31,131,31,
+ 17,66,98,117,90,24,76,43,219,88,187,211,5,240,40,72,71,183,194,240,31,7,134,132,
+ 246,221,163,133,7,17,133,6,38,232,187,157,70,187,82,49,20,114,34,120,31,22,14,34,
+ 37,196,240,186,30,189,69,81,250,175,76,168,212,124,93,31,35,242,48,79,6,24,88,16,
+ 122,3,97,187,235,232,160,169,157,95,30,168,174,197,234,23,240,15,138,28,90,22,145,171,
+ 186,208,255,91,69,23,216,206,143,120,186,31,22,63,128,32,120,123,135,221,14,45,72,180,
+ 5,215,183,162,242,32,99,163,90,32,244,133,246,224,48,127,160,253,131,10,254,35,216,162,
+ 88,174,245,102,29,29,237,241,191,228,32,48,192,47,176,160,222,253,209,120,93,19,94,162,
+ 246,38,50,56,218,66,215,93,224,15,241,33,80,81,26,129,19,123,97,177,24,145,89,40,
+ 154,204,227,246,67,238,163,252,15,240,162,80,209,88,85,106,68,72,113,111,245,143,69,227,
+ 95,111,214,70,63,72,128,14,33,201,193,195,236,62,141,165,186,254,139,121,223,127,122,71,
+ 217,31,210,63,147,220,8,255,195,5,9,10,132,62,254,37,69,98,232,191,203,143,198,72,
+ 142,163,122,122,220,143,141,145,39,141,147,192,15,254,23,65,162,197,7,129,237,195,113,27,
+ 14,237,174,76,97,17,222,74,170,255,84,87,145,124,15,143,135,190,194,126,30,190,75,39,
+ 251,25,26,56,190,227,244,125,237,100,49,254,139,252,40,195,240,73,95,187,68,254,137,140,
+ 42,122,218,242,4,198,163,107,27,93,223,246,144,144,143,248,44,16,227,193,65,247,86,31,
+ 223,69,123,19,89,157,139,123,175,237,71,114,31,93,125,73,12,63,135,137,161,36,212,32,
+ 108,117,91,73,239,155,133,139,79,125,11,228,86,242,54,178,87,106,94,40,5,147,65,87,
+ 234,172,156,93,198,244,58,54,132,95,184,238,56,203,186,191,125,31,247,192,16,113,126,194,
+ 252,52,40,148,70,181,237,106,75,109,119,236,91,224,68,227,48,49,241,174,228,108,31,7,
+ 255,124,72,93,147,13,139,177,155,117,14,209,238,216,255,173,10,245,38,222,188,120,15,195,
+ 254,15,132,135,188,236,155,246,40,120,158,172,100,39,93,174,177,181,222,133,242,31,128,28,
+ 158,47,97,127,113,172,12,49,189,195,226,161,116,95,72,225,124,124,44,127,228,223,227,254,
+ 15,23,224,176,95,189,228,195,162,248,206,188,217,43,222,37,32,123,130,213,228,61,187,253,
+ 14,72,127,19,124,76,87,113,126,19,253,192,63,191,227,67,232,147,111,246,254,54,240,124,
+ 188,90,29,223,110,254,239,7,251,68,195,160,108,103,111,100,187,141,137,3,55,19,112,124,
+ 31,194,113,110,43,176,156,124,93,5,255,102,241,3,17,162,238,251,160,252,157,127,137,112,
+ 137,177,255,111,159,110,8,93,193,222,78,236,31,138,183,23,218,46,2,23,23,3,96,64,
+ 226,60,15,158,142,32,181,184,150,180,98,69,212,111,182,225,174,135,232,85,127,171,242,90,
+ 255,2,224,143,36,63,39,95,141,175,141,137,179,122,27,69,252,28,120,189,123,180,9,215,
+ 96,126,7,192,30,15,252,151,252,15,226,33,208,146,196,135,133,27,118,141,245,181,24,87,
+ 95,71,171,194,250,14,31,253,252,46,37,197,232,111,122,36,102,62,163,100,31,214,70,21,
+ 169,30,147,87,222,184,113,124,190,78,223,198,110,27,189,195,176,196,123,34,175,125,176,252,
+ 72,95,112,63,3,224,126,60,223,162,186,84,150,187,113,104,222,69,17,127,171,138,225,224,
+ 255,131,254,15,7,246,124,222,15,100,187,223,177,119,210,196,222,225,190,4,126,68,52,47,
+ 245,15,247,254,192,15,252,46,224,250,7,13,137,2,31,82,129,216,59,212,91,140,6,227,
+ 228,125,116,154,74,145,253,192,63,131,156,42,7,4,74,31,183,163,34,124,58,39,22,28,
+ 111,91,164,34,253,92,149,1,234,74,191,186,15,252,38,14,134,33,214,225,219,80,241,94,
+ 177,85,235,118,2,233,3,55,37,35,100,246,128,246,244,32,112,254,193,134,134,246,170,244,
+ 27,227,1,68,33,21,180,141,90,5,37,86,234,143,105,27,173,186,30,15,23,195,66,193,
+ 244,40,99,110,244,123,184,209,30,141,212,86,247,180,110,69,108,143,99,147,238,79,15,158,
+ 43,236,189,14,15,140,18,131,1,54,212,14,18,135,110,170,22,239,129,210,251,144,40,31,
+ 160,52,143,159,254,240,3,68,139,186,214,63,98,107,218,46,51,182,50,189,174,224,194,99,
+ 232,161,126,15,15,225,65,132,253,246,62,136,15,197,174,244,46,140,232,212,75,46,59,244,
+ 183,178,45,252,127,55,74,44,111,150,141,226,137,209,117,66,240,157,245,68,240,225,123,161,
+ 96,55,80,52,15,239,4,148,254,108,91,246,253,27,99,163,246,220,77,132,225,209,183,107,
+ 110,30,193,237,7,162,235,192,129,22,111,72,182,247,215,241,125,29,209,54,186,138,163,253,
+ 123,5,23,31,244,49,225,188,27,240,153,167,249,47,223,69,177,94,190,23,13,133,225,247,
+ 182,23,224,123,5,7,97,64,116,63,224,153,255,159,255,195,67,26,42,6,251,189,18,133,
+ 208,80,191,7,127,176,16,31,253,15,248,129,121,61,247,36,22,39,251,13,248,48,247,237,
+ 26,135,208,244,62,13,241,244,60,86,235,23,30,72,127,232,148,36,47,131,87,140,45,121,
+ 198,176,232,125,15,224,70,238,6,253,169,124,15,96,124,128,121,102,252,52,104,111,168,106,
+ 136,19,126,184,58,23,208,188,27,127,224,127,80,255,38,255,128,83,255,226,49,176,251,135,
+ 228,225,192,188,32,80,54,45,239,131,1,3,193,129,250,31,114,111,220,137,191,136,111,253,
+ 5,136,137,213,173,248,158,6,2,197,118,173,71,244,61,112,254,178,81,255,153,179,248,198,
+ 226,232,190,239,128,194,68,186,209,34,193,182,193,240,180,31,10,2,15,255,80,15,248,136,
+ 63,16,180,47,252,76,17,71,97,234,254,36,94,61,19,177,244,103,79,141,209,159,221,146,
+ 141,197,192,52,14,32,193,250,244,236,45,137,187,183,123,176,225,120,157,21,21,25,235,170,
+ 55,141,244,221,240,127,230,72,250,44,111,17,183,137,110,247,225,33,123,11,245,11,129,192,
+ 111,251,255,100,64,147,100,244,27,190,199,66,120,19,234,7,225,125,250,8,31,22,14,252,
+ 59,177,253,188,31,3,136,112,120,125,226,225,88,188,246,135,216,88,120,190,137,123,10,140,
+ 47,218,251,209,126,150,251,15,195,224,252,38,22,133,222,182,27,17,106,29,37,21,236,195,
+ 216,238,239,215,70,72,38,190,232,112,76,31,193,137,209,88,98,66,23,181,10,132,223,85,
+ 204,133,232,207,163,118,67,227,180,116,117,207,252,148,28,31,192,226,81,28,36,79,97,80,
+ 238,192,197,109,139,227,215,100,70,95,93,165,247,89,30,79,33,228,128,253,234,13,184,158,
+ 153,25,209,255,68,162,169,124,93,164,18,209,250,183,123,93,39,255,15,14,44,52,28,86,
+ 213,2,133,215,177,26,195,106,143,209,118,53,2,147,77,14,58,161,97,236,156,131,249,50,
+ 48,30,15,192,225,49,94,18,162,216,97,113,118,177,113,6,215,123,89,57,11,91,29,182,
+ 214,143,73,247,88,63,76,20,84,43,124,68,13,137,195,215,223,99,125,38,110,66,75,81,
+ 234,142,242,70,163,220,159,224,158,13,56,208,129,212,6,177,110,222,178,113,53,116,146,43,
+ 169,181,252,143,199,118,74,72,245,63,240,28,126,64,67,88,91,170,23,183,241,59,17,19,
+ 196,252,87,32,97,124,147,171,235,25,209,118,249,60,15,240,195,67,65,244,187,10,35,64,
+ 227,137,111,163,44,138,45,125,106,142,233,42,226,200,171,175,247,15,8,230,193,247,82,21,
+ 16,56,203,19,162,60,87,199,72,163,209,245,235,72,88,255,122,71,201,127,232,100,64,16,
+ 125,174,21,212,48,177,93,81,34,221,86,221,84,93,215,244,100,163,254,77,120,9,239,192,
+ 12,56,57,232,86,139,212,56,141,213,181,209,145,53,215,34,186,200,218,87,187,245,220,15,
+ 224,12,32,196,9,235,13,110,136,29,174,182,174,160,127,113,114,58,55,90,85,145,250,223,
+ 214,248,144,7,7,208,236,45,173,11,3,90,7,18,139,163,9,215,90,61,35,88,250,237,
+ 181,3,189,251,128,17,224,241,117,133,227,40,177,30,173,110,186,208,104,245,118,183,242,89,
+ 29,221,238,239,96,33,195,7,219,222,232,148,44,91,123,99,141,70,11,71,189,35,175,89,
+ 42,23,181,200,214,238,224,15,249,16,240,97,118,219,237,139,27,209,113,184,247,94,239,64,
+ 69,33,38,254,78,254,250,44,31,133,131,252,102,135,137,176,98,215,72,69,196,234,142,142,
+ 147,170,247,34,221,219,215,242,124,144,10,15,214,193,244,70,135,181,219,104,182,199,215,26,
+ 186,68,109,117,176,40,21,27,125,255,15,135,195,247,225,33,124,245,162,121,41,1,69,99,
+ 85,108,109,87,93,87,122,174,233,190,224,8,112,122,16,237,11,163,40,170,35,86,171,170,
+ 45,186,199,107,168,253,183,122,210,91,2,237,226,64,8,112,122,80,173,14,212,72,22,209,
+ 32,69,173,29,173,214,5,27,173,34,245,173,129,90,246,255,128,46,15,193,96,253,40,109,
+ 19,214,183,162,244,100,106,61,175,88,59,34,180,141,106,13,5,239,248,12,60,25,232,91,
+ 186,34,28,14,74,135,162,234,234,234,54,5,213,210,58,176,46,154,221,3,127,128,15,14,
+ 14,21,187,187,241,98,67,221,184,207,164,70,199,165,35,119,109,31,234,53,192,129,254,12,
+ 56,57,104,87,13,208,216,123,37,120,150,188,77,168,215,234,227,237,72,175,77,109,129,191,
+ 192,33,195,7,216,143,118,221,221,139,27,237,184,244,94,237,145,185,43,222,223,118,254,15,
+ 249,104,60,49,58,22,29,235,25,189,70,164,56,234,215,61,90,251,232,29,39,91,208,62,
+ 15,252,78,12,56,91,161,194,153,219,125,162,254,59,126,62,176,20,89,47,100,254,183,3,
+ 208,12,48,121,232,77,14,235,90,201,81,53,212,107,122,180,93,171,22,69,170,46,212,212,
+ 143,119,248,15,252,46,15,216,136,144,223,112,249,172,84,92,126,188,126,67,143,209,147,104,
+ 14,79,86,156,15,192,8,96,250,23,10,135,184,149,116,102,171,173,111,80,34,246,168,247,
+ 105,43,214,173,139,118,252,15,249,16,184,62,198,161,208,54,218,245,23,168,213,239,81,251,
+ 222,217,62,160,83,129,248,96,224,226,210,22,24,93,80,246,38,168,180,23,81,99,171,171,
+ 85,212,125,104,219,7,201,168,61,61,248,12,48,121,152,108,42,37,173,173,180,80,45,160,
+ 212,77,173,123,227,218,36,209,251,182,192,201,223,128,15,252,80,129,251,93,15,216,144,248,
+ 250,227,106,21,1,99,239,81,254,146,63,38,2,191,191,176,60,31,193,65,248,169,88,90,
+ 46,140,136,131,72,168,154,45,170,14,218,168,253,170,185,26,171,6,223,240,15,252,47,131,
+ 226,117,14,103,161,224,99,214,45,234,47,113,235,1,81,37,122,239,171,39,3,224,15,252,
+ 46,15,232,140,59,51,118,47,119,120,244,136,188,125,116,3,228,174,169,234,3,120,31,128,
+ 44,31,133,7,253,135,68,216,161,232,205,180,26,142,200,104,218,216,50,81,237,6,79,90,
+ 147,239,247,128,47,12,31,221,253,12,68,35,71,161,213,234,40,155,213,215,30,208,180,73,
+ 90,251,107,201,223,128,44,31,193,65,195,122,196,94,100,77,69,235,162,250,193,176,119,254,
+ 71,71,250,15,251,201,208,31,7,225,94,205,127,232,152,123,186,42,67,199,86,178,71,164,
+ 117,54,161,55,111,123,190,32,126,31,195,220,77,215,26,197,91,109,124,150,46,61,169,8,
+ 248,90,69,9,186,213,186,133,248,15,252,44,26,8,158,221,158,140,31,122,209,110,74,210,
+ 27,91,125,182,233,235,96,96,127,12,32,252,48,122,20,75,98,173,140,235,91,32,93,19,
+ 171,186,85,31,219,94,7,87,216,31,224,47,7,240,80,97,230,142,181,7,168,149,186,183,
+ 234,47,113,234,70,207,170,10,211,170,175,191,128,15,252,46,15,195,216,159,113,34,233,72,
+ 26,222,182,46,5,70,199,173,99,251,81,248,11,127,192,40,60,32,248,104,58,100,5,98,
+ 1,209,90,189,90,189,117,114,17,235,209,94,146,234,7,93,201,240,8,112,121,208,236,45,
+ 173,17,129,172,74,4,106,45,209,181,235,107,35,173,246,242,117,221,3,240,15,135,143,18,
+ 222,18,208,186,22,226,218,56,212,93,171,187,84,39,90,170,23,163,85,146,223,216,24,63,
+ 232,33,133,127,108,78,66,138,137,234,45,70,81,163,176,92,154,213,218,213,218,131,212,239,
+ 208,8,65,254,209,30,148,58,194,181,181,21,168,213,23,169,11,29,30,145,107,214,219,174,
+ 215,127,192,15,252,60,30,23,180,75,53,182,241,212,90,47,93,241,251,231,200,250,153,24,
+ 31,191,160,15,252,40,55,246,254,20,60,88,158,52,88,154,107,108,141,99,219,168,252,142,
+ 143,145,224,127,128,44,28,63,67,65,252,58,47,53,17,176,186,214,245,200,108,148,121,24,
+ 84,214,239,82,59,223,224,15,252,60,30,22,140,138,137,113,171,104,26,44,123,80,173,214,
+ 187,173,236,14,78,255,123,192,56,62,31,96,252,37,10,39,74,238,232,209,117,214,237,169,
+ 3,133,244,139,125,119,119,252,60,25,2,41,209,17,54,215,21,173,117,162,113,84,151,139,
+ 235,38,142,64,202,222,214,169,210,113,47,254,31,16,60,45,122,59,224,127,17,69,197,68,
+ 87,109,197,251,228,141,139,142,147,232,252,90,69,249,56,15,32,190,42,37,7,213,168,110,
+ 168,80,236,90,245,44,113,50,21,209,146,43,143,90,200,163,91,92,150,71,128,31,240,68,
+ 198,234,78,240,176,209,162,186,59,89,14,36,107,108,149,245,163,71,145,182,164,70,244,120,
+ 222,47,224,46,26,11,2,195,218,47,187,136,143,17,19,184,149,23,198,170,199,235,164,217,
+ 11,39,177,61,31,15,225,36,49,144,144,118,170,39,142,185,44,84,169,61,177,163,177,125,
+ 182,201,212,157,177,253,34,255,224,18,199,131,70,163,34,105,85,80,171,213,137,112,239,94,
+ 52,143,56,216,232,232,239,253,146,147,164,42,120,251,128,64,139,130,45,67,191,239,176,248,
+ 236,44,116,125,11,174,177,83,232,241,133,168,188,88,244,189,255,246,8,191,244,31,194,225,
+ 161,162,80,250,218,139,90,209,97,252,173,209,191,29,38,67,29,30,164,91,215,64,15,254,
+ 21,6,131,133,13,171,161,235,139,68,190,214,53,21,116,104,119,236,113,146,24,223,87,164,
+ 241,96,15,32,252,44,74,11,209,56,113,113,35,6,180,152,215,177,176,248,190,238,199,27,
+ 33,218,147,117,233,16,248,60,31,134,209,24,76,56,21,10,222,219,98,99,62,187,69,135,
+ 218,242,17,235,82,69,140,183,141,244,129,120,56,188,15,193,232,119,13,15,227,241,81,81,
+ 79,68,22,171,173,253,69,136,141,239,201,253,208,121,56,191,21,138,130,226,250,189,134,215,
+ 141,80,111,170,129,54,173,191,173,72,127,64,223,129,32,15,138,129,97,127,133,14,40,239,
+ 104,181,224,128,34,61,143,85,173,236,127,136,215,201,241,159,227,82,96,153,252,197,135,26,
+ 215,195,125,237,16,95,160,84,47,111,120,14,133,234,7,123,133,228,44,47,136,62,24,104,
+ 63,248,84,32,226,254,226,81,16,249,63,21,227,162,162,222,140,252,251,239,27,242,64,12,
+ 83,244,251,188,42,138,189,235,116,16,212,111,6,208,222,31,223,68,247,239,120,159,34,12,
+ 192,241,85,245,81,255,248,154,10,31,213,23,85,7,172,127,240,240,176,104,157,98,216,87,
+ 88,160,244,106,247,129,254,128,44,49,241,1,224,55,3,99,34,208,245,106,21,31,173,225,
+ 223,240,25,242,4,223,87,235,197,107,135,239,255,11,240,63,8,185,191,92,29,22,220,70,
+ 61,214,220,6,31,195,248,126,8,243,112,116,123,67,219,253,254,44,33,34,251,123,139,240,
+ 88,231,241,154,29,175,247,227,248,95,4,74,6,2,223,97,64,81,230,23,128,180,109,213,
+ 209,190,14,143,232,154,38,162,171,247,41,197,153,29,68,26,227,212,84,44,48,170,23,90,
+ 221,64,133,235,111,224,247,254,143,252,79,184,93,188,103,34,8,219,7,22,133,139,161,113,
+ 115,191,135,225,248,15,255,9,248,246,51,143,22,182,38,192,82,67,192,168,3,129,255,6,
+ 69,193,200,129,47,39,142,197,100,108,92,140,8,163,59,139,193,108,61,107,22,189,223,35,
+ 35,248,47,147,137,241,154,63,13,22,164,85,106,135,173,92,107,65,208,58,132,187,238,4,
+ 12,191,132,71,30,215,236,143,219,248,215,244,47,195,98,94,191,27,128,109,30,20,69,208,
+ 215,245,127,95,255,29,248,21,253,81,55,124,44,15,244,65,112,92,28,48,118,142,168,171,
+ 87,86,226,59,9,9,163,55,70,222,141,3,95,163,133,161,237,17,80,22,170,171,117,223,
+ 24,95,29,241,219,113,224,239,131,143,255,5,240,124,43,135,66,145,35,84,136,187,72,139,
+ 51,113,192,118,143,88,158,6,25,63,216,50,31,235,195,100,110,177,180,1,232,8,152,184,
+ 16,135,232,16,183,244,120,121,115,68,98,180,68,43,235,225,177,176,200,191,176,95,34,29,
+ 200,224,105,28,25,31,15,248,191,180,79,90,143,9,65,233,12,28,49,136,163,6,215,214,
+ 254,255,6,143,255,196,255,30,151,70,214,2,2,62,221,196,193,11,14,234,10,137,221,120,
+ 13,31,200,227,212,113,175,137,98,200,218,46,244,60,39,216,84,55,183,191,15,252,142,27,
+ 211,118,250,58,22,241,235,216,164,43,218,238,4,180,100,24,28,139,17,189,216,24,12,121,
+ 168,225,32,107,208,58,245,227,221,189,121,61,95,212,70,11,23,86,232,27,255,192,32,193,
+ 254,209,9,73,96,197,110,197,250,43,97,62,253,238,50,47,227,104,82,45,9,13,34,63,
+ 251,64,156,120,52,72,72,71,144,183,30,71,218,68,91,220,89,25,11,22,71,113,18,35,
+ 108,73,26,21,6,160,171,222,22,47,209,160,28,143,38,57,1,177,155,85,173,235,91,214,
+ 136,191,164,95,214,197,242,52,31,212,131,163,253,232,123,250,70,90,21,81,157,72,237,10,
+ 162,84,143,183,128,252,148,26,13,39,71,175,106,49,112,9,97,112,58,23,3,241,108,31,
+ 23,180,141,238,123,97,126,242,94,23,39,97,114,112,224,124,121,62,46,190,46,28,100,133,
+ 47,85,220,58,68,43,214,22,227,112,27,250,236,144,96,127,188,57,165,158,152,148,88,253,
+ 215,164,251,143,71,246,252,70,178,16,137,118,247,107,3,133,223,95,64,25,162,244,104,94,
+ 71,108,140,158,216,100,193,26,42,29,198,139,14,79,69,137,188,125,147,207,39,252,159,240,
+ 116,162,47,45,126,183,234,252,101,81,245,85,196,85,84,254,170,201,250,180,143,130,214,4,
+ 29,24,233,205,195,147,246,220,126,13,247,39,133,242,47,116,104,191,239,126,241,63,125,12,
+ 153,127,187,225,125,133,126,79,126,247,228,39,95,173,13,245,135,141,35,116,111,38,159,40,
+ 63,212,17,201,226,224,215,224,199,191,248,191,240,223,140,142,36,111,98,72,194,66,210,33,
+ 124,152,48,167,244,27,254,191,248,215,138,232,241,69,194,161,48,240,189,208,162,63,235,145,
+ 246,70,8,205,164,188,61,183,217,61,193,168,49,97,228,223,252,123,226,95,145,161,92,45,
+ 93,23,252,106,5,225,4,141,193,244,47,66,74,75,255,209,31,234,254,39,184,236,84,46,
+ 62,168,126,139,220,24,34,30,37,109,161,228,138,141,151,95,175,129,177,35,69,96,17,131,
+ 147,66,215,109,120,29,197,68,242,215,247,141,199,236,72,193,21,156,92,159,195,222,96,52,
+ 29,234,132,176,53,84,242,21,86,6,187,254,255,178,201,106,100,2,15,23,6,132,29,160,
+ 90,251,226,66,141,144,86,52,118,212,123,241,187,48,105,69,128,121,51,71,137,141,240,52,
+ 29,42,54,132,183,85,122,170,160,12,135,127,223,244,14,17,90,70,192,8,98,142,88,48,
+ 161,197,134,20,56,177,161,67,139,26,40,113,99,71,135,22,52,121,34,198,143,34,44,104,
+ 242,37,141,30,70,140,19,102,176,32,111,147,249,30,6,131,167,70,208,150,226,170,208,213,
+ 81,110,187,239,253,246,176,117,32,132,111,151,226,62,26,240,149,128,10,173,85,65,85,74,
+ 109,150,0,108,188,126,225,240,52,29,137,84,37,38,170,189,85,35,163,187,239,251,230,4,
+ 177,35,108,110,76,167,246,47,3,244,122,10,47,213,6,71,85,162,106,215,222,253,145,11,
+ 101,41,164,48,24,63,255,198,195,11,116,58,34,235,85,209,87,99,104,247,251,200,237,219,
+ 149,75,12,32,84,103,253,191,3,65,196,161,170,18,153,213,94,170,176,49,157,248,159,196,
+ 240,56,42,89,182,99,134,159,65,246,3,35,131,2,145,226,1,145,201,219,197,218,43,27,
+ 177,126,219,240,62,255,23,132,178,220,81,138,0,9,191,26,255,80,113,5,107,171,6,14,
+ 22,125,35,189,208,191,239,225,118,19,10,108,72,45,31,193,95,226,223,242,50,180,75,212,
+ 101,169,117,81,54,70,170,79,65,186,142,212,128,226,85,171,106,168,244,75,128,94,159,225,
+ 232,92,71,160,109,195,208,187,163,92,125,185,21,5,124,13,87,41,234,187,183,43,191,255,
+ 220,95,252,27,230,208,160,32,18,181,88,214,190,180,138,108,112,181,71,255,248,96,2,0,
+ 211,250,183,240,119,69,71,253,112,191,168,190,14,255,161,191,189,132,161,139,41,0,
+};
+static const uint16_t lv_at[310] = {0,6,12,17,22,30,38,46,54,65,77,88,100,116,131,144,160,179,197,216,236,253,271,289,308,326,345,364,382,402,421,438,455,474,493,511,530,549,567,583,601,619,637,657,676,693,711,729,747,765,784,803,821,841,861,879,898,918,936,955,975,992,1015,1037,1059,1083,1107,1131,1154,1176,1200,1225,1248,1270,1294,1317,1339,1362,1386,1406,1428,1452,1476,1498,1520,1543,1568,1591,1612,1635,1659,1682,1705,1727,1751,1776,1797,1820,1842,1864,1887,1910,1933,1955,1978,2001,2022,2046,2068,2091,2114,2140,2163,2186,2208,2231,2253,2276,2300,2323,2345,2367,2390,2411,2433,2456,2479,2502,2532,2558,2582,2608,2632,2658,2684,2710,2734,2759,2784,2808,2831,2855,2880,2906,2931,2956,2981,3006,3030,3054,3077,3104,3132,3159,3187,3213,3241,3267,3292,3318,3344,3370,3395,3419,3445,3472,3497,3523,3548,3575,3603,3629,3653,3678,3703,3730,3758,3784,3810,3841,3868,3896,3923,3950,3977,4005,4032,4057,4082,4109,4133,4159,4183,4209,4234,4259,4286,4313,4339,4366,4391,4417,4439,4464,4489,4515,4542,4567,4591,4619,4646,4672,4700,4726,4752,4780,4806,4831,4855,4881,4905,4931,4957,4983,5010,5036,5062,5089,5115,5139,5165,5191,5216,5240,5268,5295,5325,5353,5381,5409,5439,5466,5494,5522,5551,5578,5605,5631,5659,5684,5711,5735,5751,5768,5786,5800,5816,5832,5849,5866,5888,5909,5932,5954,5976,5995,6013,6036,6057,6080,6103,6126,6147,6168,6188,6214,6238,6266,6297,6322,6348,6375,6401,6427,6456,6481,6503,6526,6553,6578,6603,6629,6646,6666,6690,6713,6739,6778,6802,6819,6843,6868,6892,6917,6949,6973,7005,7033,7054,7078};
+/* the pools: size, rank, main path only (10 x 10 ranks 3 and 4), first puzzle, count */
+static const uint8_t lv_pool[18][5] = {{4,1,0,0,4},{5,1,0,4,4},{6,1,0,8,4},{7,1,0,12,4},{8,1,0,16,6},{8,2,0,22,20},{8,3,0,42,8},{8,4,0,50,11},{9,1,0,61,9},{9,2,0,70,24},{9,3,0,94,18},{9,4,0,112,14},{10,1,0,126,24},{10,2,0,150,24},{10,3,0,174,11},{10,3,1,185,24},{10,4,1,209,24},{10,5,0,233,18}};
+static const uint8_t lv_pool_hi[18] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
+/* LinkedIn-modified puzzles of the main path: size, rank, strict, first, count */
+static const uint16_t lv_lk[9][5] = {{8,2,0,251,5},{8,3,0,256,1},{8,4,0,257,2},{9,2,0,259,8},{9,3,0,267,4},{9,4,0,271,3},{10,2,0,274,5},{10,3,0,279,3},{10,4,0,282,9}};
+/* special levels: level, size, puzzle, its own colours */
+static const uint16_t lv_special[18][4] = {{10,7,291,1},{20,8,292,1},{30,9,293,1},{40,8,294,1},{50,9,295,1},{55,9,296,1},{60,9,297,1},{62,7,298,1},{70,9,299,1},{75,9,300,1},{80,9,301,1},{90,9,302,1},{100,10,303,1},{123,9,304,1},{200,11,305,0},{250,11,306,0},{314,9,307,0},{456,9,308,1}};
diff --git a/games/meowdoku/src/main.c b/games/meowdoku/src/main.c
new file mode 100644
index 00000000..18f8f969
--- /dev/null
+++ b/games/meowdoku/src/main.c
@@ -0,0 +1,798 @@
+/* Meowdoku: put one cat in every row, every column and every colour; no two cats may touch.
+ *
+ * Played as on the phone: OK on a cell marks an X (or takes it off), OK twice quickly places a cat there
+ * (EXE does too). A cat in the right place stays; a wrong one turns into an X and costs a fish, and with
+ * the third fish gone the level starts over. OK held while moving marks X's along the way. The lamp
+ * (shift) shows the next step a player can reason out and does it on OK; the winking cat (alpha) finds
+ * one cat. The backspace takes back X's.
+ *
+ * The puzzles are the game's own (levels.h, from its level banks), dealt the way the game deals them:
+ * the board size set by the level number, special picture levels at fixed numbers, a hard level every
+ * tenth, and a difficulty that climbs while the player wins cleanly and drops after failures.
+ *
+ * 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 (Meowdoku.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"
+#ifdef HOST /* (the tests keep the file in memory, and have no app header) */
+const uint8_t *np_file_read(const char *name, uint32_t *len);
+bool np_file_write(const char *name, const void *data, uint32_t len);
+#else
+#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"))) = "Meowdoku";
+const uint32_t eadk_api_level __attribute__((section(".rodata.eadk_api_level"))) = 0;
+#endif
+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
+
+typedef struct {
+ uint8_t w, h;
+ const uint16_t *pal;
+ const uint8_t *alpha, *px;
+} sprite_t;
+#include "art.h"
+#include "levels.h"
+
+#define NMAX 11
+#define NPOOL (int)(sizeof lv_pool / sizeof *lv_pool)
+#define NLK (int)(sizeof lv_lk / sizeof *lv_lk)
+#define NSPECIAL (int)(sizeof lv_special / sizeof *lv_special)
+#define NPUZ (int)(sizeof lv_at / sizeof *lv_at - 1)
+#define K(k) (1ull << (k))
+
+#define TEXT HEX(0x6B4A2E) /* brown, as the game's words */
+#define SOFT HEX(0xA08466)
+#define WHITE 0xFFFF
+#define ORANGE HEX(0xFFA62B) /* the game's buttons */
+#define RED HEX(0xE5484D)
+#define INK HEX(0x24170E) /* the frame around the cell picked */
+#define SUN HEX(0xFFD43B) /* a hint's cells */
+static const uint32_t palette[12] = {0xCDA400, 0xD36F8F, 0x8979DA, 0xF89BE5, 0xFA9D5C, 0xFBD983,
+ 0x5076A5, 0xA5C6E7, 0x38A9C0, 0x2A8C53, 0x8BD57D, 0xA86D4A};
+
+enum { EMPTY, MARK, CAT };
+
+/* meowdoku.sav: the level being played and how the game deals the next ones */
+static struct {
+ uint8_t magic, version, flags, lives; /* flags: 1 the guide was read, 2 a level in play */
+ uint16_t level, wins;
+ uint8_t strat, clean, fails, pend; /* the difficulty: its strategy, clean wins and fails in a row, a drop due */
+ uint8_t retried, dirty, rlevels, rstrat; /* the level was failed once; a helper was used; retried levels in a row */
+ uint32_t seed;
+ uint16_t puz; /* the puzzle, its size, its turn (0-7), whether it has its own colours */
+ uint8_t size, t, special, perfect;
+ uint8_t cell[NMAX * NMAX];
+ uint8_t pc[NPOOL][3]; /* each pool: the next puzzle, its turn, puzzles since a LinkedIn one */
+ uint8_t lkc[NLK]; /* the next LinkedIn-modified puzzle of each size and rank */
+} sv;
+#define SAVE_NAME "meowdoku.sav"
+
+static color_t strip[SCREEN_W * STRIP_H];
+static int n, reg[NMAX * NMAX], sol[NMAX], color[NMAX]; /* the puzzle: size, regions, each row's cat, colours */
+static int cr, cc; /* the cell picked */
+static int ov, menu, quit_ok;
+static uint32_t now, err_until, err_cell;
+
+static uint32_t rnd(void) {
+ sv.seed ^= sv.seed << 13;
+ sv.seed ^= sv.seed >> 17;
+ return sv.seed ^= sv.seed << 5;
+}
+
+/* ------------------------------------------------------------ the puzzles */
+static int size_at(int lv) {
+ static const uint8_t first[10] = {4, 5, 6, 6, 8, 6, 7, 8, 9, 7}, then[10] = {8, 10, 10, 9, 10, 10, 9, 10, 10, 10};
+ return lv <= 10 ? first[lv - 1] : then[(lv - 11) % 10];
+}
+static bool is_hard(int lv) { return lv >= 21 && lv % 10 == 0; }
+static int special_at(int lv) {
+ for (int i = 0; i < NSPECIAL; i++)
+ if (lv_special[i][0] == lv) return i;
+ return -1;
+}
+static int pool_first(int p) { return lv_pool[p][3] | lv_pool_hi[p] << 8; }
+static int find_pool(int size, int rank, int main_path) {
+ int only = main_path && size == 10 && (rank == 3 || rank == 4);
+ for (int p = 0; p < NPOOL; p++)
+ if (lv_pool[p][0] == size && lv_pool[p][1] == rank && lv_pool[p][2] == only) return p;
+ return -1;
+}
+
+/* The next level's puzzle (NLControlStrategy): its size from the level number, a special one at fixed
+ levels, rank 5 on hard levels, otherwise the rank of the difficulty reached (from rank 3, any rank from 2
+ up to it); then the next puzzle of that pool, which turns and mirrors once the pool has been played. */
+static void deal(void) {
+ int lv = sv.level, sp = special_at(lv), main_path = lv >= 51, rank;
+ sv.t = 0, sv.special = sp >= 0;
+ if (sp >= 0) {
+ sv.size = (uint8_t)lv_special[sp][1], sv.puz = lv_special[sp][2];
+ return;
+ }
+ sv.size = (uint8_t)size_at(lv);
+ if (is_hard(lv)) rank = 5;
+ else {
+ if (main_path && sv.strat < 2) sv.strat = 2;
+ int s = lv <= 5 ? 1 : sv.strat, cap = main_path ? 4 : lv >= 21 ? 3 : 2;
+ if (s > cap) s = cap;
+ if (s >= 3) s = 2 + (int)(rnd() % (uint32_t)(s - 1));
+ rank = s;
+ }
+ int p = find_pool(sv.size, rank, main_path);
+ for (int r = rank - 1; p < 0 && r >= 1; r--) p = find_pool(sv.size, r, main_path); /* (as the game relaxes) */
+ for (int r = rank + 1; p < 0 && r <= 5; r++) p = find_pool(sv.size, r, main_path);
+ uint8_t *c = sv.pc[p];
+ for (int k = 0; main_path && rank < 5 && k < NLK; k++)
+ if (lv_lk[k][0] == sv.size && lv_lk[k][1] == rank && c[2] >= 4 && sv.lkc[k] < lv_lk[k][4]) {
+ sv.puz = (uint16_t)(lv_lk[k][3] + sv.lkc[k]++), c[2] = 0;
+ return;
+ }
+ if (c[0] >= lv_pool[p][4]) c[0] = 0, c[1] = (uint8_t)((c[1] + 1) & 7);
+ sv.puz = (uint16_t)(pool_first(p) + c[0]++), sv.t = c[1];
+ if (c[2] < 255) c[2]++;
+}
+
+/* The colours of the regions (LevelGenerator.compute_color_map_with_seed): regions in turn (most neighbours
+ first, or shuffled by the puzzle's turn), each the unused colour farthest from its coloured neighbours. */
+static void colour(int seed) {
+ static const uint32_t rgb[12] = {0xE6A8C1, 0xC1658A, 0x9179D1, 0xFEA0EC, 0xFFA96C, 0xE3BA46,
+ 0x6182B5, 0xA6BED8, 0x69BCE6, 0x46B3B0, 0xACD994, 0xAB6D46};
+ uint16_t adj[NMAX] = {0};
+ int order[NMAX], used = 0;
+ for (int i = 0; i < n * n; i++) {
+ int a = reg[i];
+ if (i % n + 1 < n && reg[i + 1] != a) adj[a] |= (uint16_t)(1 << reg[i + 1]), adj[reg[i + 1]] |= (uint16_t)(1 << a);
+ if (i + n < n * n && reg[i + n] != a) adj[a] |= (uint16_t)(1 << reg[i + n]), adj[reg[i + n]] |= (uint16_t)(1 << a);
+ }
+ for (int i = 0; i < n; i++) order[i] = i, color[i] = -1;
+ if (!seed)
+ for (int i = 1; i < n; i++) /* (a stable sort: most neighbours, then the lower number) */
+ for (int j = i; j > 0 && __builtin_popcount(adj[order[j]]) > __builtin_popcount(adj[order[j - 1]]); j--) {
+ int t = order[j];
+ order[j] = order[j - 1], order[j - 1] = t;
+ }
+ else {
+ uint64_t st = ((uint64_t)seed * 1664525u + 1013904223u) & 0x7FFFFFFF;
+ for (int i = n - 1; i > 0; i--) {
+ st = (st * 1664525u + 1013904223u) & 0x7FFFFFFF;
+ int j = (int)(st % (uint64_t)(i + 1)), t = order[i];
+ order[i] = order[j], order[j] = t;
+ }
+ }
+ for (int k = 0; k < n; k++) {
+ int ri = order[k], best = 0;
+ int64_t best_d = -1;
+ for (int ci = 0; ci < 12; ci++) {
+ if (used >> ci & 1) continue;
+ int64_t d = INT64_MAX;
+ for (int nb = 0; nb < n; nb++)
+ if (adj[ri] >> nb & 1 && color[nb] >= 0) {
+ int dr = (int)(rgb[ci] >> 16) - (int)(rgb[color[nb]] >> 16), dg = (int)(rgb[ci] >> 8 & 255) - (int)(rgb[color[nb]] >> 8 & 255),
+ db = (int)(rgb[ci] & 255) - (int)(rgb[color[nb]] & 255);
+ if (dr * dr + dg * dg + db * db < d) d = dr * dr + dg * dg + db * db;
+ }
+ if (d > best_d) best_d = d, best = ci;
+ }
+ color[ri] = best, used |= 1 << best;
+ }
+}
+
+/* Counts the solutions, up to two; the first in sol. */
+static int nsol, tmp[NMAX];
+static void search(int r, int cols, int regs) {
+ if (r == n) {
+ if (!nsol++)
+ for (int i = 0; i < n; i++) sol[i] = tmp[i];
+ return;
+ }
+ for (int c = 0; c < n && nsol < 2; c++) {
+ int g = reg[r * n + c];
+ if (cols >> c & 1 || regs >> g & 1 || (r && (tmp[r - 1] - c) * (tmp[r - 1] - c) <= 1)) continue;
+ tmp[r] = c;
+ search(r + 1, cols | 1 << c, regs | 1 << g);
+ }
+}
+static int solve(void) {
+ nsol = 0;
+ search(0, 0, 0);
+ return nsol;
+}
+
+/* The puzzle of sv.puz, turned by sv.t (LevelData.apply_transform), solved and coloured. */
+static const uint8_t *bp;
+static int bb;
+static int bits(int k) {
+ int v = 0;
+ while (k--) {
+ v = v << 1 | (*bp >> (7 - bb) & 1);
+ if (++bb == 8) bb = 0, bp++;
+ }
+ return v;
+}
+static void load_puzzle(void) {
+ int t[NMAX * NMAX];
+ bp = lv_data + lv_at[sv.puz], bb = 0, n = sv.size;
+ for (int i = 0; i < n * n; i++)
+ reg[i] = i % n && bits(1) ? reg[i - 1] : i >= n && bits(1) ? reg[i - n] : bits(4);
+ if (sv.special && lv_special[special_at(sv.level)][3])
+ for (int i = 0; i < n; i++) color[i] = bits(4) % 12;
+ if (sv.t >= 4)
+ for (int i = 0; i < n * n; i++) t[i] = reg[i - i % n + n - 1 - i % n];
+ else
+ for (int i = 0; i < n * n; i++) t[i] = reg[i];
+ for (int k = 0; k < sv.t % 4; k++) { /* a quarter turn: new (r, c) is old (n - 1 - c, r) */
+ for (int i = 0; i < n * n; i++) reg[i] = t[(n - 1 - i % n) * n + i / n];
+ for (int i = 0; i < n * n; i++) t[i] = reg[i];
+ }
+ for (int i = 0; i < n * n; i++) reg[i] = t[i] % NMAX;
+ solve();
+ if (!(sv.special && lv_special[special_at(sv.level)][3])) colour(sv.t);
+}
+
+/* ------------------------------------------------------------ playing */
+static uint16_t undo[256]; /* each X put or taken: the cell, the state before, and whether a move starts there */
+static uint8_t utop, ucount;
+static int stroke = -1; /* while OK is held: what moving onto a cell does (MARK or EMPTY) */
+
+static int cats(void) {
+ int k = 0;
+ for (int i = 0; i < n * n; i++) k += sv.cell[i] == CAT;
+ return k;
+}
+static void set_mark(int i, int v, int first) {
+ if (sv.cell[i] == CAT || sv.cell[i] == v) return;
+ undo[utop++] = (uint16_t)(i | sv.cell[i] << 7 | first << 9);
+ if (ucount < 255) ucount++;
+ sv.cell[i] = (uint8_t)v;
+}
+static void undo_move(void) {
+ while (ucount) {
+ uint16_t e = undo[--utop];
+ ucount--;
+ if (sv.cell[e & 127] != CAT) sv.cell[e & 127] = (uint8_t)(e >> 7 & 3);
+ if (e >> 9 & 1) break;
+ }
+}
+
+enum { OV_NONE, OV_MENU, OV_HELP, OV_WON, OV_FAILED };
+static void won(void);
+static void failed(void);
+
+/* a cat on cell i (the double tap): it stays if the solution has it there; otherwise the cell gets an X
+ and a fish is lost */
+static void place(int i) {
+ if (sv.cell[i] == CAT || ov) return;
+ if (sol[i / n] == i % n) {
+ sv.cell[i] = CAT;
+ if (cats() == n) won();
+ return;
+ }
+ sv.cell[i] = MARK, err_cell = (uint32_t)i, err_until = now + 600;
+ if (sv.lives) sv.lives--;
+ sv.perfect = 0;
+ if (!sv.lives) failed();
+}
+
+/* the level from its start (a retry, or a new level): three fish, the board empty, and on levels 1 to 10 a
+ cat already in (LevelData.compute_prefill) */
+static void start_level(void) {
+ load_puzzle();
+ for (int i = 0; i < NMAX * NMAX; i++) sv.cell[i] = EMPTY;
+ sv.lives = 3, sv.perfect = 1, sv.flags |= 2, ucount = 0, cr = cc = n / 2, err_until = 0;
+ if (sv.level <= 10) { /* (levels 7 to 10: a cat alone in its colour) */
+ int area[NMAX] = {0}, at = -1, one = sv.level >= 7;
+ for (int i = 0; i < n * n; i++) area[reg[i]]++;
+ for (int r = 0; r < n && at < 0; r++)
+ if ((area[reg[r * n + sol[r]]] == 1) == one) at = r * n + sol[r];
+ sv.cell[at < 0 ? sol[0] : at] = CAT;
+ }
+}
+
+/* GameState._apply_level_won: the difficulty climbs after clean wins (two in a row before level 51, then
+ one) and drops after failures, then the next level is dealt */
+static void won(void) {
+ int lv = sv.level;
+ if (lv >= 6) {
+ int mx = lv >= 201 ? 6 : lv >= 101 ? 5 : lv >= 51 ? 4 : lv >= 21 ? 3 : 2, mn = mx >= 5 ? 2 : 1, demoted = 0;
+ if (!sv.dirty) {
+ if (++sv.clean >= (lv >= 51 ? 1 : 2) && sv.strat < mx) sv.strat++, sv.clean = 0;
+ } else sv.clean = 0;
+ if (sv.fails >= (lv >= 21 ? 2 : 1) && sv.strat > mn) sv.strat--, demoted = 1;
+ sv.fails = 0;
+ if (lv >= 21) {
+ if (!sv.retried) sv.rlevels = sv.rstrat = 0;
+ else if (sv.strat != sv.rstrat) sv.rlevels = 1, sv.rstrat = sv.strat;
+ else if (++sv.rlevels >= 2 && sv.strat > mn && !demoted) sv.strat--, sv.rlevels = sv.rstrat = 0;
+ }
+ if (sv.pend && !demoted) sv.strat = (uint8_t)(sv.strat > mn ? sv.strat - 1 : mn), sv.pend = 0, demoted = 1;
+ if (sv.retried && !demoted) {
+ if (is_hard(lv + 1) || special_at(lv + 1) >= 0) sv.pend = 1;
+ else sv.strat = (uint8_t)(sv.strat > mn ? sv.strat - 1 : mn);
+ }
+ }
+ sv.retried = sv.dirty = 0, sv.flags &= (uint8_t)~2, sv.wins++, sv.level++;
+ deal();
+ ov = OV_WON, menu = 0;
+}
+static void failed(void) {
+ sv.retried = sv.dirty = 1;
+ if (sv.level >= 6) sv.clean = 0, sv.fails++;
+ sv.flags &= (uint8_t)~2;
+ ov = OV_FAILED, menu = 0;
+}
+
+/* ------------------------------------------------------------ the helpers */
+/* Locate (LocateStrategy): of the cats still missing, in colours without one, the one whose colour has the
+ fewest cells left without an X */
+static void locate(void) {
+ int left[NMAX] = {0}, done = 0, best = -1, bl = 999;
+ for (int i = 0; i < n * n; i++) {
+ if (sv.cell[i] == CAT) done |= 1 << reg[i];
+ if (sv.cell[i] != MARK) left[reg[i]]++;
+ }
+ for (int r = 0; r < n; r++) {
+ int i = r * n + sol[r];
+ if (sv.cell[i] != CAT && !(done >> reg[i] & 1) && left[reg[i]] < bl) bl = left[reg[i]], best = i;
+ }
+ if (best < 0) return;
+ sv.dirty = 1;
+ place(best);
+}
+
+/* Hints (HintEngine, in the game's order): the X's a cat already decides, an X on a cat's cell, a line or
+ colour with one place left, a colour held in one line (or a line held by one colour), a few colours held
+ in as many lines, and a cell where a cat would leave a line or colour with no room. */
+enum { H_NONE, H_MARKS, H_UNMARK, H_ONE_ROW, H_ONE_COL, H_ONE_COLOR, H_COLOR_LINE, H_LINE_COLOR, H_SETS, H_CHAIN };
+static struct {
+ int kind, cell;
+ uint8_t hl[NMAX * NMAX]; /* 1 a cell the hint is about, 2 one it changes */
+} hint;
+static const char *const hint_text[] = {
+ 0,
+ T("This cat rules out its row, its column and the cells around it."),
+ T("A cat goes in this cell: take the X off."),
+ T("Only one cell in this row can take a cat."),
+ T("Only one cell in this column can take a cat."),
+ T("Only one cell of this color can take a cat."),
+ T("This color's cat must be in this line, so the rest of the line can't have one."),
+ T("This line's cat must be in this color, so the rest of the color can't have one."),
+ T("These colors fill these lines between them, so nothing else in the lines can have a cat."),
+ T("A cat here would leave a row, column or color with no room."),
+};
+
+static uint8_t cand[NMAX * NMAX]; /* the cells a cat could still go in */
+static void candidates(const uint8_t *cell, uint8_t *out) {
+ int rows = 0, cols = 0, regs = 0;
+ for (int i = 0; i < n * n; i++)
+ if (cell[i] == CAT) rows |= 1 << i / n, cols |= 1 << i % n, regs |= 1 << reg[i];
+ for (int i = 0; i < n * n; i++) {
+ int r = i / n, c = i % n, ok = cell[i] == EMPTY && !(rows >> r & 1) && !(cols >> c & 1) && !(regs >> reg[i] & 1);
+ for (int dr = -1; dr <= 1 && ok; dr++)
+ for (int dc = -1; dc <= 1; dc++)
+ if (r + dr >= 0 && r + dr < n && c + dc >= 0 && c + dc < n && cell[(r + dr) * n + c + dc] == CAT) ok = 0;
+ out[i] = (uint8_t)ok;
+ }
+}
+/* unit u: rows 0..n-1, columns n..2n-1, colours 2n..3n-1 */
+static int unit_of(int type, int i) { return type == 0 ? i / n : type == 1 ? n + i % n : 2 * n + reg[i]; }
+static uint16_t touch[3 * NMAX][3]; /* the rows, columns and colours a unit's candidates are in */
+static uint16_t has_cat[3]; /* the rows, columns and colours with a cat */
+
+/* k colours whose cells left lie in k lines (or k lines in k colours): the other cells of those lines
+ (colours) get X's. Units of type a picked, their candidates spanning units of type b. */
+static int set_k, set_a, set_b;
+static bool sets(int from, int k, uint32_t pick, uint32_t span) {
+ if (__builtin_popcount(span) > set_k) return false;
+ if (k == set_k) {
+ if (__builtin_popcount(span) != k) return false;
+ bool any = false;
+ for (int i = 0; i < n * n; i++) {
+ int in_b = span >> (unit_of(set_b, i) - set_b * n) & 1, in_a = pick >> (unit_of(set_a, i) - set_a * n) & 1;
+ hint.hl[i] = in_b && !in_a && sv.cell[i] == EMPTY ? 2 : in_a && cand[i] ? 1 : 0;
+ any |= hint.hl[i] == 2;
+ }
+ return any;
+ }
+ for (int u = from; u < n; u++)
+ if (!(has_cat[set_a] >> u & 1) && touch[set_a * n + u][set_b] && sets(u + 1, k + 1, pick | 1u << u, span | touch[set_a * n + u][set_b]))
+ return true;
+ return false;
+}
+
+/* a cat on cell i, then the cells forced in turn (a row, column or colour with one place left): the cats
+ placed before some unit is left with no room, or -1 */
+static int contradiction(int i) {
+ uint8_t cell[NMAX * NMAX], c2[NMAX * NMAX];
+ for (int k = 0; k < n * n; k++) cell[k] = sv.cell[k] == CAT ? CAT : cand[k] ? EMPTY : MARK;
+ cell[i] = CAT;
+ for (int depth = 0;; depth++) {
+ int cnt[3 * NMAX] = {0}, at[3 * NMAX], has[3] = {0};
+ candidates(cell, c2);
+ for (int k = 0; k < n * n; k++)
+ for (int t = 0; t < 3; t++) {
+ int u = unit_of(t, k);
+ if (cell[k] == CAT) has[t] |= 1 << (u - t * n);
+ if (c2[k]) cnt[u]++, at[u] = k;
+ }
+ int forced = -1;
+ for (int u = 0; u < 3 * n; u++) {
+ if (has[u / n] >> (u % n) & 1) continue;
+ if (!cnt[u]) return depth;
+ if (cnt[u] == 1 && forced < 0) forced = at[u];
+ }
+ if (forced < 0) return -1;
+ cell[forced] = CAT;
+ }
+}
+
+static void find_hint(void) {
+ for (int i = 0; i < n * n; i++) hint.hl[i] = 0;
+ hint.kind = H_NONE;
+ for (int i = 0; i < n * n; i++) /* a cat's row, column and neighbours */
+ if (sv.cell[i] == CAT) {
+ for (int k = 0; k < n * n; k++) {
+ int dr = k / n - i / n, dc = k % n - i % n;
+ if (sv.cell[k] == EMPTY && (!dr || !dc || (dr * dr <= 1 && dc * dc <= 1))) hint.hl[k] = 2, hint.kind = H_MARKS;
+ }
+ if (hint.kind) {
+ hint.cell = i, hint.hl[i] = 1;
+ return;
+ }
+ }
+ for (int r = 0; r < n; r++) /* an X where the cat is */
+ if (sv.cell[r * n + sol[r]] == MARK) {
+ hint.kind = H_UNMARK, hint.cell = r * n + sol[r], hint.hl[hint.cell] = 2;
+ return;
+ }
+ candidates(sv.cell, cand);
+ int cnt[3 * NMAX] = {0}, at[3 * NMAX];
+ has_cat[0] = has_cat[1] = has_cat[2] = 0;
+ for (int u = 0; u < 3 * n; u++) touch[u][0] = touch[u][1] = touch[u][2] = 0;
+ for (int i = 0; i < n * n; i++)
+ for (int t = 0; t < 3; t++) {
+ int u = unit_of(t, i);
+ if (sv.cell[i] == CAT) has_cat[t] |= (uint16_t)(1 << (u - t * n));
+ if (cand[i]) {
+ cnt[u]++, at[u] = i;
+ for (int t2 = 0; t2 < 3; t2++) touch[u][t2] |= (uint16_t)(1 << (unit_of(t2, i) - t2 * n));
+ }
+ }
+ for (int u = 0; u < 3 * n; u++) /* one place left */
+ if (cnt[u] == 1 && !(has_cat[u / n] >> (u % n) & 1)) {
+ for (int i = 0; i < n * n; i++) hint.hl[i] = unit_of(u / n, i) == u;
+ hint.kind = H_ONE_ROW + u / n, hint.cell = at[u], hint.hl[at[u]] = 2;
+ return;
+ }
+ /* a colour in one line, then a line in one colour; then 2, 3, ... of them */
+ static const uint8_t pass[4][2] = {{2, 0}, {2, 1}, {0, 2}, {1, 2}};
+ for (set_k = 1; 2 * set_k <= n; set_k++)
+ for (int p = 0; p < 4; p++) {
+ set_a = pass[p][0], set_b = pass[p][1];
+ if (sets(0, 0, 0, 0)) {
+ hint.kind = set_k > 1 ? H_SETS : p < 2 ? H_COLOR_LINE : H_LINE_COLOR;
+ return;
+ }
+ }
+ for (int i = 0; i < n * n; i++) hint.hl[i] = 0;
+ int best = -1, bd = 99;
+ for (int i = 0; i < n * n; i++) /* a cat that leaves no room, the soonest */
+ if (cand[i]) {
+ int d = contradiction(i);
+ if (d >= 0 && d < bd) bd = d, best = i;
+ }
+ if (best >= 0) hint.kind = H_CHAIN, hint.cell = best, hint.hl[best] = 2;
+}
+
+static void apply_hint(void) {
+ int first = 1;
+ sv.dirty = 1;
+ if (hint.kind == H_ONE_ROW || hint.kind == H_ONE_COL || hint.kind == H_ONE_COLOR) place(hint.cell);
+ else if (hint.kind == H_UNMARK) set_mark(hint.cell, EMPTY, 1);
+ else
+ for (int i = 0; i < n * n; i++)
+ if (hint.hl[i] == 2) set_mark(i, MARK, first), first = 0;
+ hint.kind = H_NONE;
+}
+
+/* ------------------------------------------------------------ drawing */
+static int pitch, bx, by; /* the board: a cell's pitch, its top left */
+static color_t catc[48 * 48];
+static uint8_t cat_a[48 * 48], x_a[48 * 48]; /* the cat and the X at the cell's size, their opacity 0-32 */
+static int cat_w, cat_h, cell_w;
+
+static inline void blend(int x, int y, color_t c, int a) {
+ if (a > 0 && x >= 0 && x < SCREEN_W && y >= gfx_y0 && y < gfx_y1) {
+ color_t *p = gfx_buf + (y - gfx_y0) * SCREEN_W + x;
+ *p = a >= 32 ? c : gfx_mix(*p, c, a);
+ }
+}
+static int nib(const sprite_t *s, int x, int y) { return s->px[y * ((s->w + 1) / 2) + x / 2] >> (x & 1 ? 0 : 4) & 15; }
+static void sprite(const sprite_t *s, int x, int y) {
+ for (int j = NP_MAX(0, gfx_y0 - y); j < s->h && y + j < gfx_y1; j++)
+ for (int i = 0; i < s->w; i++) {
+ int k = nib(s, i, j);
+ blend(x + i, y + j, s->pal[k], (s->alpha[k] + 4) >> 3);
+ }
+}
+/* the cat shrunk to w x h: each pixel the mean of 4 x 4 samples */
+static void scale_cat(int w, int h) {
+ const sprite_t *s = &spr_cat;
+ cat_w = w, cat_h = h;
+ for (int y = 0; y < h; y++)
+ for (int x = 0; x < w; x++) {
+ int sr = 0, sg = 0, sb = 0, sa = 0;
+ for (int v = 0; v < 4; v++)
+ for (int u = 0; u < 4; u++) {
+ int k = nib(s, (x * 4 + u) * s->w / (w * 4), (y * 4 + v) * s->h / (h * 4)), a = s->alpha[k];
+ uint16_t c = s->pal[k];
+ sr += (c >> 11) * a, sg += (c >> 5 & 63) * a, sb += (c & 31) * a, sa += a;
+ }
+ cat_a[y * w + x] = (uint8_t)((sa / 16 + 4) >> 3);
+ catc[y * w + x] = sa ? (color_t)((sr / sa) << 11 | (sg / sa) << 5 | sb / sa) : 0;
+ }
+}
+/* the game's white X, two strokes with round ends, at the cell's size */
+static void make_x(int w) {
+ float half = w * 0.25f, th = w * 0.085f + 0.6f, c = (w - 1) * 0.5f;
+ cell_w = w;
+ for (int y = 0; y < w; y++)
+ for (int x = 0; x < w; x++) {
+ float px = x - c, py = y - c, best = 99;
+ for (int d = -1; d <= 1; d += 2) { /* the distance to each stroke, from (-half, -d half) to (half, d half) */
+ float t = (px + d * py) / 2;
+ t = t < -half ? -half : t > half ? half : t;
+ float ex = px - t, ey = py - d * t, dist = __builtin_sqrtf(ex * ex + ey * ey);
+ if (dist < best) best = dist;
+ }
+ float a = th - best + 0.5f;
+ x_a[y * w + x] = (uint8_t)(a <= 0 ? 0 : a >= 1 ? 32 : a * 32);
+ }
+}
+static void layout(void) {
+ pitch = NP_MIN(40, 214 / n);
+ int side = n * pitch + 6;
+ bx = 4 + (230 - side) / 2, by = 2 + (224 - side) / 2;
+ int s = pitch - 2, w = s * 92 / 100;
+ scale_cat(w, w * spr_cat.h / spr_cat.w);
+ make_x(s);
+}
+static void cell_at(int i, int *x, int *y) { *x = bx + 3 + i % n * pitch + 1, *y = by + 3 + i / n * pitch + 1; }
+
+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 char *num(char *o, uint32_t v) {
+ char t[10];
+ int k = 0;
+ do t[k++] = (char)('0' + v % 10); while (v /= 10);
+ while (k) *o++ = t[--k];
+ *o = 0;
+ return o;
+}
+
+static void board(void) {
+ int s = pitch - 2, rad = s / 5 + 1;
+ gfx_rrect(bx, by, n * pitch + 6, n * pitch + 6, 6, WHITE, 256);
+ for (int i = 0; i < n * n; i++) {
+ int x, y;
+ cell_at(i, &x, &y);
+ if (y >= gfx_y1 || y + s <= gfx_y0) continue;
+ color_t c = gfx_rgb(palette[color[reg[i]]]);
+ if (hint.kind && !hint.hl[i]) c = gfx_mix(c, WHITE, 14);
+ gfx_rrect(x, y, s, s, rad, c, 256);
+ if (sv.cell[i] == CAT) {
+ int ox = x + (s - cat_w) / 2, oy = y + (s - cat_h) / 2;
+ for (int j = NP_MAX(0, gfx_y0 - oy); j < cat_h && oy + j < gfx_y1; j++)
+ for (int k = 0; k < cat_w; k++) blend(ox + k, oy + j, catc[j * cat_w + k], cat_a[j * cat_w + k]);
+ }
+ bool err = err_until && (uint32_t)i == err_cell;
+ if (err) gfx_rrect(x, y, s, s, rad, RED, 200);
+ int preview = hint.kind && hint.hl[i] == 2 && sv.cell[i] == EMPTY && hint.kind != H_ONE_ROW && hint.kind != H_ONE_COL &&
+ hint.kind != H_ONE_COLOR;
+ if (sv.cell[i] == MARK || preview)
+ for (int j = NP_MAX(0, gfx_y0 - y); j < s && y + j < gfx_y1; j++)
+ for (int k = 0; k < s; k++) blend(x + k, y + j, preview ? INK : WHITE, preview ? x_a[j * s + k] / 2 : x_a[j * s + k]);
+ if (hint.kind && hint.hl[i] == 2 && !preview) gfx_rrect_outline(x - 1, y - 1, s + 2, s + 2, rad + 1, 2, SUN, 256);
+ }
+ if (!ov) { /* the cell picked: a black frame with a white edge inside, around it */
+ int x, y;
+ cell_at(cr * n + cc, &x, &y);
+ gfx_rrect_outline(x - 3, y - 3, s + 6, s + 6, rad + 3, 3, INK, 256);
+ gfx_rrect_outline(x, y, s, s, rad, 1, WHITE, 256);
+ }
+}
+
+static void panel(void) {
+ char s[24];
+ if (hint.kind) {
+ sprite(&spr_lamp, 265, 6);
+ int y = gfx_paragraph(&np_font_small, 276, 44, 80, 13, hint_text[hint.kind], TEXT, 256);
+ say(&np_font_small, 276, y + 10, T("OK apply"), TEXT);
+ say(&np_font_small, 276, y + 24, T("Back close"), SOFT);
+ return;
+ }
+ say(&np_font_small, 276, 14, T("Level"), SOFT);
+ num(s, sv.level);
+ say(&np_font_title, 276, 40, s, TEXT);
+ if (is_hard(sv.level)) {
+ int w = gfx_text_width(&np_font_small, T("Hard"));
+ sprite(&spr_flame, 276 - (w + 15) / 2, 47);
+ gfx_text(&np_font_small, 276 - (w + 15) / 2 + 15, 59, T("Hard"), RED, 256);
+ }
+ for (int f = 0; f < 3; f++) sprite(f < sv.lives ? &spr_fish : &spr_fish_dim, 243 + 23 * f, 68);
+ char *e = num(s, (uint32_t)cats());
+ *e++ = ' ', *e++ = '/', *e++ = ' ';
+ num(e, (uint32_t)n);
+ say(&np_font_body, 276, 110, s, TEXT);
+ sprite(&spr_lamp, 244, 130);
+ sprite(&spr_locate, 286, 130);
+ say(&np_font_small, 255, 166, T("shift"), TEXT);
+ say(&np_font_small, 297, 166, T("alpha"), TEXT);
+ say(&np_font_small, 255, 179, T("hint"), SOFT);
+ say(&np_font_small, 297, 179, T("find"), SOFT);
+}
+
+/* each card: its title, then its buttons; what each button leads to */
+#define QUIT 6
+#define NEXT 7
+#define RETRY 8
+static const char *const cards[5][4] = {
+ {0},
+ {T("Paused"), T("Resume"), T("How to play"), T("Quit game")},
+ {T("How to play"), T("Play")},
+ {T("Clear!"), T("Next level"), T("Quit game")},
+ {T("Out of fish"), T("Try again"), T("Quit game")},
+};
+static const uint8_t buttons[5] = {0, 3, 1, 2, 2}, leads[5][3] = {
+ {0}, {OV_NONE, OV_HELP, QUIT}, {OV_NONE}, {NEXT, QUIT}, {RETRY, QUIT}};
+
+static void overlay(void) {
+ char s[32];
+ int nb = buttons[ov], extra = ov == OV_HELP ? 98 : 26, h = 50 + extra + 30 * nb, y = (SCREEN_H - h) / 2;
+ gfx_fill_alpha(0, 0, SCREEN_W, SCREEN_H, INK, 100);
+ gfx_rrect(48, y - 2, 224, h + 4, 14, TEXT, 256);
+ gfx_rrect(50, y, 220, h, 12, HEX(0xFFF8EC), 256);
+ say(&np_font_title, 160, y + 32, cards[ov][0], ov == OV_WON ? HEX(0xE8920C) : TEXT);
+ y += 44;
+ if (ov == OV_HELP) {
+ int b = gfx_paragraph(&np_font_small, 160, y + 6, 200, 13,
+ T("One cat in each row, each column and each color. Cats can't touch, not even at the corners."), TEXT, 256);
+ gfx_paragraph(&np_font_small, 160, b + 6, 200, 13,
+ T("OK marks an X. OK twice (or EXE) places a cat. A wrong cat costs a fish; with all 3 gone, try again."), SOFT, 256);
+ } else {
+ char *e = s;
+ for (const char *m = T("Level "); *m;) *e++ = *m++;
+ num(e, ov == OV_WON ? sv.level - 1u : sv.level);
+ say(&np_font_body, 160, y + 12, ov == OV_WON && sv.perfect ? T("Perfect!") : s, SOFT);
+ }
+ y += extra;
+ for (int i = 0; i < nb; i++, y += 30) {
+ bool on = menu == i;
+ gfx_rrect(70, y, 180, 26, 13, on ? ORANGE : HEX(0xF3E6D3), 256);
+ say(&np_font_body, 160, y + 18, ov == OV_MENU && i == 2 && quit_ok ? T("OK again to quit") : cards[ov][i + 1],
+ on ? WHITE : TEXT);
+ }
+}
+
+static void scene(void *ctx) {
+ gfx_vgrad(0, 0, SCREEN_W, SCREEN_H, 0xFAE4BA, 0xFAF7ED);
+ board();
+ panel();
+ if (!hint.kind) say(&np_font_small, 160, 236, T("OK X OK OK cat DEL undo Back menu"), SOFT);
+ 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 = 'M', sv.version = 1;
+ np_file_write(SAVE_NAME, &sv, sizeof sv);
+}
+
+/* a save this version could have written; anything else starts over */
+static bool sane(void) {
+ if (sv.magic != 'M' || sv.version != 1 || !sv.level || sv.puz >= NPUZ || sv.t > 7 || sv.lives > 3 || sv.strat > 7) return false;
+ for (int p = 0; p < NPOOL; p++)
+ if (sv.pc[p][0] > lv_pool[p][4] || sv.pc[p][1] > 7) return false;
+ for (int k = 0; k < NLK; k++)
+ if (sv.lkc[k] > lv_lk[k][4]) return false;
+ int sp = special_at(sv.level);
+ if (sv.size != (sp >= 0 ? lv_special[sp][1] : size_at(sv.level)) || !!sv.special != (sp >= 0)) return false;
+ return true;
+}
+
+int main(void) {
+ np_app_begin();
+ color_t *their_strip = gfx_buf;
+ gfx_buf = strip;
+ now = (uint32_t)eadk_timing_millis();
+ uint32_t len = 0, repeat_at = 0, last_ok = 0, ok_at = ~0u;
+ const uint8_t *d = np_file_read(SAVE_NAME, &len);
+ for (uint32_t i = 0; i < sizeof sv; i++) ((uint8_t *)&sv)[i] = d && len == sizeof sv ? d[i] : 0;
+ if (!sane()) {
+ for (uint32_t i = 0; i < sizeof sv; i++) ((uint8_t *)&sv)[i] = 0;
+ sv.magic = 'M', sv.version = 1, sv.level = 1, sv.strat = 1;
+ deal();
+ }
+ if (!sv.seed) sv.seed = eadk_random() | 1;
+ load_puzzle();
+ bool in_play = sv.flags & 2;
+ for (int i = 0; i < n * n && in_play; i++) /* a cat only where the solution has one */
+ if (sv.cell[i] > CAT || (sv.cell[i] == CAT && sol[i / n] != i % n)) in_play = false;
+ if (!in_play) start_level();
+ if (!sv.lives) sv.lives = 3;
+ cr = cc = n / 2;
+ layout();
+ if (!(sv.flags & 1)) ov = OV_HELP, sv.flags |= 1;
+ uint64_t held = eadk_keyboard_scan(), stale = held; /* keys still down from the launcher wait to be let go */
+ bool dirty_screen = true;
+ for (;;) {
+ now = (uint32_t)eadk_timing_millis();
+ uint64_t k = eadk_keyboard_scan(), 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 & (K(eadk_key_home) | K(eadk_key_on_off))) break;
+ int dx = !!(hit & K(eadk_key_right)) - !!(hit & K(eadk_key_left));
+ int dy = !!(hit & K(eadk_key_down)) - !!(hit & K(eadk_key_up));
+ bool ok = hit & K(eadk_key_ok), exe = hit & K(eadk_key_exe), back = hit & K(eadk_key_back);
+ if (ov) {
+ int i = menu = (menu + dy + buttons[ov]) % buttons[ov], to = (ok || exe) ? leads[ov][i] : ov;
+ if (dy) quit_ok = 0;
+ if (back && (ov == OV_MENU || ov == OV_HELP)) to = OV_NONE;
+ if (to == QUIT && (ov != OV_MENU || quit_ok)) {
+ if (ov == OV_MENU) sv.dirty = 1; /* (leaving a level part way, as the game counts it) */
+ break;
+ }
+ if (to == QUIT) to = OV_MENU, quit_ok = 1; /* Quit game asks first */
+ if (to != ov) menu = 0;
+ if (to == NEXT || to == RETRY) {
+ start_level();
+ layout();
+ to = OV_NONE;
+ }
+ ov = to;
+ } else if (hint.kind) {
+ if (ok || exe) apply_hint();
+ else if (back || hit & K(eadk_key_shift)) hint.kind = H_NONE;
+ } else if (back) {
+ ov = OV_MENU, menu = quit_ok = 0;
+ } else if (hit) {
+ int i = (cr = NP_MAX(0, NP_MIN(n - 1, cr + dy))) * n + (cc = NP_MAX(0, NP_MIN(n - 1, cc + dx)));
+ if ((dx || dy) && stroke >= 0 && k & K(eadk_key_ok)) set_mark(i, stroke, 0); /* OK held: a swipe */
+ if (exe) place(i);
+ else if (ok && now - last_ok < 400 && ok_at == (uint32_t)i) place(i), last_ok = 0, stroke = -1; /* the double tap */
+ else if (ok) {
+ stroke = sv.cell[i] == EMPTY ? MARK : sv.cell[i] == MARK ? EMPTY : -1;
+ if (stroke >= 0) set_mark(i, stroke, 1);
+ last_ok = now, ok_at = (uint32_t)i;
+ }
+ if (hit & K(eadk_key_backspace)) undo_move();
+ if (hit & K(eadk_key_alpha)) locate();
+ if (hit & K(eadk_key_shift)) {
+ find_hint();
+ if (!hint.kind) locate();
+ }
+ }
+ if (!(k & K(eadk_key_ok))) stroke = -1;
+ if (err_until && (int32_t)(now - err_until) >= 0) err_until = 0, dirty_screen = true;
+ if (hit) save(), dirty_screen = true;
+ if (dirty_screen || err_until) draw(), dirty_screen = false;
+ eadk_timing_msleep(20);
+ }
+ save();
+ gfx_buf = their_strip;
+ return np_app_end();
+}
diff --git a/games/meowdoku/tests/play.c b/games/meowdoku/tests/play.c
new file mode 100644
index 00000000..7411680f
--- /dev/null
+++ b/games/meowdoku/tests/play.c
@@ -0,0 +1,393 @@
+/* Meowdoku on a computer, for tests and pictures (make host, make test).
+ *
+ * play check every puzzle in all 8 turns: exactly one solution, all its colours, distinct colours;
+ * the hints alone solve every puzzle without a wrong step; the dealing over 1000 levels
+ * for a player who always wins and one who fails each level once; the rules (a wrong
+ * cat, three of them, undo, locate); a level won with the keys; bad saves; random keys
+ * 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)
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#define main meowdoku_main
+#include "../src/main.c"
+#undef main
+
+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); }
+static uint8_t file[4096];
+static uint32_t file_len, has_file;
+const uint8_t *np_file_read(const char *name, uint32_t *len) { return has_file ? (*len = file_len, file) : NULL; }
+bool np_file_write(const char *name, const void *data, uint32_t len) {
+ if (len > sizeof file) return false;
+ memcpy(file, data, len), file_len = len, has_file = 1;
+ return true;
+}
+
+/* the keys: a script of presses, each held `hold` ms; the clock moves on as the game sleeps */
+static uint64_t clock_ms;
+static struct { uint64_t t; int key, hold; } script[8192];
+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 + (uint64_t)script[i].hold) k |= 1ull << script[i].key;
+ return k;
+}
+
+/* (tests/test_games.py reads meowdoku.sav at these places) */
+_Static_assert(sizeof sv == 212 && __builtin_offsetof(__typeof__(sv), cell) == 26, "the save's layout");
+static int fails;
+#define CHECK(c, ...) do { if (!(c) && fails++ < 20) { printf("FAIL: " __VA_ARGS__); printf("\n"); } } while (0)
+
+/* the rules, checked apart from the solver: n cats, one per row, column and colour, none touching */
+static bool valid(const int *s) {
+ int cols = 0, regs = 0;
+ for (int r = 0; r < n; r++) {
+ if (s[r] < 0 || s[r] >= n) return false;
+ cols |= 1 << s[r], regs |= 1 << reg[r * n + s[r]];
+ if (r && abs(s[r] - s[r - 1]) <= 1) return false;
+ }
+ return cols == (1 << n) - 1 && regs == (1 << n) - 1;
+}
+
+static void fresh(void) {
+ memset(&sv, 0, sizeof sv);
+ sv.magic = 'M', sv.version = 1, sv.level = 1, sv.strat = 1, sv.seed = 12345;
+ ov = 0, hint.kind = 0, ucount = 0, err_until = 0;
+}
+
+/* every puzzle, every turn */
+static void check_puzzles(void) {
+ int sizes[12] = {0};
+ for (int p = 0; p < NPUZ; p++) {
+ int sp = -1;
+ for (int i = 0; i < NSPECIAL; i++)
+ if (lv_special[i][2] == p) sp = i;
+ int size = 0;
+ for (int q = 0; q < NPOOL; q++)
+ if (p >= pool_first(q) && p < pool_first(q) + lv_pool[q][4]) size = lv_pool[q][0];
+ for (int k = 0; k < NLK; k++)
+ if (p >= lv_lk[k][3] && p < lv_lk[k][3] + lv_lk[k][4]) size = lv_lk[k][0];
+ if (sp >= 0) size = lv_special[sp][1];
+ CHECK(size, "puzzle %d belongs to no pool", p);
+ sizes[size]++;
+ for (int t = 0; t < (sp >= 0 ? 1 : 8); t++) {
+ fresh();
+ sv.puz = (uint16_t)p, sv.size = (uint8_t)size, sv.t = (uint8_t)t, sv.special = sp >= 0;
+ sv.level = sp >= 0 ? lv_special[sp][0] : 1000;
+ load_puzzle();
+ int seen = 0, used = 0;
+ for (int i = 0; i < n * n; i++) seen |= 1 << reg[i];
+ CHECK(seen == (1 << n) - 1, "puzzle %d turn %d: colours missing", p, t);
+ CHECK(solve() == 1, "puzzle %d turn %d: %d solutions", p, t, nsol);
+ solve();
+ CHECK(valid(sol), "puzzle %d turn %d: the solution breaks the rules", p, t);
+ for (int i = 0; i < n; i++) {
+ CHECK(color[i] >= 0 && color[i] < 12 && !(used >> color[i] & 1), "puzzle %d: colour %d twice", p, color[i]);
+ used |= 1 << color[i];
+ }
+ }
+ }
+ printf("%d puzzles (%d bytes): ", NPUZ, (int)sizeof lv_data);
+ for (int s = 4; s <= 11; s++)
+ if (sizes[s]) printf("%dx%d %d ", s, s, sizes[s]);
+ printf("\n");
+}
+
+/* the hints alone, from an empty board (and from levels 1-10's prefilled cat), never wrong */
+static void check_hints(void) {
+ int used[10] = {0}, steps = 0, worst = 0;
+ for (int p = 0; p < NPUZ; p++) {
+ fresh();
+ int size = 0, sp = -1;
+ for (int q = 0; q < NPOOL; q++)
+ if (p >= pool_first(q) && p < pool_first(q) + lv_pool[q][4]) size = lv_pool[q][0];
+ for (int k = 0; k < NLK; k++)
+ if (p >= lv_lk[k][3] && p < lv_lk[k][3] + lv_lk[k][4]) size = lv_lk[k][0];
+ for (int i = 0; i < NSPECIAL; i++)
+ if (lv_special[i][2] == p) sp = i, size = lv_special[i][1];
+ sv.puz = (uint16_t)p, sv.size = (uint8_t)size, sv.t = (uint8_t)(p % 8), sv.special = sp >= 0;
+ if (sp >= 0) sv.t = 0;
+ sv.level = sp >= 0 ? lv_special[sp][0] : 1000;
+ start_level();
+ int k = 0;
+ for (; k < 400 && !ov; k++) {
+ clock_t h0 = clock();
+ find_hint();
+ int ms = (int)((clock() - h0) * 1000 / CLOCKS_PER_SEC);
+ worst = ms > worst ? ms : worst;
+ CHECK(hint.kind, "puzzle %d: no hint (%d cats)", p, cats());
+ if (!hint.kind) break;
+ used[hint.kind]++;
+ for (int i = 0; i < n * n; i++) {
+ bool cat_cell = sol[i / n] == i % n;
+ if (hint.hl[i] == 2 && hint.kind != H_UNMARK && hint.kind < H_ONE_ROW) CHECK(!cat_cell, "puzzle %d: hint %d X's a cat's cell", p, hint.kind);
+ if (hint.hl[i] == 2 && hint.kind >= H_COLOR_LINE) CHECK(!cat_cell, "puzzle %d: hint %d X's a cat's cell", p, hint.kind);
+ }
+ if (hint.kind >= H_ONE_ROW && hint.kind <= H_ONE_COLOR) CHECK(sol[hint.cell / n] == hint.cell % n, "puzzle %d: a cat in the wrong cell", p);
+ int lives = sv.lives;
+ apply_hint();
+ CHECK(sv.lives == lives, "puzzle %d: a hint cost a fish", p);
+ }
+ steps += k;
+ CHECK(ov == OV_WON, "puzzle %d: the hints don't finish it", p);
+ }
+ printf("hints: %d puzzles solved in %d steps (marks %d, X off %d, one place %d, colour in a line %d, line in a "
+ "colour %d, sets %d, no room %d); the slowest hint %d ms\n",
+ NPUZ, steps, used[H_MARKS], used[H_UNMARK], used[H_ONE_ROW] + used[H_ONE_COL] + used[H_ONE_COLOR], used[H_COLOR_LINE],
+ used[H_LINE_COLOR], used[H_SETS], used[H_CHAIN], worst);
+}
+
+/* the dealing: sizes, specials, hard levels, ranks, the pools' turns */
+static void check_dealing(void) {
+ for (int player = 0; player < 2; player++) {
+ fresh();
+ deal();
+ int hard_ok = 0, top = 0;
+ for (int lv = 1; lv <= 1000; lv++) {
+ CHECK(sv.level == lv, "level %d dealt as %d", lv, sv.level);
+ int sp = special_at(lv);
+ CHECK(sv.size == (sp >= 0 ? lv_special[sp][1] : size_at(lv)), "level %d: size %d", lv, sv.size);
+ CHECK(!!sv.special == (sp >= 0), "level %d: special", lv);
+ if (sp >= 0) CHECK(sv.puz == lv_special[sp][2], "level %d: not its special puzzle", lv);
+ if (sp < 0 && is_hard(lv)) {
+ int p = find_pool(sv.size, 5, lv >= 51);
+ hard_ok += p >= 0 && sv.puz >= pool_first(p) && sv.puz < pool_first(p) + lv_pool[p][4];
+ }
+ CHECK(sv.puz < NPUZ && sv.t < 8, "level %d: puzzle %d turn %d", lv, sv.puz, sv.t);
+ top = sv.strat > top ? sv.strat : top;
+ if (player) { /* fails once, then wins */
+ failed();
+ ov = 0;
+ }
+ won();
+ ov = 0;
+ }
+ int hard = 0;
+ for (int lv = 30; lv <= 1000; lv += 10) hard += special_at(lv) < 0;
+ CHECK(hard_ok == hard, "hard levels from the wrong pool (%d of %d)", hard_ok, hard);
+ printf("dealing, %s: 1000 levels, difficulty up to %d, now %d\n", player ? "a level failed each time" : "clean wins", top, sv.strat);
+ if (!player) CHECK(top == 6, "clean wins don't reach the top difficulty");
+ else CHECK(sv.strat <= 2, "failing doesn't bring the difficulty down");
+ }
+}
+
+/* the rules: a wrong cat, three of them, undo, locate */
+static void check_rules(void) {
+ fresh();
+ sv.level = 20 + 3, sv.size = (uint8_t)size_at(23);
+ deal();
+ start_level();
+ int wrong = sol[0] == 0 ? 1 : 0;
+ set_mark(5, MARK, 1);
+ CHECK(sv.cell[5] == MARK, "an X isn't put");
+ undo_move();
+ CHECK(sv.cell[5] == EMPTY, "undo doesn't take the X back");
+ place(wrong);
+ CHECK(sv.cell[wrong] == MARK && sv.lives == 2 && !sv.perfect, "a wrong cat isn't an X and a fish lost");
+ place(sol[0]);
+ CHECK(sv.cell[sol[0]] == CAT && sv.lives == 2, "the right cat isn't placed");
+ int lv = sv.level;
+ for (int r = 1; r < n && sv.lives; r++) {
+ int c = sol[r] ? 0 : 1;
+ if (sv.cell[r * n + c] == EMPTY) place(r * n + c);
+ }
+ CHECK(!sv.lives && ov == OV_FAILED && sv.retried && sv.level == lv, "three wrong cats don't fail the level");
+ ov = 0;
+ start_level();
+ CHECK(sv.lives == 3 && cats() == 0, "trying again doesn't start over");
+ for (int r = 0; r < n && !ov; r++) locate();
+ CHECK(ov == OV_WON && sv.level == lv + 1 && sv.dirty == 0, "locate doesn't finish the level");
+}
+
+/* the keys: arrows to a cell, then OK twice */
+static uint64_t ft;
+static int fr, fc;
+static void press(int key, int wait) { script[nscript].t = ft, script[nscript].hold = 60, script[nscript++].key = key, ft += (uint64_t)wait; }
+static void go(int r, int c) {
+ while (fr < r) press(eadk_key_down, 120), fr++;
+ while (fr > r) press(eadk_key_up, 120), fr--;
+ while (fc < c) press(eadk_key_right, 120), fc++;
+ while (fc > c) press(eadk_key_left, 120), fc--;
+}
+static void reset_save(void) {
+ static const uint8_t bad[4] = {0};
+ np_file_write(SAVE_NAME, bad, 4);
+}
+
+/* level 1 played with the keys from a new save: the guide, then each cat placed with OK twice */
+static void check_keys(void) {
+ reset_save();
+ fresh();
+ deal();
+ load_puzzle(); /* (the game will deal the same) */
+ int s[NMAX], size = n;
+ for (int r = 0; r < n; r++) s[r] = sol[r];
+ nscript = 0, ft = clock_ms + 300, fr = fc = size / 2;
+ press(eadk_key_ok, 400); /* the guide */
+ for (int r = 0; r < size; r++) {
+ go(r, s[r]);
+ press(eadk_key_ok, 150), press(eadk_key_ok, 300);
+ }
+ press(eadk_key_ok, 400); /* Next level */
+ press(eadk_key_home, 300);
+ meowdoku_main();
+ uint32_t len;
+ const uint8_t *d = np_file_read(SAVE_NAME, &len);
+ CHECK(d && len == sizeof sv, "no save");
+ if (d) memcpy(&sv, d, sizeof sv);
+ CHECK(sv.level == 2 && sv.wins == 1 && (sv.flags & 2) && sv.lives == 3, "level 1 isn't won with the keys (level %d)", sv.level);
+}
+
+/* bad saves start over; random keys never crash */
+static void check_fuzz(void) {
+ uint32_t r = 7;
+ for (int run = 0; run < 300; run++) {
+ uint8_t junk[sizeof sv];
+ r = r * 1103515245u + 12345u;
+ if (run % 3 == 0) { /* a save from a real game, altered */
+ fresh();
+ sv.level = (uint16_t)(1 + r % 600);
+ deal();
+ start_level();
+ memcpy(junk, &sv, sizeof sv);
+ junk[(r >> 8) % sizeof sv] ^= (uint8_t)(r >> 16);
+ } else
+ for (uint32_t i = 0; i < sizeof junk; i++) r = r * 1103515245u + 12345u, junk[i] = (uint8_t)(r >> 16);
+ np_file_write(SAVE_NAME, junk, run % 5 ? sizeof junk : 7);
+ static const int keys[] = {0, 1, 2, 3, 4, 4, 4, 5, 12, 13, 17, 52, 4, 1, 2};
+ nscript = 0, ft = clock_ms + 100;
+ for (int k = 0; k < 120; k++) {
+ r = r * 1103515245u + 12345u;
+ script[nscript].t = ft, script[nscript].hold = 30 + (int)(r >> 20) % 300;
+ script[nscript++].key = keys[(r >> 8) % (sizeof keys / sizeof *keys)];
+ ft += 20 + (r >> 12) % 200;
+ }
+ press(eadk_key_home, 100);
+ meowdoku_main();
+ uint32_t len;
+ const uint8_t *d = np_file_read(SAVE_NAME, &len);
+ CHECK(d && len == sizeof sv, "run %d: no save", run);
+ if (d) memcpy(&sv, d, sizeof sv);
+ CHECK(sane(), "run %d: a save it can't read back", run);
+ }
+ printf("300 runs of random keys on good and broken saves\n");
+}
+
+/* A film: the guide, level 1 won with the keys, then a level with a mistake, a hint and the menu. */
+static void film(void) {
+ reset_save();
+ fresh();
+ deal();
+ load_puzzle();
+ int s[NMAX], size = n;
+ for (int r = 0; r < n; r++) s[r] = sol[r];
+ nscript = 0, ft = 300, fr = fc = size / 2;
+ shots[nshots++] = 250; /* how to play */
+ press(eadk_key_ok, 1600);
+ for (int r = 0; r < size; r++) {
+ go(r, s[r]);
+ press(eadk_key_ok, 150), press(eadk_key_ok, 350);
+ }
+ shots[nshots++] = ft + 300; /* level cleared */
+ ft += 600;
+ press(eadk_key_ok, 900);
+ press(eadk_key_home, 300);
+ meowdoku_main();
+ printf("level 12 from frame %d\n", frame);
+ /* level 12 (10 x 10), part way */
+ fresh();
+ sv.level = 12, sv.strat = 2, sv.flags = 1;
+ deal();
+ start_level();
+ for (int r = 0; r < 4; r++) sv.cell[r * n + sol[r]] = CAT;
+ find_hint();
+ apply_hint();
+ sv.flags |= 2;
+ save();
+ nscript = 0, ft = clock_ms + 300, fr = fc = n / 2;
+ int wrong = 4 * n + (sol[4] + 3) % n;
+ go(4, wrong % n);
+ press(eadk_key_ok, 120), press(eadk_key_ok, 700);
+ go(6, 2);
+ press(eadk_key_ok, 300);
+ press(eadk_key_right, 150), press(eadk_key_right, 500);
+ shots[nshots++] = ft; /* the game */
+ press(eadk_key_shift, 1500);
+ shots[nshots++] = ft - 200; /* a hint */
+ press(eadk_key_ok, 900);
+ press(eadk_key_alpha, 1000);
+ go(8, 1);
+ press(eadk_key_ok, 150), press(eadk_key_ok, 700);
+ press(eadk_key_back, 1200);
+ shots[nshots++] = ft - 200; /* the menu */
+ press(eadk_key_back, 600);
+ press(eadk_key_home, 300);
+ meowdoku_main();
+}
+
+/* the time a frame takes to draw, on the host (the calculator's is measured with tools/emu.py) */
+static void check_speed(void) {
+ fresh();
+ sv.level = 16;
+ deal();
+ start_level();
+ layout();
+ gfx_buf = strip;
+ clock_t t0 = clock();
+ for (int i = 0; i < 50; i++) draw();
+ printf("a 10x10 frame: %.2f ms on this computer\n", (double)(clock() - t0) * 1000 / CLOCKS_PER_SEC / 50);
+}
+
+int main(int argc, char **argv) {
+ if (argc > 2 && !strcmp(argv[1], "film")) {
+ dir = argv[2];
+ film();
+ return 0;
+ }
+ check_puzzles();
+ check_hints();
+ check_dealing();
+ check_rules();
+ check_keys();
+ check_fuzz();
+ check_speed();
+ printf(fails ? "%d FAILED\n" : "all good\n", fails);
+ return fails != 0;
+}
diff --git a/games/meowdoku/tools/art.py b/games/meowdoku/tools/art.py
new file mode 100644
index 00000000..21925d4e
--- /dev/null
+++ b/games/meowdoku/tools/art.py
@@ -0,0 +1,70 @@
+#!/usr/bin/env python3
+"""Makes src/art.h: Meowdoku's own pictures, shrunk for the calculator: the cat on a found cell, the fish (lives,
+full and lost), the hint lamp, the Locate cat and the hard level's flame. They come from the game's Android package
+(its ASTC textures decoded to PNG, kept in ~/Documents/Assets/gamesrc/meowdoku/png, never in the repo).
+
+Each picture: up to 16 colours, each with its own opacity, 4 bits a pixel.
+
+Usage: art.py [png_dir] [src/art.h]
+"""
+import os
+import sys
+
+from PIL import Image
+
+PNG = sys.argv[1] if len(sys.argv) > 1 else os.path.expanduser("~/Documents/Assets/gamesrc/meowdoku/png")
+OUT = sys.argv[2] if len(sys.argv) > 2 else os.path.join(os.path.dirname(__file__), "..", "src", "art.h")
+ART = [ # name, file, width, height
+ ("cat", "atlas/cat_face.png", 44, 40),
+ ("fish", "fish_full.png", 20, 20),
+ ("fish_dim", "atlas/fish_dim.png", 20, 20),
+ ("lamp", "atlas/icon_hint_lamp.png", 22, 22),
+ ("locate", "atlas/tool_cat_item.png", 22, 22),
+ ("flame", "atlas/hard.png", 12, 16),
+]
+
+
+def pack(im):
+ """16 RGBA colours (premultiplied fit), the pixels as 4-bit indices."""
+ w, h = im.size
+ q = im.quantize(16, method=Image.Quantize.FASTOCTREE, dither=Image.Dither.NONE)
+ pal = q.getpalette("RGBA")[:64]
+ px = list(q.getdata())
+ # the true colour and opacity of each index: the mean of its pixels
+ sums = [[0, 0, 0, 0, 0] for _ in range(16)]
+ for i, p in zip(px, im.getdata()):
+ r, g, b, a = p
+ s = sums[i]
+ s[0] += r * a
+ s[1] += g * a
+ s[2] += b * a
+ s[3] += a
+ s[4] += 1
+ cols = []
+ for s in sums:
+ if s[4] == 0 or s[3] == 0:
+ cols.append((0, 0, 0, 0))
+ else:
+ cols.append((s[0] // s[3], s[1] // s[3], s[2] // s[3], s[3] // s[4]))
+ data = bytearray()
+ for y in range(h):
+ row = px[y * w:(y + 1) * w] + [0]
+ for x in range(0, w, 2):
+ data.append(row[x] << 4 | (row[x + 1] if x + 1 < w else 0))
+ return cols, bytes(data)
+
+
+with open(OUT, "w") as f:
+ f.write("/* Made by tools/art.py from Meowdoku's own pictures. */\n")
+ total = 0
+ for name, path, w, h in ART:
+ im = Image.open(os.path.join(PNG, path)).convert("RGBA")
+ im = im.resize((w, h), Image.LANCZOS)
+ cols, data = pack(im)
+ total += len(data) + 48
+ f.write("static const uint16_t %s_pal[16] = {%s};\n" % (name, ",".join(
+ "0x%04X" % ((r >> 3) << 11 | (g >> 2) << 5 | b >> 3) for r, g, b, a in cols)))
+ f.write("static const uint8_t %s_alpha[16] = {%s};\n" % (name, ",".join(str(a) for r, g, b, a in cols)))
+ f.write("static const uint8_t %s_px[%d] = {%s};\n" % (name, len(data), ",".join(str(b) for b in data)))
+ f.write("static const sprite_t spr_%s = {%d, %d, %s_pal, %s_alpha, %s_px};\n" % (name, w, h, name, name, name))
+print("art: %d bytes" % total)
diff --git a/games/meowdoku/tools/levels.py b/games/meowdoku/tools/levels.py
new file mode 100644
index 00000000..986cb0e6
--- /dev/null
+++ b/games/meowdoku/tools/levels.py
@@ -0,0 +1,344 @@
+#!/usr/bin/env python3
+"""Makes src/levels.h: Meowdoku's puzzles, taken from the game's own level banks, in the order the game deals them.
+
+The banks come from the Android package (com.oakever.meowdoku 1.23.0): its .bin banks, XOR-ed with the game's key
+and unpacked from Godot variants into JSON (kept in ~/Documents/Assets/gamesrc/meowdoku/lv, never in the repo).
+
+Meowdoku deals its puzzles from pools: one per board size and difficulty rank, each the game's regular bank
+followed by its LinkedIn-style bank (and its GC bank for 10 x 10 rank 1), minus puzzles with more than one
+one-cell region. On the main path (level 51 on) a LinkedIn-modified puzzle comes after every four others, and
+10 x 10 ranks 3 and 4 skip the regular bank. This keeps the first puzzles of each pool, as many as a player
+meets in the first 300 levels (24 at most); when a pool runs out the game turns and mirrors it (8 ways).
+
+Each puzzle is stored as its colour regions, cell by cell: 1 if the cell is in the region on its left, else 01 if
+in the one above, else 00 and the region's number in 4 bits (with no bit for a side the cell hasn't got). Solutions are found on the calculator (each puzzle has
+exactly one; the tests check it).
+
+Usage: levels.py [bank_dir] [src/levels.h]
+"""
+import json
+import os
+import sys
+from collections import Counter
+
+BANKS = sys.argv[1] if len(sys.argv) > 1 else os.path.expanduser("~/Documents/Assets/gamesrc/meowdoku/lv")
+OUT = sys.argv[2] if len(sys.argv) > 2 else os.path.join(os.path.dirname(__file__), "..", "src", "levels.h")
+
+SIZES_1_10 = [4, 5, 6, 6, 8, 6, 7, 8, 9, 7]
+SIZES_11 = [8, 10, 10, 9, 10, 10, 9, 10, 10, 10]
+SPECIAL = {10: ("sp", 44), 20: ("sp", 45), 30: ("sp", 36), 40: ("sp", 9), 50: ("sp", 37), 55: ("sp", 7),
+ 60: ("sp", 34), 62: ("sp", 8), 70: ("sp", 32), 75: ("sp", 6), 80: ("sp", 43), 90: ("sp", 33),
+ 100: ("sp", 5), 123: ("sp", 1), 200: ("lk", 30), 250: ("lk", 75), 314: ("lk", 141), 456: ("sp", 2)}
+LK_MOD_RESERVED = {20, 30, 53, 71, 72, 75, 114, 141, 164}
+PLAYED = 300 # levels a pool is sized for
+MOST = 24 # puzzles a pool keeps at most
+
+
+def load(name):
+ return json.load(open(os.path.join(BANKS, name + ".json")))
+
+
+def regions(e):
+ rm = e["regionMap"]
+ if rm and isinstance(rm[0], list):
+ rm = [v for row in rm for v in row]
+ return [int(v) for v in rm]
+
+
+def solution(e):
+ return [int(v) for v in e["solution"]]
+
+
+def size_of(e):
+ return int(e.get("size", 0)) or int(round(len(regions(e)) ** 0.5))
+
+
+def singles(e):
+ return sum(1 for v in Counter(regions(e)).values() if v == 1)
+
+
+# ------------------------------------------------------------------ the banks
+regular, lkstyle, gc = {}, {}, {}
+for sz in range(4, 13):
+ for kind, table in (("bankData%dx%d", regular), ("bankDataLKStyle%dx%d", lkstyle)):
+ try:
+ d = load(kind % (sz, sz))
+ except FileNotFoundError:
+ continue
+ for rk, levels in d.items():
+ if rk.isdigit():
+ table[sz, int(rk)] = levels
+ try:
+ for e in load("bankDataGC%dx%d" % (sz, sz))["levels"]:
+ gc.setdefault((sz, int(e.get("r", 0))), []).append(e)
+ except FileNotFoundError:
+ pass
+lk_mod_all = load("bankDataLKModified")["levels"]
+sp_all = load("bankDataSP")["levels"]
+lk_all = load("bankDataLK")
+
+
+def by_tier(levels, tier):
+ return [e for e in levels if e.get("tier", "") == tier] if tier else list(levels)
+
+
+def tier_for(sz, rank):
+ """TierFallbackModifier: N, or '' when neither the regular nor the LinkedIn-style bank has N puzzles."""
+ if by_tier(regular.get((sz, rank), []), "N") or by_tier(lkstyle.get((sz, rank), []), "N"):
+ return "N"
+ return ""
+
+
+def pool(sz, rank, main):
+ """LevelData.build_pools: the puzzles in dealing order, the filters applied (lk_mod apart)."""
+ tier = "N" if rank == 5 else tier_for(sz, rank)
+ reg = by_tier(regular.get((sz, rank), []), tier)
+ lks = by_tier(lkstyle.get((sz, rank), []), tier)
+ if tier and not reg and not lks:
+ reg, lks = regular.get((sz, rank), []), lkstyle.get((sz, rank), [])
+ if main and sz == 10 and rank in (3, 4):
+ reg = []
+ g = []
+ if (sz == 10 and rank == 1) or sz == 11:
+ g = by_tier(gc.get((sz, rank), []), tier) or gc.get((sz, rank), [])
+ out, seen = [], set()
+ for e in reg + lks + g:
+ if singles(e) > 1 or e.get("_pid_h") in seen:
+ continue
+ seen.add(e.get("_pid_h"))
+ out.append(e)
+ return out
+
+
+def lk_mod(sz, rank, strict):
+ out = []
+ for i, e in enumerate(lk_mod_all):
+ if i + 1 in LK_MOD_RESERVED or size_of(e) != sz:
+ continue
+ if int(e.get("r", 1) if strict else e.get("maxR", e.get("r", 1))) == rank:
+ out.append(e)
+ return out
+
+
+# ------------------------------------------------------------------ the dealer (as main.c deals)
+def size_at(lv):
+ return SIZES_1_10[lv - 1] if lv <= 10 else SIZES_11[(lv - 11) % 10]
+
+
+def is_hard(lv):
+ return lv >= 21 and lv % 10 == 0
+
+
+def max_strategy(lv):
+ return 6 if lv >= 201 else 5 if lv >= 101 else 4 if lv >= 51 else 3 if lv >= 21 else 2
+
+
+def simulate(player, levels, rnd):
+ """Pool use (the furthest index reached) for a player who wins (player 0), or fails once each level (1)."""
+ use, lk_use = Counter(), Counter()
+ cur, clean, fails, pend = 1, 0, 0, False
+ cursor = {}
+ for lv in range(1, levels + 1):
+ retried = False
+ if lv in SPECIAL:
+ pass
+ else:
+ sz = size_at(lv)
+ if is_hard(lv):
+ key = (sz, 5, lv >= 51, True)
+ else:
+ if lv >= 51 and cur < 2:
+ cur = 2
+ s = 1 if lv <= 5 else max(cur, 2) if lv >= 51 else cur
+ s = min(s, 4 if lv >= 51 else 3 if lv >= 21 else 2)
+ if s >= 3:
+ s = 2 + rnd() % (s - 1)
+ key = (sz, s, lv >= 51, False)
+ c = cursor.setdefault(key, [0, 0, 0]) # idx, since_lk, lk_idx
+ if key[2] and c[1] >= 4 and c[2] < len(lk_mod(key[0], key[1], key[3])):
+ c[2] += 1
+ c[1] = 0
+ lk_use[key[0], key[1], key[3]] = max(lk_use[key[0], key[1], key[3]], c[2])
+ else:
+ c[0] += 1
+ c[1] += 1
+ pk = (key[0], key[1], key[2] and key[0] == 10 and key[1] in (3, 4))
+ use[pk] = max(use[pk], c[0])
+ if player == 1 and lv >= 6:
+ retried = True
+ clean, fails = 0, fails + 1
+ if lv >= 6:
+ mx = max_strategy(lv)
+ mn = 2 if mx >= 5 else 1
+ demoted = False
+ if not retried:
+ clean += 1
+ if clean >= (1 if lv >= 51 else 2) and cur < mx:
+ cur, clean = cur + 1, 0
+ else:
+ clean = 0
+ if fails >= (2 if lv >= 21 else 1) and cur > mn:
+ cur, demoted = cur - 1, True
+ fails = 0
+ if pend and not demoted:
+ cur, pend, demoted = max(mn, cur - 1), False, True
+ if retried and not demoted:
+ nxt = lv + 1
+ if is_hard(nxt) or nxt in SPECIAL:
+ pend = True
+ else:
+ cur = max(mn, cur - 1)
+ return use, lk_use
+
+
+def rng(seed):
+ s = [seed]
+
+ def r():
+ s[0] ^= (s[0] << 13) & 0xFFFFFFFF
+ s[0] ^= s[0] >> 17
+ s[0] ^= (s[0] << 5) & 0xFFFFFFFF
+ return s[0]
+ return r
+
+
+need, lk_need = Counter(), Counter()
+for player in (0, 1):
+ for seed in (1, 7, 99, 12345):
+ u, l = simulate(player, PLAYED, rng(seed))
+ for k, v in u.items():
+ need[k] = max(need[k], v)
+ for k, v in l.items():
+ lk_need[k] = max(lk_need[k], v)
+
+
+# ------------------------------------------------------------------ checks
+def solve(n, rm, limit=2):
+ """Solutions of the region map, up to limit."""
+ sols, cols = [], [0] * n
+
+ def ok(r, c, placed):
+ for pr, pc in enumerate(placed):
+ if pc == c or rm[pr * n + pc] == rm[r * n + c] or (r - pr == 1 and abs(pc - c) <= 1):
+ return False
+ return True
+
+ def go(r, placed):
+ if len(sols) >= limit:
+ return
+ if r == n:
+ sols.append(list(placed))
+ return
+ for c in range(n):
+ if ok(r, c, placed):
+ placed.append(c)
+ go(r + 1, placed)
+ placed.pop()
+ go(0, [])
+ return sols
+
+
+def check(e, n):
+ rm = regions(e)
+ assert len(rm) == n * n and sorted(set(rm)) == list(range(n)), (n, e.get("id"))
+ s = solve(n, rm)
+ assert len(s) == 1, ("not unique", n, e.get("id"))
+ if "solution" in e:
+ assert s[0] == solution(e), ("solution differs", e.get("id"))
+
+
+# ------------------------------------------------------------------ packing
+class Bits:
+ def __init__(self):
+ self.out, self.acc, self.n = bytearray(), 0, 0
+
+ def put(self, v, k):
+ for i in range(k - 1, -1, -1):
+ self.acc = self.acc << 1 | (v >> i & 1)
+ self.n += 1
+ if self.n == 8:
+ self.out.append(self.acc)
+ self.acc = self.n = 0
+
+ def end(self):
+ if self.n:
+ self.put(0, 8 - self.n)
+ return bytes(self.out)
+
+
+def encode(e, n, cmap=None):
+ rm, b = regions(e), Bits()
+ for i, v in enumerate(rm):
+ r, c = divmod(i, n)
+ if c and rm[i - 1] == v:
+ b.put(1, 1)
+ continue
+ if c:
+ b.put(0, 1)
+ if r and rm[i - n] == v:
+ b.put(1, 1)
+ continue
+ if r:
+ b.put(0, 1)
+ b.put(v, 4)
+ for v in cmap or []:
+ b.put(v, 4)
+ return b.end()
+
+
+blob, offs = bytearray(), []
+
+
+def add(e, n, cmap=None):
+ check(e, n)
+ offs.append(len(blob))
+ blob.extend(encode(e, n, cmap))
+ return len(offs) - 1
+
+
+pools = [] # (size, rank, main_only, first, count)
+for (sz, rank, main_only), k in sorted(need.items()):
+ p = pool(sz, rank, main_only)
+ k = min(len(p), MOST, max(k, 4))
+ first = len(offs)
+ for e in p[:k]:
+ add(e, sz)
+ pools.append((sz, rank, int(main_only), first, k))
+lkpools = [] # (size, rank, strict, first, count)
+for (sz, rank, strict), k in sorted(lk_need.items()):
+ p = lk_mod(sz, rank, strict)[:k]
+ first = len(offs)
+ for e in p:
+ add(e, sz)
+ lkpools.append((sz, rank, int(strict), first, len(p)))
+specials = [] # (level, size, puzzle, has colour map)
+for lv, (src, idx) in sorted(SPECIAL.items()):
+ e = (sp_all if src == "sp" else lk_all)[idx - 1]
+ n = size_of(e)
+ cm = [int(v) for v in e.get("colorMap", [])] if src == "sp" else None
+ specials.append((lv, n, add(e, n, cm), int(bool(cm))))
+
+offs.append(len(blob))
+with open(OUT, "w") as f:
+ f.write("/* Made by tools/levels.py from Meowdoku's own level banks: %d puzzles, %d bytes. */\n"
+ % (len(offs) - 1, len(blob)))
+ f.write("static const uint8_t lv_data[%d] = {\n" % len(blob))
+ for i in range(0, len(blob), 24):
+ f.write(" " + ",".join(str(b) for b in blob[i:i + 24]) + ",\n")
+ f.write("};\nstatic const uint16_t lv_at[%d] = {" % len(offs))
+ f.write(",".join(str(o) for o in offs) + "};\n")
+ f.write("/* the pools: size, rank, main path only (10 x 10 ranks 3 and 4), first puzzle, count */\n")
+ f.write("static const uint8_t lv_pool[%d][5] = {%s};\n" % (len(pools), ",".join(
+ "{%d,%d,%d,%d,%d}" % (a, b, c, d & 255, e) for a, b, c, d, e in pools)))
+ f.write("static const uint8_t lv_pool_hi[%d] = {%s};\n" % (len(pools), ",".join(str(p[3] >> 8) for p in pools)))
+ f.write("/* LinkedIn-modified puzzles of the main path: size, rank, strict, first, count */\n")
+ f.write("static const uint16_t lv_lk[%d][5] = {%s};\n" % (len(lkpools), ",".join(
+ "{%d,%d,%d,%d,%d}" % p for p in lkpools)))
+ f.write("/* special levels: level, size, puzzle, its own colours */\n")
+ f.write("static const uint16_t lv_special[%d][4] = {%s};\n" % (len(specials), ",".join(
+ "{%d,%d,%d,%d}" % s for s in specials)))
+print("%d puzzles, %d bytes, %d pools, %d lk pools" % (len(offs) - 1, len(blob), len(pools), len(lkpools)))
+for p in pools:
+ print(" pool", p)
+for p in lkpools:
+ print(" lk", p)
diff --git a/games/meowdoku/tools/media.py b/games/meowdoku/tools/media.py
new file mode 100644
index 00000000..b271913e
--- /dev/null
+++ b/games/meowdoku/tools/media.py
@@ -0,0 +1,58 @@
+#!/usr/bin/env python3
+"""The pictures of the README and How to play, from the host build (make host; python3 tools/media.py):
+
+ docs/start.png, docs/shot.png, docs/hint.png how to play, a 10 x 10 level, a hint (shot.png is NumPlay's card too)
+ ../../docs/media/meowdoku.gif level 1 won with the keys, then level 12, for How to play
+ ../../docs/media/gallery/meowdoku.gif level 12: a wrong cat, X's, a hint, a cat found, for the README's gallery
+ ../../docs/media/thumb_meowdoku.png the README's table
+
+Python 3 with Pillow.
+"""
+import os
+import subprocess
+import tempfile
+
+from PIL import Image
+
+HERE = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
+PLAY = os.path.join(HERE, "build", "play")
+MEDIA = os.path.join(HERE, "..", "..", "docs", "media")
+
+
+def gif(path, frames):
+ """Each distinct screen, held as long as it was shown (40 ms steps), at most 2 s."""
+ out, times = [], []
+ for f in frames:
+ if out and f.tobytes() == out[-1].tobytes():
+ times[-1] += 40
+ else:
+ out.append(f)
+ times.append(40)
+ times = [min(t, 2000) for t in times]
+ sheet = Image.new("RGB", (320, 240 * len(out[::3])))
+ for i, f in enumerate(out[::3]):
+ sheet.paste(f, (0, 240 * i))
+ pal = sheet.quantize(96, method=Image.Quantize.MEDIANCUT, dither=Image.Dither.NONE)
+ q = [f.quantize(palette=pal, dither=Image.Dither.NONE) for f in out]
+ q[0].save(path, save_all=True, append_images=q[1:], duration=times, loop=0, optimize=True, disposal=1)
+ print(f"{path}: {len(q)} frames, {os.path.getsize(path)} bytes")
+
+
+def main():
+ with tempfile.TemporaryDirectory() as d:
+ out = subprocess.run([PLAY, "film", d], check=True, capture_output=True, text=True).stdout
+ level12 = int(out.split("from frame ")[1].split()[0])
+ for i, name in ((0, "start.png"), (2, "shot.png"), (3, "hint.png")):
+ Image.open(os.path.join(d, f"shot_{i}.ppm")).convert("RGB").save(os.path.join(HERE, "docs", name), optimize=True)
+ names = sorted(f for f in os.listdir(d) if f.startswith("f_"))
+ frames = [Image.open(os.path.join(d, f)).convert("RGB") for f in names]
+ gif(os.path.join(MEDIA, "meowdoku.gif"), frames)
+ gif(os.path.join(MEDIA, "gallery", "meowdoku.gif"), frames[level12:])
+ thumb = os.path.join(MEDIA, "thumb_meowdoku.png")
+ Image.open(os.path.join(HERE, "docs", "shot.png")).crop((0, 0, 320, 240)).resize((160, 120), Image.LANCZOS).save(
+ thumb, optimize=True)
+ subprocess.run(["python3", os.path.join(HERE, "..", "..", "tools", "media", "round_corners.py"), thumb], check=True)
+
+
+if __name__ == "__main__":
+ main()
diff --git a/tests/test_games.py b/tests/test_games.py
index 4aabcb01..d9c258e5 100644
--- a/tests/test_games.py
+++ b/tests/test_games.py
@@ -146,6 +146,10 @@ GAMES = {
# past how to play, the first level and a few steps; next time the second level, picked in the list
"sokoban": ("Sokoban.nwa", "sokoban.sav", presses((1500, "ok"), (2000, "ok"), (2600, "right"), (2900, "right")), 4000,
presses((1500, "right"), (1900, "ok"), (2500, "up")), 4000),
+ # past how to play, a hint on level 1 (the X's its cat rules out) done with OK; next time the game goes on: the
+ # winking cat finds one more cat
+ "meowdoku": ("Meowdoku.nwa", "meowdoku.sav", presses((1500, "ok"), (2000, "shift"), (2500, "ok")), 3500,
+ presses((1500, "alpha")), 2500),
# 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",
@@ -497,6 +501,9 @@ CHECKS = {
lambda v: v[5] == 3 and v[34] == 2),
# how to play seen and the first level played last; then the second
"sokoban": (lambda v: len(v) == 314 and v[:4] == b"S\1\1\0", lambda v: len(v) == 314 and v[:4] == b"S\1\1\1"),
+ # "M", version 1, the guide read, level 1 (at 4) in play: X's put by the hint (1s in the cells, at 26); then two cats
+ "meowdoku": (lambda v: len(v) == 212 and v[:2] == b"M\1" and v[2] == 3 and v[4] == 1 and v[26:147].count(1) >= 3,
+ lambda v: len(v) == 212 and v[2] == 3 and v[26:147].count(2) == 2),
# the bakery kept ("CCK1", the cookies at 8, the clicks at 48): 3 clicks; after the reinstall, from the copy, 5
"cookieclicker": (lambda v: v[:4] == b"CCK1" and struct.unpack_from("<d", v, 48)[0] == 3
and struct.unpack_from("<d", v, 8)[0] >= 3,
diff --git a/tools/release.py b/tools/release.py
index 128888eb..acba7bd3 100644
--- a/tools/release.py
+++ b/tools/release.py
@@ -41,6 +41,7 @@ ALONE = {
"leveldevil": ("Level Devil", "Unept's troll platformer, all sixteen worlds"),
"sonic": ("Sonic the Hedgehog", "the whole 1991 game, Green Hill to the Final Zone"),
"numvisuals": ("NumVisuals", "moving backgrounds with a clock, a stopwatch, a timer, a counter or your own words"),
+ "meowdoku": ("Meowdoku", "one cat per row, column and color, with the game's own puzzles, in its order"),
"cookieclicker": ("Cookie Clicker", "the whole game, to the grandmapocalypse, ascension and the dragon"),
"jetpackjoyride": ("Jetpack Joyride", "Barry's run through the lab, with five vehicles and the Final Spin"),
"stickmanhook": ("Stickman Hook", "swing from hook to hook: 39 levels made by hand, then endless ones"),