Documentation

The application is split into a CLI that can be found under app/ and a library (suso) that does all the heavylifting. You can find the documentation of the library here.

Glossary

cell
The cells are the places of a Sudoku where the numbers are placed. A cell can be empty or filled with exactly one number.
field
The whole 9x9 grid of a Sudoku with all its 81 cells.
row
A row of 9 cells in the field. There are always nine rows in one field.
column
A column of 9 cells in the field. There are always nine columns in one field.
block
A section of the field with 3x3 cells. There are nine of these non overlapping sections in one field. In the visualized Sudokus they are mostly marked by stronger lines.
group
An area where numbers have to be unique in. This can be a block, a row or a column.

Library documentation

Enums

enum Mode

Values:

DEFAULT
NAKED
HIDDEN
BACKTRACKING
LAST_RESORT_BACKTRACKING

Functions

std::ostream &operator<<(std::ostream &stream, const Metrics &metrics)

Variables

const Position INVALID_POS = {-1, -1}

A invalid position.

struct Position
#include <suso.h>

A position contains the coordinates of one cell inside a Sudoku field.

Public Members

int x

The x-component of the coordinate. This can also be described as the number of the column.

int y

The y-component of the coordinate. This can also be described as the number of the row.

struct Metrics
#include <suso.h>

Metrics contain information about a single solving process.

Public Members

int given

Number of cells already filled in the loaded Sudoku

int solvedNaked

Number of cells filled by searching for naked singles

int solvedHidden

Number of cells filled by searching for hidden singles

int solvedBacktracking

Number of cells filled by the backtracking algorithm.

std::chrono::duration<double, std::milli> duration

The amount of time that was needed to solve the Sudoku

class Sudoku
#include <suso.h>

A Sudoku represents the complete field of one Sudoku. It also has functions to solve the Sudoku using different algorithms.

Public Functions

Sudoku()

Creates a new empty Sudoku.

Metrics getSolvingMetrics()

Get information about how this Sudoku has been solved. This is only filled completely after successfully solving it.

Return
Metrics about the previous solving process

std::vector<int> validNumbers(Position pos)

This function returns all numbers that could be placed in the cell at the given position so they do not conflict with the numbers already placed in the field.

Return
all possible numbers for the position
Parameters
  • pos: the position to check

bool loadFromFile(std::string path)

This function reads a file into the sudoku field.

Return
true if the Sudoku stored in the field is correct and could be read successfully
Parameters
  • path: the path of the Sudoku file

bool solveNakedSingles()

This function tries to fill cells by searching for naked singles. These are cells where only one number is valid. The function iterates over the whole field and fills in the number when it finds a naked single.

Return
true if the field has been changed (at least one number filled into a cell), false otherwise

bool solveHiddenSingles()

This function tries to fill cells by searching for hidden singles. This is a cell that is the only one in a group, that could contain a specific number. The function iterates over all groups and fills in the numbers when it finds hidden singles inside a group.

Return
true if the field has been changed (at least one number filled into a cell), false otherwise

bool solveBacktracking()

This function solves the sudoku recursively by using the backtracking algorithm.

Return
true if the sudoku is solved

void checkSolvability() const

This function checks if the sudoku is solvable. If the sudoku is not solvable, the function will throw an exception.

void solve(Mode algorithm)

This function solves the sudoku with the given algorithms.

Return
true if sudoku is solved
Parameters
  • algorithm: way to solve the sudoku

Private Functions

bool isEmpty(Position pos)

Returns if a given cell is not filled with a number.

Return
true if the cell is empty, false otherwise
Parameters
  • pos: the position to check

void insertNumber(Position pos, int num)

Writes a number into the Sudoku field at a given position. No checks of the number are performed.

Parameters
  • pos: where to insert the number
  • num: the number to insert

bool getNextEmptyCell(Position &pos)

Returns if the sudoku has one or more empty cell to fill.

Return
true if at least one cell is empty
Parameters
  • pos: reference to the position of the next empty cell

Private Members

std::array<std::array<int, 9>, 9> field
Metrics metrics

Friends

std::ostream &operator<<(std::ostream &stream, Sudoku &sudoku)

This function can be used to print out the current state of the Sudoku. Cells that are already filled with a number are printed as the number, empty cells show up as zero.

bool operator==(const Sudoku &lhs, const Sudoku &rhs)

This function can be used to compare two sudoku fields.

Return
true if the every cell is equal to the same cell in the other sudoku
Parameters
  • lhs: the sudoku to compare with the other sudoku
  • rhs: other sudoku to compare with the sudoku