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 (2421B)


      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 NULL_POINTER;
     43 		static const error BUFFER_SIZE;
     44 		static const error DATA;
     45 		static const error OPTIONS;
     46 		static const error UNKNOWN;
     47 	};
     48 
     49 	class status {
     50 	public:
     51 		int value;
     52 
     53 		static const status RUN;
     54 		static const status STOP;
     55 		static const status PAUSE;
     56 	};
     57 
     58 	class cube {
     59 	public:
     60 		cube();
     61 		error move(const std::string&);
     62 		error transform(const std::string&);
     63 		void invert();
     64 		std::string to_string() const;
     65 
     66 		static std::variant<cube, error> from_string(
     67 		    const std::string&);
     68 		static std::variant<cube, error> get(long long ep,
     69 		    long long eo, long long cp, long long co, long long orien);
     70 		static std::variant<cube, error> get(long long ep,
     71 		    long long eo, long long cp, long long co, long long orien,
     72 		    const std::string& options);
     73 
     74 	private:
     75 		std::string m_str{"ABCDEFGH=ABCDEFGHIJKL=A"};
     76 	};
     77 
     78 	class solver {
     79 	public:
     80 		struct solve_result {
     81 			error err;
     82 			std::vector<std::string> solutions;
     83 			std::array<long long, 10> stats;
     84 		};
     85 
     86 		const std::string name;
     87 		size_t size;
     88 		std::string id;
     89 		std::vector<std::byte> data;
     90 		bool data_checked{false};
     91 
     92 		error generate_data();
     93 		void read_data(std::ifstream&);
     94 		error check_data();
     95 		void unload_data();
     96 		solve_result solve(const cube&, nissflag, unsigned minmoves,
     97 		    unsigned maxmoves, unsigned maxsols, unsigned optimal,
     98 		    unsigned threads, int (*poll_status)(void *),
     99 		    void *poll_status_data) const;
    100 
    101 		static std::variant<solver, error> get(const std::string&);
    102 	private:
    103 		solver(const std::string& name);
    104 	};
    105 
    106 	error count_moves(const std::string&);
    107 	void set_logger(void (*)(const char *, void *), void *);
    108 }
    109 
    110 #endif