khetai 0.2.3 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.clang-format +14 -0
- data/Gemfile.lock +1 -1
- data/ext/khetai/dev/fltk-ui/ai_loader.cpp +20 -40
- data/ext/khetai/dev/fltk-ui/ai_loader.h +4 -5
- data/ext/khetai/dev/fltk-ui/game_board.cpp +98 -204
- data/ext/khetai/dev/fltk-ui/game_board.h +12 -19
- data/ext/khetai/dev/fltk-ui/game_board_util.cpp +16 -36
- data/ext/khetai/dev/fltk-ui/game_board_util.h +1 -1
- data/ext/khetai/dev/fltk-ui/khet.cpp +9 -14
- data/ext/khetai/dev/main.c +4 -6
- data/ext/khetai/khetai.c +25 -33
- data/ext/khetai/khetai_lib.c +252 -272
- data/ext/khetai/khetai_lib.h +88 -104
- data/lib/khetai/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 397d91c1cb38ed6a3c61ef8132415e88c74fcd80c933b124b028515109c656a1
|
4
|
+
data.tar.gz: 24b234943d22a75d358a3c4caa5723469d6ee98665e710ecdcc981288b975f11
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1bd6ceb6036f2a11bdce881f176ccccfe247d2884aa647b2da423b81cc3ff36120fa56fac338b4aacb55edcb2e11a4b722c85b3633c7c307e0419f0cf5b5bb07
|
7
|
+
data.tar.gz: ed3131f4fefe5bc2050a396bb39036b73782bbabc39756445806dbf6b07485a4503e119fcef4baaa491033d3c695bfde451efac6a9ca83aa5287197b0af18d55
|
data/.clang-format
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
BasedOnStyle: LLVM
|
2
|
+
IndentWidth: 4
|
3
|
+
BraceWrapping:
|
4
|
+
AfterClass: false
|
5
|
+
AfterControlStatement: false
|
6
|
+
AfterEnum: false
|
7
|
+
AfterFunction: false
|
8
|
+
AfterNamespace: false
|
9
|
+
AfterStruct: false
|
10
|
+
AfterUnion: false
|
11
|
+
BeforeCatch: false
|
12
|
+
BeforeElse: false
|
13
|
+
IndentBraces: false
|
14
|
+
ColumnLimit: 0
|
data/Gemfile.lock
CHANGED
@@ -1,98 +1,78 @@
|
|
1
1
|
#include "ai_loader.h"
|
2
2
|
|
3
|
-
AILoader::AILoader(const std::string &lib_path) : handle(nullptr)
|
4
|
-
{
|
3
|
+
AILoader::AILoader(const std::string &lib_path) : handle(nullptr) {
|
5
4
|
load_library(lib_path);
|
6
5
|
}
|
7
6
|
|
8
|
-
AILoader::~AILoader()
|
9
|
-
{
|
10
|
-
if (handle)
|
11
|
-
{
|
7
|
+
AILoader::~AILoader() {
|
8
|
+
if (handle) {
|
12
9
|
dlclose(handle);
|
13
10
|
}
|
14
11
|
}
|
15
12
|
|
16
|
-
void AILoader::load_library(const std::string &lib_path)
|
17
|
-
{
|
13
|
+
void AILoader::load_library(const std::string &lib_path) {
|
18
14
|
handle = dlopen(lib_path.c_str(), RTLD_LAZY);
|
19
|
-
if (!handle)
|
20
|
-
{
|
15
|
+
if (!handle) {
|
21
16
|
throw std::runtime_error("Failed to load KhetAI: " + std::string(dlerror()));
|
22
17
|
}
|
23
18
|
}
|
24
19
|
|
25
|
-
void AILoader::reload_library(const std::string &lib_path)
|
26
|
-
{
|
27
|
-
if (handle)
|
28
|
-
{
|
20
|
+
void AILoader::reload_library(const std::string &lib_path) {
|
21
|
+
if (handle) {
|
29
22
|
dlclose(handle);
|
30
23
|
}
|
31
24
|
load_library(lib_path);
|
32
25
|
}
|
33
26
|
|
34
|
-
void *AILoader::get_symbol(const std::string &symbol_name)
|
35
|
-
{
|
27
|
+
void *AILoader::get_symbol(const std::string &symbol_name) {
|
36
28
|
void *symbol = dlsym(handle, symbol_name.c_str());
|
37
29
|
check_error();
|
38
30
|
return symbol;
|
39
31
|
}
|
40
32
|
|
41
|
-
void AILoader::check_error()
|
42
|
-
{
|
33
|
+
void AILoader::check_error() {
|
43
34
|
const char *error = dlerror();
|
44
|
-
if (error)
|
45
|
-
{
|
35
|
+
if (error) {
|
46
36
|
throw std::runtime_error("Error in dynamic loading: " + std::string(error));
|
47
37
|
}
|
48
38
|
}
|
49
39
|
|
50
|
-
void (*AILoader::get_init_zobrist())()
|
51
|
-
{
|
40
|
+
void (*AILoader::get_init_zobrist())() {
|
52
41
|
return reinterpret_cast<void (*)()>(get_symbol("init_zobrist"));
|
53
42
|
}
|
54
43
|
|
55
|
-
void (*AILoader::get_reset_undo())()
|
56
|
-
{
|
44
|
+
void (*AILoader::get_reset_undo())() {
|
57
45
|
return reinterpret_cast<void (*)()>(get_symbol("reset_undo"));
|
58
46
|
}
|
59
47
|
|
60
|
-
void (*AILoader::get_setup_board())(char **)
|
61
|
-
{
|
48
|
+
void (*AILoader::get_setup_board())(char **) {
|
62
49
|
return reinterpret_cast<void (*)(char **)>(get_symbol("setup_board"));
|
63
50
|
}
|
64
51
|
|
65
|
-
void (*AILoader::get_print_board())()
|
66
|
-
{
|
52
|
+
void (*AILoader::get_print_board())() {
|
67
53
|
return reinterpret_cast<void (*)()>(get_symbol("print_board"));
|
68
54
|
}
|
69
55
|
|
70
|
-
void (*AILoader::get_set_time_parameters())(int, time_t)
|
71
|
-
{
|
56
|
+
void (*AILoader::get_set_time_parameters())(int, time_t) {
|
72
57
|
return reinterpret_cast<void (*)(int, time_t)>(get_symbol("set_time_parameters"));
|
73
58
|
}
|
74
59
|
|
75
|
-
Move (*AILoader::get_alphabeta_root())(int, enum Player)
|
76
|
-
{
|
60
|
+
Move (*AILoader::get_alphabeta_root())(int, enum Player) {
|
77
61
|
return reinterpret_cast<Move (*)(int, enum Player)>(get_symbol("alphabeta_root"));
|
78
62
|
}
|
79
63
|
|
80
|
-
void (*AILoader::get_make_move())(Move)
|
81
|
-
{
|
64
|
+
void (*AILoader::get_make_move())(Move) {
|
82
65
|
return reinterpret_cast<void (*)(Move)>(get_symbol("make_move"));
|
83
66
|
}
|
84
67
|
|
85
|
-
int (*AILoader::get_get_start())(Move)
|
86
|
-
{
|
68
|
+
int (*AILoader::get_get_start())(Move) {
|
87
69
|
return reinterpret_cast<int (*)(Move)>(get_symbol("get_start_wrapper"));
|
88
70
|
}
|
89
71
|
|
90
|
-
int (*AILoader::get_get_end())(Move)
|
91
|
-
{
|
72
|
+
int (*AILoader::get_get_end())(Move) {
|
92
73
|
return reinterpret_cast<int (*)(Move)>(get_symbol("get_end_wrapper"));
|
93
74
|
}
|
94
75
|
|
95
|
-
int (*AILoader::get_get_rotation())(Move)
|
96
|
-
{
|
76
|
+
int (*AILoader::get_get_rotation())(Move) {
|
97
77
|
return reinterpret_cast<int (*)(Move)>(get_symbol("get_rotation_wrapper"));
|
98
78
|
}
|
@@ -1,14 +1,13 @@
|
|
1
1
|
#ifndef AI_LOADER_H
|
2
2
|
#define AI_LOADER_H
|
3
3
|
|
4
|
+
#include "../../khetai_lib.h"
|
4
5
|
#include <dlfcn.h>
|
5
6
|
#include <stdexcept>
|
6
7
|
#include <string>
|
7
|
-
#include "../../khetai_lib.h"
|
8
8
|
|
9
|
-
class AILoader
|
10
|
-
|
11
|
-
public:
|
9
|
+
class AILoader {
|
10
|
+
public:
|
12
11
|
AILoader(const std::string &lib_path);
|
13
12
|
~AILoader();
|
14
13
|
|
@@ -24,7 +23,7 @@ public:
|
|
24
23
|
int (*get_get_rotation())(Move);
|
25
24
|
void reload_library(const std::string &lib_path);
|
26
25
|
|
27
|
-
private:
|
26
|
+
private:
|
28
27
|
void *handle;
|
29
28
|
void load_library(const std::string &lib_path);
|
30
29
|
void *get_symbol(const std::string &symbol_name);
|