SudokuAnalyzer.hpp

Analyzes a sudoku instance to determine the solving experience for a human player.

This file is part of Empirical, https://github.com/devosoft/Empirical Copyright (C) 2024 Michigan State University MIT Software license; see doc/LICENSE.md

DEVELOPER NOTES: For the moment, we will assume that all boards are 9x9 with a standard Sudoku layout. In the future, we should make the board configuration more flexible.

Defines

INCLUDE_EMP_GAMES_SUDOKU_ANALYZER_HPP_GUARD
class SudokuAnalyzer : public GridPuzzleAnalyzer<9, 9, 9>
#include <SudokuAnalyzer.hpp>

Public Functions

inline SudokuAnalyzer()
SudokuAnalyzer(const SudokuAnalyzer&) = default
inline ~SudokuAnalyzer()
SudokuAnalyzer &operator=(const SudokuAnalyzer&) = default
inline virtual bool Set(size_t cell, uint8_t state) override

Set the value of an individual cell Return true/false based on whether progress was made toward solving the puzzle.

inline virtual void Print(bool verbose = true, std::ostream &out = std::cout) override
inline void PrintSimple(std::ostream &out = std::cout)
inline void PrintDetails(std::ostream &out = std::cout)
inline bool ForceSolve(uint8_t cur_state = 1)
inline vector<PuzzleMove> Solve_FindLastCellState()
inline vector<PuzzleMove> Solve_FindLastRegionState()
inline vector<PuzzleMove> Solve_FindRegionOverlap()
inline vector<PuzzleMove> Solve_FindLimitedCells2()
inline vector<PuzzleMove> Solve_FindLimitedCells3()
inline vector<PuzzleMove> Solve_FindLimitedStates2()
inline vector<PuzzleMove> Solve_FindLimitedStates3()
inline vector<PuzzleMove> Solve_FindSwordfish2_ROW_COL()
inline vector<PuzzleMove> Solve_FindSwordfish2_BOX()
inline vector<PuzzleMove> Solve_FindSwordfish3_ROW_COL()
inline vector<PuzzleMove> Solve_FindSwordfish4_ROW_COL()
inline bool OK()

Public Static Functions

static inline constexpr size_t GetNumCells()
static inline constexpr size_t GetNumMoveTypes()

Private Types

using base_t = GridPuzzleAnalyzer<NUM_ROWS, NUM_COLS, NUM_STATES>
using grid_bits_t = BitSet<NUM_CELLS>
using state_bits_t = BitSet<NUM_STATES + 1>
using region_bits_t = BitSet<NUM_REGIONS>
using region_pair_t = std::pair<size_t, size_t>
using symbol_set_t = array<char, NUM_STATES + 1>

Private Functions

inline grid_bits_t ComboRegion(region_bits_t region_ids)

Convert a set of region bits into the combined grid cells in those regions.

Private Static Functions

static inline const array<grid_bits_t, NUM_REGIONS> &RegionMap()
static inline array<grid_bits_t, NUM_REGIONS> BuildRegionMap()
static inline const grid_bits_t &RegionMap(size_t id)
static inline const grid_bits_t &RowMap(size_t id)
static inline const grid_bits_t &ColMap(size_t id)
static inline const grid_bits_t &BoxMap(size_t id)
static inline const array<region_bits_t, NUM_CELLS> &CellMemberships()
static inline array<region_bits_t, NUM_CELLS> BuildCellMemberships()
static inline const region_bits_t CellMemberships(size_t cell_id)
static inline const array<grid_bits_t, NUM_CELLS> &CellLinks()
static inline array<grid_bits_t, NUM_CELLS> BuildCellLinks()
static inline const grid_bits_t &CellLinks(size_t cell_id)
static inline const array<region_pair_t, NUM_OVERLAPS> &RegionOverlaps()
static inline array<region_pair_t, NUM_OVERLAPS> BuildRegionOverlaps()

Private Static Attributes

static constexpr size_t NUM_STATES = 9
static constexpr size_t NUM_ROWS = 9
static constexpr size_t NUM_COLS = 9
static constexpr size_t NUM_SQUARES = 9
static constexpr size_t NUM_CELLS = NUM_ROWS * NUM_COLS
static constexpr size_t NUM_REGIONS = NUM_ROWS + NUM_COLS + NUM_SQUARES
static constexpr size_t REGIONS_PER_CELL = 3
static constexpr size_t NO_REGION = static_cast<size_t>(-1)
static constexpr size_t NUM_OVERLAPS = (NUM_ROWS + NUM_COLS) * 3