Skip to content

Commit 2c1d8ef

Browse files
committed
Add readme field to sodo-wasm package metadata, reorder edition field in sodo, and bump sodo-wasm to 0.2.1
1 parent 8391601 commit 2c1d8ef

4 files changed

Lines changed: 103 additions & 3 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sodo-wasm/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
[package]
22
name = "sodo-wasm"
3-
version = "0.2.0"
3+
version = "0.2.1"
44
edition = "2024"
55
authors = ["ΣX <gitctrlx@gmail.com>"]
66
license = "MIT"
77
description = "WebAssembly bindings for sodo Sudoku library"
8+
readme = "../README.md"
89
homepage = "https://github.com/pyroth/sodo"
910
repository = "https://github.com/pyroth/sodo"
1011

sodo-wasm/example.ts

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/**
2+
* sodo-wasm usage example with Bun
3+
* Run: bun run example.ts
4+
*/
5+
6+
import init, {
7+
Difficulty,
8+
generateSudoku,
9+
solveGrid,
10+
validateSolution,
11+
validateGrid,
12+
isSolvable,
13+
getHint,
14+
formatGrid,
15+
createEmptyGrid,
16+
cloneGrid,
17+
gridToJson,
18+
jsonToGrid,
19+
parseGrid,
20+
stringifyGrid,
21+
// String API
22+
generate,
23+
solve,
24+
validate,
25+
hint,
26+
format,
27+
} from "./pkg/sodo_wasm.js";
28+
29+
// Initialize WASM module
30+
await init();
31+
32+
console.log("=== sodo-wasm Example ===\n");
33+
34+
// 1. Generate a puzzle with Grid API
35+
console.log("1. Generating puzzle (Medium difficulty)...");
36+
const { puzzle, solution } = generateSudoku(Difficulty.Medium);
37+
console.log("Puzzle:");
38+
console.log(formatGrid(puzzle));
39+
console.log("Solution:");
40+
console.log(formatGrid(solution));
41+
42+
// 2. Validate the solution
43+
console.log("2. Validating solution...");
44+
const isValid = validateSolution(puzzle, solution);
45+
console.log(`Solution valid: ${isValid}\n`);
46+
47+
// 3. Get a hint
48+
console.log("3. Getting hint for puzzle...");
49+
const hintResult = getHint(puzzle);
50+
if (hintResult) {
51+
console.log(`Hint: Place ${hintResult.value} at row ${hintResult.row}, col ${hintResult.col}\n`);
52+
} else {
53+
console.log("No hint available\n");
54+
}
55+
56+
// 4. Check if puzzle is solvable
57+
console.log("4. Checking if puzzle is solvable...");
58+
console.log(`Is solvable: ${isSolvable(puzzle)}\n`);
59+
60+
// 5. Grid utilities
61+
console.log("5. Grid utilities demo...");
62+
const emptyGrid = createEmptyGrid();
63+
console.log(`Empty grid created: ${emptyGrid[0][0] === 0 ? "✓" : "✗"}`);
64+
65+
const cloned = cloneGrid(puzzle);
66+
console.log(`Grid cloned: ${cloned[0][0] === puzzle[0][0] ? "✓" : "✗"}`);
67+
68+
// 6. JSON conversion
69+
console.log("\n6. JSON conversion...");
70+
const json = gridToJson(puzzle);
71+
console.log(`Grid to JSON (first 50 chars): ${json.slice(0, 50)}...`);
72+
73+
const fromJson = jsonToGrid(json);
74+
console.log(`JSON to Grid: ${fromJson ? "✓" : "✗"}`);
75+
76+
// 7. String conversion
77+
console.log("\n7. String conversion...");
78+
const compactStr = stringifyGrid(puzzle);
79+
console.log(`Compact string: ${compactStr}`);
80+
81+
const fromStr = parseGrid(compactStr);
82+
console.log(`Parse string: ${fromStr ? "✓" : "✗"}`);
83+
84+
// 8. String API (legacy)
85+
console.log("\n8. String API demo...");
86+
const puzzleStr = generate("hard");
87+
console.log(`Generated (hard): ${puzzleStr}`);
88+
89+
const solutionStr = solve(puzzleStr);
90+
console.log(`Solved: ${solutionStr}`);
91+
92+
console.log(`Valid: ${validate(puzzleStr)}`);
93+
94+
const hintStr = hint(puzzleStr);
95+
if (hintStr) {
96+
console.log(`Hint: row=${hintStr.row}, col=${hintStr.col}, value=${hintStr.value}`);
97+
}
98+
99+
console.log("\n=== Done ===");

sodo/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
[package]
22
name = "sodo"
33
version = "0.2.6"
4+
edition = "2024"
45
description = "Sudoku in Rust"
56
license = "MIT OR Apache-2.0"
67
readme = "../README.md"
7-
edition = "2024"
88
homepage = "https://github.com/pyroth/sodo"
99
repository = "https://github.com/pyroth/sodo"
1010

0 commit comments

Comments
 (0)