Browse Source

feat: add block-seq dump support

master
Dnomd343 6 days ago
parent
commit
93ad027fd0
  1. 11
      src/core_ffi/python_ffi/binder/klsk_code.cc
  2. 11
      src/core_ffi/python_ffi/include/py_ffi/layout.h
  3. 10
      src/core_ffi/python_ffi/wrapper/layout.cc

11
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_<PyBlock>(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_<PyLayout>(mod, "Layout")
.def(py::init<uint64_t>())
.def(py::init<PyShortCode>())
@ -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)

11
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<PyLayout> next_cases() const noexcept;
[[nodiscard]] std::array<PyBlock, 20> dump_seq() const noexcept;
// ------------------------------------------------------------------------------------- //
private:

10
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<PyBlock, 20> PyLayout::dump_seq() const noexcept {
std::array<PyBlock, 20> 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 {

Loading…
Cancel
Save