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


      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::string solutions;
     83 		};
     84 
     85 		const std::string name;
     86 		size_t size;
     87 		std::string id;
     88 		std::vector<std::byte> data;
     89 		bool data_checked{false};
     90 
     91 		error generate_data();
     92 		void read_data(std::ifstream&);
     93 		error check_data();
     94 		void unload_data();
     95 		solve_result solve(const cube&, nissflag, unsigned minmoves,
     96 		    unsigned maxmoves, unsigned maxsols, unsigned optimal,
     97 		    unsigned threads, int (*poll_status)(void *),
     98 		    void *poll_status_data) const;
     99 
    100 		static std::variant<solver, error> get(const std::string&);
    101 	private:
    102 		solver(const std::string& name);
    103 	};
    104 
    105 	error count_moves(const std::string&);
    106 	void set_logger(void (*)(const char *, void *), void *);
    107 }
    108 
    109 #endif