Being stuck home for the past month due to Covid-19 has not only given me drive to learn new things, but has also driven me to the walls with boredom.

After all, what’s the use of learning something new if you don’t apply it?

And thus, sudoku_api was born.

sudoku_api is a pure dart package which simplifies the generation, interaction, and management of Sudoku Puzzles.

Well, how does it do that?

  • Contains a Built-in solver for generating new puzzles, or solving existing ones
  • Utilizes and exposes event streams for grid interactions (e.g. cell value changed), and puzzle states
  • Exposes a bunch of neat, easy to use models manipulating Cells, Positions, Grids, and even Patterns of a Sudoku puzzle

Whoah that sounds pretty cool – but what’s this ‘sue dough que’ you keep talking about?

Sudoku is a logic-based, combinatorial number-placement puzzle. The objective is to fill a 9×9 grid with digits so that each column, each row, and each of the nine 3×3 subgrids (segments) that compose the grid contain all of the digits from 1 to 9. The puzzle setter provides a partially completed grid, which for a well-posed puzzle has a single solution.

Wikipedia

Let’s see some sample code

import 'package:sudoku_api/Puzzle.dart';

void main() {
  
  PuzzleOptions puzzleOptions = new PuzzleOptions(patternName: "winter");
  
  Puzzle puzzle = new Puzzle(puzzleOptions);
  
    puzzle.generate().then((_) {
      print("=====================================");
      print("Your puzzle, fresh off the press:");
      print("-------------------------------------");
      printGrid(puzzle.board());
      print("=====================================");
      print("Give up? Here's your puzzle solution:");
      print("-------------------------------------");
      printGrid(puzzle.solvedBoard());
      print("=====================================");
    });
}

Inspiration

I’ve mentioned a few years ago that one of the first games I completed, 100%, was Brain Age Sudoku on the DSi. I really loved the simplicity and clean, non-bloated interface.

Flash forward a few years, and I still haven’t found an app that gives me the same feel.

My goal is to develop a highly customizable, clean, and easy to use Sudoku Toolkit in Flutter using this API – and perhaps encourage others to do the same.

A solid chunk of logic was re-used (namely, solving) from a previous project in college; Java Sudoku. The rest was an experiment in developing a dart package for the first time.

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.