h48

A prototype for an optimal Rubik's cube solver, work in progress.
git clone https://git.tronto.net/h48
Download | Log | Files | Refs | README | LICENSE

nissy.h (2444B)


      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;
     37 		static const error INVALID_CUBE;
     38 		static const error UNSOLVABLE_CUBE;
     39 		static const error INVALID_MOVES;
     40 		static const error INVALID_TRANS;
     41 		static const error INVALID_FORMAT;
     42 		static const error INVALID_SOLVER;
     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 cube {
     51 	public:
     52 		cube();
     53 		error move(const std::string&);
     54 		error transform(const std::string&);
     55 		void invert();
     56 		void compose(const cube&);
     57 		std::string to_string() const;
     58 		std::variant<std::string, error> to_string(
     59 		    const std::string& format) const;
     60 
     61 		static std::variant<cube, error> from_string(
     62 		    const std::string&);
     63 		static std::variant<cube, error> from_string(
     64 		    const std::string& str, const std::string& format);
     65 		static std::variant<cube, error> get(
     66 		    long long ep, long long eo, long long cp, long long co);
     67 		static std::variant<cube, error> get(
     68 		    long long ep, long long eo, long long cp, long long co,
     69 		    const std::string& options);
     70 
     71 	private:
     72 		std::string m_b32{"ABCDEFGH=ABCDEFGHIJKL"};
     73 	};
     74 
     75 	class solver {
     76 	public:
     77 		struct solve_result {
     78 			error err;
     79 			std::vector<std::string> solutions;
     80 			std::array<long long, 10> stats;
     81 		};
     82 
     83 		const std::string name;
     84 		size_t size;
     85 		std::string id;
     86 		std::vector<std::byte> data;
     87 		bool data_checked{false};
     88 
     89 		error generate_data();
     90 		void read_data(std::ifstream&);
     91 		error check_data();
     92 		void unload_data();
     93 		solve_result solve(const cube&, nissflag, unsigned minmoves,
     94 		    unsigned maxmoves, unsigned maxsols, unsigned optimal,
     95 		    unsigned threads);
     96 
     97 		static std::variant<solver, error> get(const std::string&);
     98 	private:
     99 		solver(const std::string& name);
    100 	};
    101 
    102 	error count_moves(const std::string&);
    103 	void set_logger(void (*)(const char *, void *), void *);
    104 }
    105 
    106 #endif