YasSS 0.4.7.1 review

Download
by rbytes.net on

YasSS is a command line C++ program that solves given Sudokus. The actual work is done in a class the encapsulates all the functio

License: GPL (GNU General Public License)
File size: 629K
Developer: Moritz Lenz
0 stars award from rbytes.net

YasSS is a command line C++ program that solves given Sudokus.

The actual work is done in a class the encapsulates all the functionality, so it should be easy to set up another GUI for it.

How It Works

YasSS stores the Sudoku field in a two-dimensional array. For each cell there is stored which numbers can be entered there.

The actual solver is discussed below.

Header File of Class Sudoku

If a cell contains a zero, it is empty.

#ifndef _MORITZ_FIELD_
#define _MORITZ_FIELD_
#include < iostream >

// a Sudoku playing field implemented as a 2d fixed size array
// contains consistency checks and a solver.
class sudoku {
public:
sudoku();
// creates a field with in ital data. 0 means "not set".
// Note that the first coordinate is considered as x, so if
// you create an array char f= {{1 ,2 ...}, {..}} you will get
// the transposed sudoku field. but don't worry, sudoku is
// invariant under transposition
sudoku(char init_data[9][9]);
sudoku(char* init_data);

// creates a field with initial data. 0 means "not set".
// Note that the first coordinate is considered as x, so if
// you create an array char f= {{1 ,2 ...}, {..}} you will get
// the transposed sudoku field. but don't worry, sudoku is
// invariant under transposition
sudoku(int init_data[9][9]);

// generates a rather simplistic output to the given stream
// call as pretty_print(cout) or something like that...
void pretty_print(std::ostream &handle);

// just print all chars in one row
void print(std::ostream &handle);

// sets item (x, y) to val
// assumes that it is doesn't lead to an intermediate
// conflict with sudoku rules
// which is equivalent to saying it requires
// allowed_set(val, x, y) to be true
void set_item(char val, int x, int y);

// get entry at position (x, y)
// 0 means "unset"
int get_item(int x, int y);

// returns true if it doesn't lead to a direct error if you
// set (x, y) to val
// If data[x][y] != 0 the return value is
// true if val == data[x][y]
bool allowed_set(char val, int x, int y);

// try to solve the puzzle. Returns true on success.
bool solve();

// returns true if there is no zero entry left, e.g. the
// problem is solved correctly.
bool is_solved();

// returns true if there is no possibility to continue without
// violating rule
bool is_stuck();
protected:

// contains 0 for unset values and the corresponding value
// if the value is set
char data[9][9];

// allowed[x][y][i] is true if and only if it is possible to
// set data[x][y] to i+1 without conjuring an immediate
// collision.
// If data[x][y] == i != 0 then allowed[x][y][i] is true,
// allowed[x][y][j] = false for j != i
bool allowed[9][9][9];
bool simple_solve();
bool simple_solve1();
bool simple_solve2();
// returns either an is_solved or a stuck() version of *this
bool backtrack();
void null_init();

int recursion_depth;
void set_recursion_depth(int rd) {recursion_depth = rd;};
};

What's New in This Release:
This release fixes parsing of command line arguments that may have lead to segfaults and might have been exploited.

YasSS 0.4.7.1 keywords