-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpy_interface.cpp
More file actions
54 lines (41 loc) · 1.3 KB
/
py_interface.cpp
File metadata and controls
54 lines (41 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include <board.h>
#include <move.h>
#include <rule.h>
#define VERSION_INFO 0.3.0
#define STRINGIFY(x) #x
#define MACRO_STRINGIFY(x) STRINGIFY(x)
namespace py = pybind11;
PYBIND11_MODULE(_core, m, py::mod_gil_not_used(), py::multiple_interpreters::per_interpreter_gil()) {
m.doc() = R"pbdoc(
Chinese Chess Library
-----------------------
.. currentmodule:: chinese_chess_lib
.. autosummary::
:toctree: _generate
get_legal_moves
warn
dead
)pbdoc";
py::class_<Chess>(m, "Chess")
.def(py::init<>()) // 默认构造函数
.def_readwrite("x", &Chess::x)
.def_readwrite("y", &Chess::y)
.def_readwrite("color", &Chess::color)
.def_readwrite("name", &Chess::name);
m.def("get_legal_moves", &get_legal_moves, R"pbdoc(
Get all legal moves for a piece on the board
)pbdoc");
m.def("warn", &warn, R"pbdoc(
Get warnings for the current board state
)pbdoc");
m.def("dead", &dead, R"pbdoc(
Check if a player is dead (i.e., their king is captured)
)pbdoc");
#ifdef VERSION_INFO
m.attr("__version__") = MACRO_STRINGIFY(VERSION_INFO);
#else
m.attr("__version__") = "dev";
#endif
}