diff --git a/src/core_ffi/python_ffi/binder/klsk_code.cc b/src/core_ffi/python_ffi/binder/klsk_code.cc index 6ed4dea..cdb65c4 100644 --- a/src/core_ffi/python_ffi/binder/klsk_code.cc +++ b/src/core_ffi/python_ffi/binder/klsk_code.cc @@ -5,10 +5,20 @@ #include "py_ffi/layout.h" #include "py_ffi/short_code.h" +using klotski::ffi::PyBlock; using klotski::ffi::PyLayout; using klotski::ffi::PyShortCode; static void bind_layout(const py::module_ &mod) { + py::enum_(mod, "Block") + .value("SPACE", PyBlock::SPACE) + .value("B_1x1", PyBlock::B_1x1) + .value("B_1x2", PyBlock::B_1x2) + .value("B_2x1", PyBlock::B_2x1) + .value("B_2x2", PyBlock::B_2x2) + .value("FILL", PyBlock::FILL) + .export_values(); + py::class_(mod, "Layout") .def(py::init()) .def(py::init()) @@ -27,6 +37,7 @@ static void bind_layout(const py::module_ &mod) { .def("__repr__", &PyLayout::repr) .def("next_cases", &PyLayout::next_cases) + .def("dump_seq", &PyLayout::dump_seq) // TODO: add fast_cal / fast_cal_multi / ... .def("to_short_code", &PyLayout::short_code) diff --git a/src/core_ffi/python_ffi/include/py_ffi/layout.h b/src/core_ffi/python_ffi/include/py_ffi/layout.h index 2bec073..9630c61 100644 --- a/src/core_ffi/python_ffi/include/py_ffi/layout.h +++ b/src/core_ffi/python_ffi/include/py_ffi/layout.h @@ -11,6 +11,15 @@ namespace klotski::ffi { +enum class PyBlock : uint8_t { + SPACE = 0b000, + B_1x2 = 0b001, + B_2x1 = 0b010, + B_1x1 = 0b011, + B_2x2 = 0b100, + FILL = 0b111, +}; + class PyLayout { public: PyLayout() = delete; @@ -57,6 +66,8 @@ public: [[nodiscard]] std::vector next_cases() const noexcept; + [[nodiscard]] std::array dump_seq() const noexcept; + // ------------------------------------------------------------------------------------- // private: diff --git a/src/core_ffi/python_ffi/wrapper/layout.cc b/src/core_ffi/python_ffi/wrapper/layout.cc index 22e7d26..53f0986 100644 --- a/src/core_ffi/python_ffi/wrapper/layout.cc +++ b/src/core_ffi/python_ffi/wrapper/layout.cc @@ -42,6 +42,16 @@ bool PyLayout::check(const std::string_view code) noexcept { return cases; } +std::array PyLayout::dump_seq() const noexcept { + std::array seq {}; + auto raw_code = code_.to_raw_code().unwrap(); + for (int i = 0; i < 20; ++i) { + auto tmp = (raw_code >> (i * 3)) & 0b111; + seq[i] = (PyBlock)(tmp); + } + return seq; +} + // ----------------------------------------------------------------------------------------- // std::string PyLayout::str(const PyLayout code) noexcept {