sdkconverter

package
v0.0.0-...-6987203 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 10, 2022 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package sdkconverter provides a set of converters to and from sudoku's default sdk format.

It supports three file types: 'sdk', 'doku', and 'komo'. To help ensure you're using a supported format, pass FooFormat instead of the direct string.

Index

Constants

This section is empty.

Variables

Converters is a list of the provided converters for direct access. It's better to use one of the convenience methods unless you need raw access.

Functions

func DataString

func DataString(format Format, grid sudoku.Grid) string

DataString is a convenience method that returns the given grid's string representation in the given format. If the converter does not exist, it will return a zero-length string.

func Load

func Load(puzzle string) sudoku.MutableGrid

Load returns a new grid that is loaded up from the provided puzzle string. The format is guessed from the input string. If no valid format is guessed, an empty (non-nil) grid is returned.

func LoadInto

func LoadInto(grid sudoku.MutableGrid, puzzle string)

LoadInto loads the given puzzle state into the given grid. The format of the puzzle string is guessed. If no valid format can be detected, the grid won't be modified.

func ToOther

func ToOther(format Format, sdk string) (other string)

ToOther is a conenience wrapper that takes the name of a format and the sdk datastring and returns the DataString in the other format.

func ToSDK

func ToSDK(format Format, other string) (sdk string)

ToSDK is a convenience wrapper that takes the name of a format and the puzzle data and returns an sdk string.

Types

type Format

type Format string

Format is a type of puzzle format this package understands. For safety, use the FooFormat constants instead of strings.

const DokuFormat Format = "doku"

The doku format's rows are delimited by line breaks and columns are delimited by "|". Each cell consists of (in order):

* Either a space, period, or number 0-9, denoting the number that is currently filled in the space.

* An optional "!" if the cell's number is locked

* An optional list of 1 or more marks, contained in "(" and ")" and separated by ","

* 0 or more spaces or tabs (useful for lining up the file's columns for clarity)

If there are no locked cells, marks, or extra whitespace in any cells, then either only the column delimiters OR both the column and row delimiters may be omitted. Thus, every valid SDK file is a valid doku file. Doku is the recommended format for any uses that include user modifications of the cell.

const KomoFormat Format = "komo"

komo is a legacy format that is used in certain online sudoku games. Like doku it can store user modifications to the grid. Unlike all of the other formats, it requires that each cell store the solution number for that cell, meaning it is unable to store grids that have no valid solution.

const SDKFormat Format = "sdk"

SDK is the default file format of the main library, and many other sudoku tools. Rows are delimited by new lines, and columns are delimited by a single pipe character ('|'). Optionally the column delimiter may be replaced with two pipes, or no characters. Each cell is represented by a single character, 0-9 or '.'. '0' and '.' denote an unfilled cell. The sdk format does not support marks, locks, or user-filled numbers. The SDK format is the default format primarily because it is simple and understood by many other tools.

func PuzzleFormat

func PuzzleFormat(puzzle string) Format

PuzzleFormat returns the most likely format type for the provided puzzle string, or "" if none are valid.

type SudokuPuzzleConverter

type SudokuPuzzleConverter interface {
	//Load loads the puzzle defined by `puzzle`, in the format tied to this
	//partcular converter, into the provided grid. Returns false if the puzzle
	//couldn't be loaded (generally because it's invalid)
	Load(grid sudoku.MutableGrid, puzzle string) bool
	//DataString returns the serialization of the provided grid in the format provided by this converter.
	DataString(grid sudoku.Grid) string
	//Valid returns true if the provided string will successfully deserialize
	//with the given converter to a grid. For example, if the string contains
	//data only 50 cells, this should return false.
	Valid(puzzle string) bool
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL