Modern Apps git

← Modern-Apps.git

chess: rename assets to avoid scanner

Commit
fbe2dc781199d6529b3fcbb01a2166607b929d4d
Author
Vayun Mathur <[email protected]>
When
2026-07-20 22:11 UTC (4 months ago)
Parents
f596f11

Diff

games/chess/src/main/assets/puzzles.dat
diff --git a/games/chess/src/main/assets/puzzles.bin b/games/chess/src/main/assets/puzzles.datsimilarity index 100%rename from games/chess/src/main/assets/puzzles.binrename to games/chess/src/main/assets/puzzles.dat
games/chess/src/main/java/com/vayunmathur/games/chess/data/Puzzle.kt
diff --git a/games/chess/src/main/java/com/vayunmathur/games/chess/data/Puzzle.kt b/games/chess/src/main/java/com/vayunmathur/games/chess/data/Puzzle.ktindex 3091326eaa..42cf460297 100644--- a/games/chess/src/main/java/com/vayunmathur/games/chess/data/Puzzle.kt+++ b/games/chess/src/main/java/com/vayunmathur/games/chess/data/Puzzle.kt@@ -16,7 +16,7 @@ data class PuzzleMove(val from: Position, val to: Position, val promotion: Piece data class Puzzle(val rating: Int, val board: Board, val solution: List<PuzzleMove>)  /**- * Loads and decodes the bundled `puzzles.bin` asset produced by+ * Loads and decodes the bundled `puzzles.dat` asset produced by  * `scripts/chess/generate_puzzles.py`. The blob is read once into memory; a  * lightweight index (record offsets + ratings) is built so puzzles can be picked  * by difficulty and decoded one at a time, without materializing ~50k Boards.@@ -26,7 +26,7 @@ data class Puzzle(val rating: Int, val board: Board, val solution: List<PuzzleMo  *   32B board nibbles, 1B flags, 1B enPassant, 2B rating, 1B moveCount, 2B*M moves.  */ object PuzzleRepository {-    private const val ASSET_NAME = "puzzles.bin"+    private const val ASSET_NAME = "puzzles.dat"     private const val HEADER_SIZE = 8     private const val EP_NONE = 0xFF @@ -42,11 +42,11 @@ object PuzzleRepository {         if (data != null) return          val bytes = context.assets.open(ASSET_NAME).use { it.readBytes() }-        require(bytes.size >= HEADER_SIZE) { "puzzles.bin too small" }+        require(bytes.size >= HEADER_SIZE) { "puzzles.dat too small" }         require(             bytes[0] == 'C'.code.toByte() && bytes[1] == 'P'.code.toByte() &&                 bytes[2] == 'Z'.code.toByte() && bytes[3] == '1'.code.toByte()-        ) { "puzzles.bin: bad magic" }+        ) { "puzzles.dat: bad magic" }          val bb = ByteBuffer.wrap(bytes).order(ByteOrder.LITTLE_ENDIAN)         val n = bb.getInt(4)
games/chess/src/test/java/com/vayunmathur/games/chess/data/PuzzleFormatTest.kt
diff --git a/games/chess/src/test/java/com/vayunmathur/games/chess/data/PuzzleFormatTest.kt b/games/chess/src/test/java/com/vayunmathur/games/chess/data/PuzzleFormatTest.ktindex 6b06075eaa..ece4413f87 100644--- a/games/chess/src/test/java/com/vayunmathur/games/chess/data/PuzzleFormatTest.kt+++ b/games/chess/src/test/java/com/vayunmathur/games/chess/data/PuzzleFormatTest.kt@@ -7,7 +7,7 @@ import java.nio.ByteBuffer import java.nio.ByteOrder  /**- * Verifies the `puzzles.bin` binary format round-trips: a record encoded exactly+ * Verifies the `puzzles.dat` binary format round-trips: a record encoded exactly  * as `scripts/chess/generate_puzzles.py` writes it decodes back to the same  * position (board + solution). Also covers [Board.fromFen] reconstruction of  * castling rights and en-passant, which the decoder relies on.
scripts/chess/generate_puzzles.py
diff --git a/scripts/chess/generate_puzzles.py b/scripts/chess/generate_puzzles.pyindex 9621c1f486..1543c036d7 100644--- a/scripts/chess/generate_puzzles.py+++ b/scripts/chess/generate_puzzles.py@@ -1,5 +1,5 @@ #!/usr/bin/env python3-"""Generate the compact `puzzles.bin` asset for the Chess app's Puzzles mode.+"""Generate the compact `puzzles.dat` asset for the Chess app's Puzzles mode.  Source: the Lichess puzzle database CSV (`lichess_db_puzzle.csv.zst`, ~6M rows), whose columns are:@@ -15,7 +15,7 @@ keep the top `ceil(TARGET / 12)` rows by Popularity, so difficulty is balanced. All bands 400..2799 are densely populated in the source (each has 130k-880k rows), so no redistribution is needed; any short band simply contributes fewer. -Binary format (`puzzles.bin`, little-endian) — kept in sync with the Kotlin+Binary format (`puzzles.dat`, little-endian) — kept in sync with the Kotlin loader in `PuzzleRepository` / `Board.fromPuzzle`:      Header:@@ -38,7 +38,7 @@ Usage:     python3 generate_puzzles.py [input.csv.zst] [output.bin]  Defaults: input ~/Documents/lichess_db_puzzle.csv.zst, output-Modern-Apps/games/chess/src/main/assets/puzzles.bin (both overridable via argv).+Modern-Apps/games/chess/src/main/assets/puzzles.dat (both overridable via argv). """ from __future__ import annotations @@ -54,7 +54,7 @@ import sys REPO_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..")) DEFAULT_INPUT = os.path.expanduser("~/Documents/lichess_db_puzzle.csv.zst") DEFAULT_OUTPUT = os.path.join(-    REPO_ROOT, "games", "chess", "src", "main", "assets", "puzzles.bin"+    REPO_ROOT, "games", "chess", "src", "main", "assets", "puzzles.dat" )  MAGIC = b"CPZ1"