1.2.2 • Published 2 months ago

@forfuns/sudoku v1.2.2

Weekly downloads
1
License
Apache-2.0
Repository
github
Last release
2 months ago

@forfuns/sudoku

关于 about

codebeat badge npm version License License Page Views Count

一款基于javascript / nodejs 开源的数独 计算器生成器 依赖库

opensource sudoku solver and generator with javascript/nodejs library

功能 features

  • 完整数独解题器 - complete Sudoku solver
  • 题目生成功能 - random one-solution generator with five level

安装 install

npm i @forfuns/sudoku

使用 tutorial

Solver & Generator

// Solver
// 9 * 9 矩阵数独题目,-1值为待输入值
// 9 * 9 matrix for the puzzle , -1 mean input position
let puzzle = [
    -1,-1,8,    9,-1,6,     -1,-1,5,
    -1,4,3,     -1,-1,-1,   -1,2,-1,
    -1,-1,-1,   -1,-1,-1,   -1,-1,-1,

    -1,-1,4,    -1,-1,-1,   9,-1,-1,
    5,-1,-1,    -1,4,-1,    6,8,-1,
    -1,-1,-1,   1,-1,-1,    -1,-1,-1,

    2,-1,-1,    -1,8,-1,    -1,7,-1,
    -1,-1,-1,   -1,3,4,     1,-1,-1,
    -1,6,-1,    -1,-1,9,    -1,-1,-1,
]
const { Sudoku , generator } = require('@forfuns/sudoku')

let sudoku 
// 数独解题(不区分是否唯一数独,回溯出结果直接返回)
// solve sudoku with puzzle
sudoku = new Sudoku(puzzle)

// 数独解题 只能计算唯一解的数独,如果该puzzle拥有多解,则抛出错误Error('puzzle is not one-solution sudoku')
// 一般来说,只是单纯解题,使用上面的构造器即可,速度最快
// if you need to sure puzzle is one solution or not , you can use strict=true (default is false), that will take longer
// if puzzle is not one solution sudoku , will throw Error('puzzle is not one-solution sudoku')
sudoku = new Sudoku(puzzle, true) 

// 获取原题目
// get sudoku puzzle
sudoku.getPuzzle()

// 获取完整答案
// get sudoku solution
sudoku.getSolution()

// 查看debug信息
// show debug infomation
sudoku.debug()

-----------------------------------------------------------------------------
// Generator
// 数独题目生成
// make puzzle with generate function , four level 0:easy / 1:medium / 2:hard / 3:expert / 4:hell(that may take long times)
puzzle = generator(0) // level 可选 0 ~ 4 分别代表:简单 / 中等 / 困难 / 专家 / "地狱"

相关测试用例,请查看 /test/sudoku/*.js

npm run test-solver
npm run test-generator

with any idea welcome open issue to make me know

if you want same project with other language like go / dart and flutter app , here they are :

1.2.2

2 months ago

1.2.0

11 months ago

1.2.1

10 months ago

1.1.11

11 months ago

1.1.1

1 year ago

1.1.0

1 year ago

1.1.9

1 year ago

1.1.8

1 year ago

1.0.9

1 year ago

1.1.7

1 year ago

1.0.8

1 year ago

1.1.6

1 year ago

1.1.5

1 year ago

1.1.4

1 year ago

1.1.3

1 year ago

1.1.2

1 year ago

1.1.10

1 year ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago