nissy-core

The "engine" of nissy, including the H48 optimal solver.
git clone https://git.tronto.net/nissy-core
Download | Log | Files | Refs | README | LICENSE

nissy.h (2946B)


      1 /*
      2 C++20 header file for nissy.
      3 */
      4 
      5 #ifndef NISSY_H
      6 #define NISSY_H
      7 
      8 #include <array>
      9 #include <functional>
     10 #include <optional>
     11 #include <ranges>
     12 #include <string>
     13 #include <string_view>
     14 #include <variant>
     15 #include <vector>
     16 
     17 namespace nissy {
     18 
     19 	class nissflag {
     20 	public:
     21 		unsigned value;
     22 
     23 		static const nissflag NORMAL;
     24 		static const nissflag INVERSE;
     25 		static const nissflag MIXED;
     26 		static const nissflag LINEAR;
     27 		static const nissflag ALL;
     28 	};
     29 
     30 	class error {
     31 	public:
     32 		long long value;
     33 		bool ok() const;
     34 
     35 		static const error OK;
     36 		static const error UNSOLVABLE_WARNING;
     37 		static const error UNSOLVABLE_ERROR;
     38 		static const error INVALID_CUBE;
     39 		static const error INVALID_MOVES;
     40 		static const error INVALID_TRANS;
     41 		static const error INVALID_SOLVER;
     42 		static const error INVALID_VARIATION;
     43 		static const error NULL_POINTER;
     44 		static const error BUFFER_SIZE;
     45 		static const error DATA;
     46 		static const error OPTIONS;
     47 		static const error UNKNOWN;
     48 	};
     49 
     50 	class status {
     51 	public:
     52 		int value;
     53 
     54 		static const status RUN;
     55 		static const status STOP;
     56 		static const status PAUSE;
     57 	};
     58 
     59 	class compare_result {
     60 	public:
     61 		long long value;
     62 
     63 		static const compare_result EQUAL;
     64 		static const compare_result DIFFERENT;
     65 	};
     66 
     67 	class variation {
     68 	public:
     69 		struct variations_result {
     70 			error err;
     71 			std::string solutions;
     72 		};
     73 
     74 		const std::string name;
     75 
     76 		variations_result find_variations(const std::string&);
     77 		static std::variant<variation, error> get(const std::string&);
     78 	private:
     79 		variation(const std::string&);
     80 	};
     81 
     82 	class cube {
     83 	public:
     84 		cube();
     85 		error move(const std::string&);
     86 		error transform(const std::string&);
     87 		void invert();
     88 		std::string to_string() const;
     89 
     90 		static std::variant<cube, error> from_string(
     91 		    const std::string&);
     92 		static std::variant<cube, error> get(long long ep,
     93 		    long long eo, long long cp, long long co, long long orien);
     94 		static std::variant<cube, error> get(long long ep,
     95 		    long long eo, long long cp, long long co, long long orien,
     96 		    const std::string& options);
     97 
     98 	private:
     99 		std::string m_str{"ABCDEFGH=ABCDEFGHIJKL=A"};
    100 	};
    101 
    102 	class solver {
    103 	public:
    104 		struct solve_result {
    105 			error err;
    106 			std::string solutions;
    107 		};
    108 
    109 		const std::string name;
    110 		size_t size;
    111 		std::string id;
    112 		std::vector<std::byte> data;
    113 		bool data_checked{false};
    114 
    115 		error generate_data();
    116 		void read_data(std::ifstream&);
    117 		error check_data();
    118 		void unload_data();
    119 		solve_result solve(const cube&, nissflag, unsigned minmoves,
    120 		    unsigned maxmoves, unsigned maxsols, unsigned optimal,
    121 		    unsigned threads, int (*poll_status)(void *),
    122 		    void *poll_status_data) const;
    123 
    124 		static std::variant<solver, error> get(const std::string&);
    125 	private:
    126 		solver(const std::string& name);
    127 	};
    128 
    129 	error count_moves(const std::string&);
    130 	std::variant<error, compare_result> compare_moves(
    131 	    const std::string&, const std::string&);
    132 	void set_logger(void (*)(const char *, void *), void *);
    133 }
    134 
    135 #endif