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


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