einsitang / sudoku-dart

sudoku library with dart
BSD 3-Clause "New" or "Revised" License
16 stars 8 forks source link
sudoku sudoku-dart sudoku-generator sudoku-solver

sudoku-dart

关于 about

License License pub package

数独 解题器生成器 开源库 dart

支持对 唯一/非唯一解数独进行解题 以及 随机唯一解数独生成

open-source sudoku solver and puzzle generator library with dart

安装 install

only-dart

Depend on it

Run this command:

With Dart:

dart pub add sudoku_dart

with-flutter :

flutter pub add sudoku_dart

This will add a line like this to your package's pubspec.yaml (and run an implicit dart pub get):

dependencies:
  sudoku_dart: ^1.2.0

Import it

import 'package:sudoku_dart/sudoku_dart.dart';

使用 tutorial

解题 solver

import 'package:sudoku_dart/sudoku_dart.dart';
// 支持数独解题
// 输入一维数组的puzzle,-1为待填空
 List<int> 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,
  ];

sudoku = Sudoku(puzzle);

// if you need check this puzzle is one-solution sudoku or not,use  strict:true 
// sudoku = Sudoku(puzzle, strict: true);

// debug print
sudoku.debug();
// origin puzzle
sudoku.puzzle;
// sudoku solution
sudoku.solution;

数独生成器 generator

import 'package:sudoku_dart/sudoku_dart.dart';
// generate random puzzle with one-solution
// Level : easy(简单), medium(中等), hard(困难), expert(专家)
Sudoku sudoku = Sudoku.generate(Level.expert);

more

this library use on sudoku-flutter , support for android and iOS app , if interesting welcome visit this repository :

einsitang/sudoku-flutter