1. 项目简介 / Overview
YZF Sudoku 是一个面向高级数独技巧分析的 Web/WASM 工具。它支持题串导入、Coach 格式导入、图片本地识别、自动解题、所有步骤搜索、候选数编辑、技巧路径展示和高亮。
项目重点不是只给出答案,而是展示每一步逻辑推理过程,尤其适合研究 AIC、ALS、UR、Oddagon、Force Chain 等高级技巧。
YZF Sudoku is a Web/WASM Sudoku tool focused on advanced solving logic. It supports puzzle-string import, Sudoku Coach formats, local image OCR, auto solving, all-step search, candidate editing, explanation paths, and highlighting.
The goal is not only to produce the final answer, but to show the logical path behind each step, especially for advanced techniques such as AIC, ALS, UR, Oddagon, and Force Chain.
2. 启动方式 / How to Start
普通 Web 版
普通版通常通过本地或在线 HTTP 服务打开,例如开发时可以使用:
cd web-app python -m http.server 8000
然后访问 http://127.0.0.1:8000/index.html。
Standalone 版
Standalone 版设计目标是双击 HTML 文件即可使用,不需要本地服务器。图片识别所需模型和运行时应已被内联进单文件 HTML。
Regular Web Build
The regular build is usually opened through a local or hosted HTTP server. For development:
cd web-app python -m http.server 8000
Then open http://127.0.0.1:8000/index.html.
Standalone Build
The standalone build is intended to work by double-clicking the HTML file without starting a server. OCR models and runtime files should be bundled into the single HTML file.
localhost。如果图片识别提示缺少 .ort、.wasm 或 ort.min.js,说明打包流程没有正确内联 OCR 资源。3. 界面区域 / Interface Layout
- 盘面区:显示 9×9 棋盘、已知数、出数和候选数。
- 输入面板:用于输入题串、导入 Coach/Library 格式、图片识别。
- 技巧面板:选择技巧、搜索下一步、搜索所有步骤。
- 结果面板:显示删数、路径、解释、评分和状态信息。
- 导出区域:导出当前盘面、候选数和可分享题串。
- Board: shows the 9×9 grid, givens, solved digits, and candidates.
- Input panel: accepts puzzle strings, Coach/Library formats, and image OCR.
- Technique panel: selects techniques, finds the next step, or searches all steps.
- Result panel: displays eliminations, paths, explanations, ratings, and status messages.
- Export area: exports the current board, candidates, and shareable strings.
4. 题面输入 / Puzzle Input
项目支持多种导入格式:
- 81 字符题串:使用数字
1-9表示提示数,0或.表示空格。 - Library 冒号格式:例如
:0000:x:<board>:<eliminations>::,可保存候选删除信息。 - Sudoku Coach JSON:包含
givenDigits、userDigits、userCellCandidates等字段。 - SCv7_32 Coach 压缩串:前端会先解压成 Coach JSON,再导入。
普通导入会进行合法性和唯一解校验;图片识别导入则允许先作为草稿落盘,方便手动校正。
The project supports several import formats:
- 81-character string: digits
1-9are givens, while0or.means empty. - Library colon format: for example
:0000:x:<board>:<eliminations>::, preserving candidate eliminations. - Sudoku Coach JSON: includes fields such as
givenDigits,userDigits, anduserCellCandidates. - SCv7_32 Coach compressed string: decompressed by the frontend into Coach JSON before import.
Regular imports are checked for validity and uniqueness. OCR imports are allowed to land as editable drafts so the user can correct recognition mistakes.
Coach 候选数 mask / Coach Candidate Masks
userCellCandidates 是 81 个 mask,用 - 分隔。数字 d 对应 1 << d。例如候选 2,3,6 的 mask 是 4 + 8 + 64 = 76。
userCellCandidates contains 81 masks separated by -. Digit d corresponds to 1 << d. For candidates 2,3,6, the mask is 4 + 8 + 64 = 76.
5. 图片识别 / Image Recognition
图片识别在浏览器本地运行,不上传图片,不使用在线 fallback。识别完成后会直接导入为可编辑草稿盘面。
入口一般位于“题面输入 / 导出评分”面板:
- 选择图片识别:从本地文件或相册选择图片。
- 拍照识别:手机端调用相机拍摄图片。
- 从剪贴板识别:桌面端读取剪贴板截图。
- Ctrl+V:桌面端也可以直接粘贴截图。
Image recognition runs locally in the browser. Images are not uploaded and no online fallback is used. The recognized result is imported directly as an editable draft board.
The buttons are normally placed in the “Puzzle Input / Export & Rating” panel:
- Select Image: choose an image from files or photo library.
- Take Photo: open the camera on mobile devices.
- Read Clipboard: read a screenshot from the desktop clipboard.
- Ctrl+V: desktop users can paste screenshots directly.
识别结果如何解释 / How OCR Results Are Interpreted
- 黑色大数字:导入为提示数
givenDigits。 - 蓝色或其它颜色大数字:导入为出数
userDigits。 - 小候选数:导入为
userCellCandidates。 - 非唯一解:不会拒绝导入,而是作为草稿显示,方便校正。
OCR 导入后会用黑色提示数组成的题串做唯一解校验。如果校验失败,仍然允许用户在盘面上继续修正。
- Black large digits: imported as givens,
givenDigits. - Blue or other colored large digits: imported as solved/user digits,
userDigits. - Pencil marks: imported as
userCellCandidates. - Non-unique result: not rejected; it is shown as a draft so the user can correct it.
After OCR import, the black givens are checked for uniqueness. If the check fails, the draft still remains editable on the board.
The OCR feature uses a local model trained by Alex Kubiesa / Sudoku OCR. This project does not use the sudoku-ocr.com online fallback.
6. 盘面编辑 / Board Editing
点击格子后,可以输入数字或候选数。OCR 草稿状态下,修改会直接作用在前端草稿盘面,不会因为当前题面尚未唯一解而被 engine 拒绝。
- 输入大数字:设置该格出数。
- 切换候选:在空格中添加或移除候选数。
- 撤销/重做:回退或恢复最近的盘面操作。
- 校正完成后,可重新导入或开始搜索技巧。
After selecting a cell, you can enter a digit or toggle candidates. In OCR draft mode, edits are applied directly to the frontend draft board, so the engine will not reject the board simply because the givens are not yet unique.
- Enter a large digit: set the solved/user digit for the cell.
- Toggle candidates: add or remove pencil marks in an empty cell.
- Undo/Redo: revert or restore recent board operations.
- After correction, you may re-import or start technique search.
7. 自动解题 / Auto Solve
自动解题会从当前盘面开始,按启用技巧和优先级逐步搜索可用步骤,直到解完或找不到下一步。
- 自动解题:连续应用找到的逻辑步骤。
- 后台解题:耗时较长的搜索可能显示后台状态提示。
- 状态信息:会显示 solved、NoResult、Invalid 等结果。
如果自动解题找不到某个高级技巧,请确认该技巧在技巧面板中已启用,并且当前 wasm/standalone 是重新编译或重新生成后的版本。
Auto Solve starts from the current board and searches for logical steps according to the enabled techniques and priority order, until the puzzle is solved or no next step is found.
- Auto Solve: repeatedly applies available logical steps.
- Background solving: long searches may display background status messages.
- Status messages: show results such as solved, NoResult, or Invalid.
If an advanced technique is not found, make sure it is enabled in the technique panel and that the current wasm/standalone file has been rebuilt or regenerated.
8. 所有步骤 / All Steps
“所有步骤”会在当前盘面上收集多个可用步骤,便于比较不同技巧、不同删数和不同路径。
- 可按技巧类型过滤。
- 可查看删数、路径、解释和高亮。
- 对复杂链和 Force Chain,搜索时间可能明显增加。
“All Steps” collects multiple available steps from the current board, making it easier to compare different techniques, eliminations, and paths.
- Filter by technique type.
- Inspect eliminations, paths, explanations, and highlights.
- Complex chains and Force Chains may require noticeably more time.
9. 技巧与高亮 / Techniques and Highlights
项目支持从基础到高级的一系列技巧。高级链类技巧会显示路径、强弱关系、共同删数和特殊构型。
近期重点支持的高级内容包括:
- AIC / X-Chain / XY-Chain
- ALS / AHS / XZ 类技巧
- UR Guardian Force Chain
- Triplet Oddagon / Tridagon Guardian Force Chain
- MSLS、JE、Dynamic Chain 等高级迁移技巧
高亮通常包含:链路径、起点、终点、删数、结构格、guardian 候选等。
完整技巧说明:请打开 techniques.html。该页面按玩家阅读方式整理当前已实现技巧的逻辑含义、成立理由和高亮阅读方式。
The project supports a wide range of techniques from basic to advanced. Advanced chain techniques display paths, strong/weak links, common eliminations, and special patterns.
Full technique guide: open techniques.html for player-facing explanations of implemented techniques, conclusions, and highlight reading tips.
Recently supported advanced areas include:
- AIC / X-Chain / XY-Chain
- ALS / AHS / XZ-style techniques
- UR Guardian Force Chain
- Triplet Oddagon / Tridagon Guardian Force Chain
- MSLS, JE, Dynamic Chain, and other migrated advanced techniques
Highlights usually include chain paths, starts, ends, eliminations, structure cells, and guardian candidates.
Guardian Force Chain 说明 / Guardian Force Chain
Guardian Force Chain 的通用逻辑是:某个 dead pattern 的所有 guardian 不可能同时为假,因此至少一个 guardian 为真。如果每个 guardian 为真都推出同一个删数,则该删数成立。
UR Guardian FC 和 Triplet Oddagon Guardian FC 的搜索逻辑相同,区别只在 dead pattern 构型不同。
The general logic of Guardian Force Chain is: not all guardians of a dead pattern can be false, so at least one guardian must be true. If every true guardian leads to the same elimination, that elimination is valid.
UR Guardian FC and Triplet Oddagon Guardian FC share the same search logic; only the dead-pattern structure differs.
10. 内置超难题库 / Built-in Superhard Bank
项目支持内置超难题库。点击生成超难题时,会从压缩内置题库随机抽取一题,解压并导入当前盘面。
当前轻量方案使用压缩 bank,题库数据段比直接 81 字符文本更小。题库生成工具可以把题串批量打包为 C++ 数据段。
- 常规题串:约 81 字节/题。
- Puzzle19 raw:约 19 字节/题。
- 压缩 bank:实测约 14.4 字节/题,取决于题库内容。
The project supports a built-in superhard puzzle bank. When generating a superhard puzzle, one entry is randomly selected from the compressed bank, decoded, and imported into the current board.
The lightweight design uses a compressed bank, much smaller than storing raw 81-character strings. The packing tool can convert a list of puzzles into a C++ data segment.
- Raw puzzle strings: about 81 bytes per puzzle.
- Puzzle19 raw: about 19 bytes per puzzle.
- Compressed bank: observed around 14.4 bytes per puzzle, depending on the bank.
11. 导出与分享 / Export and Sharing
你可以导出当前盘面用于分享、复现或调试。常见导出内容包括:
- 普通 81 字符题串。
- Library 冒号格式,包含候选删除信息。
- Coach JSON 或 SCv7_32 压缩串。
- 当前评分、步骤路径和高亮信息。
OCR 导入后如果需要保存校正后的盘面,建议先在盘面上校正,再使用现有导出功能。
You can export the current board for sharing, reproduction, or debugging. Common export contents include:
- Plain 81-character puzzle string.
- Library colon format with candidate eliminations.
- Coach JSON or SCv7_32 compressed string.
- Current rating, step paths, and highlight information.
After OCR import, correct the board first, then use the existing export feature to save the corrected position.
12. 手机端使用 / Mobile Use
- 手机没有 Ctrl + V 快捷键,因此应使用“选择图片识别”或“拍照识别”。
- 如果 Chrome 无法调用相机,先检查 Chrome 的相机权限是否被禁用。
- 某些浏览器会把“拍照识别”显示为“拍照/相册”选择,这是浏览器行为,不一定是项目问题。
- 识别后可直接在盘面上修改大数字和候选数。
Chrome Android 刷新缓存
手机端没有完全等同于电脑 Ctrl + F5 的快捷键。开发测试时建议使用版本号参数,或在 Chrome 设置中清除该站点缓存。
- Mobile devices do not have a Ctrl + V shortcut, so use “Select Image” or “Take Photo”.
- If Chrome cannot open the camera, check whether camera permission is disabled in Chrome settings.
- Some browsers show a “camera/gallery” chooser instead of opening the camera directly. This is browser behavior, not necessarily a project bug.
- After recognition, edit large digits and candidates directly on the board.
Refreshing Chrome on Android
There is no exact mobile equivalent of desktop Ctrl + F5. During development, use versioned URLs or clear the site cache in Chrome settings.
13. Standalone 版本 / Standalone Version
Standalone 版的目标是离线使用,不需要本地服务器。为了支持图片识别,构建脚本需要把 OCR JS、ORT runtime、WASM 和模型文件内联或打包进单文件 HTML。
如果普通 Web 版能识别但 standalone 失败,优先检查:
ort.min.js是否被正确内联。.wasmruntime 是否可用。puzzle_localizer.ort与puzzle_classifier.ort是否被打包。- OCR 模块是否还在使用动态
import()或fetch()本地文件。
The standalone build is meant for offline use without a local server. To support image recognition, the build script must inline or bundle the OCR JS, ORT runtime, WASM, and model files into the single HTML file.
If OCR works in the regular Web build but fails in standalone, check:
- whether
ort.min.jsis correctly bundled. - whether the
.wasmruntime is available. - whether
puzzle_localizer.ortandpuzzle_classifier.ortare bundled. - whether the OCR module still uses dynamic
import()orfetch()for local files.
14. 常见问题 / Troubleshooting
| 问题 / Issue | 原因 / Cause | 处理 / Fix |
|---|---|---|
图片识别提示 no available backend found |
ONNX Runtime Web 的 wasm/mjs 路径错误,或 standalone 没有正确内联 runtime。 | 普通版检查 web-app/ocr/ort/;standalone 重新生成单文件 HTML。 |
| OCR 结果能显示但候选数很差 | 模型输出后处理没有按参考逻辑解析。 | 应按 modelOutputs(pp) < 0 判断候选格,并用 modelOutputs(v*81+pp) > 0 判断候选。 |
| 识别的大数字变成出数,UR 类技巧失效 | 没有按颜色区分提示数与出数。 | 黑色大数字应作为 given;非黑色大数字作为 user digit。 |
| 导入非唯一解被拒绝,无法校正 OCR | OCR 走了普通题串严格导入路径。 | OCR 应导入为草稿盘面,非唯一只提示,不拒绝。 |
| 技巧找不到,但 native 测试能找到 | 可能是前端 wasm 没刷新,或 Manual/FindAll/Auto Solve 调用路径不一致。 | 重新编译 wasm,清缓存;技巧逻辑应归一化到统一搜索入口。 |
| 手机端无法拍照 | 浏览器权限被禁用,或浏览器不直接支持 capture 行为。 |
开启浏览器相机权限;或先用系统相机拍照,再用“选择图片识别”。 |
| 普通版盘面变黑或不显示 | OCR 模块在页面启动时同步加载失败,导致主 app 初始化中断。 | OCR 应懒加载;OCR 加载失败不能影响普通棋盘启动。 |
15. 模型与来源声明 / Credits
数独图片识别功能使用本地模型,模型来源于 Alex Kubiesa / Sudoku OCR 训练的识别模型。项目只在浏览器本地进行识别,不上传图片,也不使用在线 fallback。
建议在应用的 About、帮助页或图片识别区域保留声明:
数独图片识别功能使用由 Alex Kubiesa / Sudoku OCR 训练的本地识别模型。本项目不使用在线 fallback。
The Sudoku image recognition feature uses a local model trained by Alex Kubiesa / Sudoku OCR. Recognition is performed locally in the browser. Images are not uploaded and no online fallback is used.
Recommended attribution text for About, Help, or the OCR panel:
Sudoku image recognition uses a local model trained by Alex Kubiesa / Sudoku OCR. No online fallback is used.