khetai 0.2.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.clang-format +14 -0
- data/Gemfile.lock +1 -1
- data/README.md +5 -2
- data/ext/khetai/dev/fltk-ui/ai_loader.cpp +23 -38
- data/ext/khetai/dev/fltk-ui/ai_loader.h +5 -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 +15 -25
- 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 +16 -31
- data/ext/khetai/khetai_lib.c +220 -256
- data/ext/khetai/khetai_lib.h +88 -67
- 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: c47fe1f761953801fa38ca71116b99e2a8aa96a67b0878a722674efdedbe3ca9
|
4
|
+
data.tar.gz: 9333855a0a63b63ec6a0e40dba571e2ef7423d496947c3344207468c86649135
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3b54d3fcb018ab5ce843203e9abe4ad850ebf89aae61e47677f3f13bf3911a3f9b405aa76794ab61f62cbecf8db6c7b991ab282e8565452499106696b3f3cdce
|
7
|
+
data.tar.gz: 23bbe28c2875f9c7a8344e6c441554cabfa3ce4a0728a79941761169f9e36d97aaff4ac81354577a5696c7bd6908e14c5924af6c85a1eb7de2a2823c86f7ec7d
|
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
data/README.md
CHANGED
@@ -51,16 +51,19 @@ The internals of the gem are written in C, located in `ext/khetai`.
|
|
51
51
|
$ bundle exec rake build
|
52
52
|
$ gem install pkg/khetai-<version>.gem
|
53
53
|
|
54
|
-
Once tested and verified, bump the version number in `lib/khetai/version.rb`
|
54
|
+
Once tested and verified, bump the version number in `lib/khetai/version.rb` and commit changes.
|
55
55
|
|
56
56
|
To release and push to rubygems.org:
|
57
57
|
|
58
58
|
$ bundle exec rake release
|
59
|
+
|
60
|
+
To push a pre-built gem manually:
|
61
|
+
|
59
62
|
$ gem push pkg/<gem>
|
60
63
|
|
61
64
|
## Manual Testing
|
62
65
|
|
63
|
-
There is a GUI test harness written in C++ using FLTK available in the
|
66
|
+
There is a GUI test harness written in C++ using FLTK available in the [ext/khetai/dev/fltk-ui](/ext/khetai/dev/fltk-ui) directory.
|
64
67
|
|
65
68
|
### Why does this exist?
|
66
69
|
|
@@ -1,93 +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::
|
56
|
-
|
44
|
+
void (*AILoader::get_reset_undo())() {
|
45
|
+
return reinterpret_cast<void (*)()>(get_symbol("reset_undo"));
|
46
|
+
}
|
47
|
+
|
48
|
+
void (*AILoader::get_setup_board())(char **) {
|
57
49
|
return reinterpret_cast<void (*)(char **)>(get_symbol("setup_board"));
|
58
50
|
}
|
59
51
|
|
60
|
-
void (*AILoader::get_print_board())()
|
61
|
-
{
|
52
|
+
void (*AILoader::get_print_board())() {
|
62
53
|
return reinterpret_cast<void (*)()>(get_symbol("print_board"));
|
63
54
|
}
|
64
55
|
|
65
|
-
void (*AILoader::get_set_time_parameters())(int, time_t)
|
66
|
-
{
|
56
|
+
void (*AILoader::get_set_time_parameters())(int, time_t) {
|
67
57
|
return reinterpret_cast<void (*)(int, time_t)>(get_symbol("set_time_parameters"));
|
68
58
|
}
|
69
59
|
|
70
|
-
Move (*AILoader::get_alphabeta_root())(int, enum Player)
|
71
|
-
{
|
60
|
+
Move (*AILoader::get_alphabeta_root())(int, enum Player) {
|
72
61
|
return reinterpret_cast<Move (*)(int, enum Player)>(get_symbol("alphabeta_root"));
|
73
62
|
}
|
74
63
|
|
75
|
-
void (*AILoader::get_make_move())(Move)
|
76
|
-
{
|
64
|
+
void (*AILoader::get_make_move())(Move) {
|
77
65
|
return reinterpret_cast<void (*)(Move)>(get_symbol("make_move"));
|
78
66
|
}
|
79
67
|
|
80
|
-
int (*AILoader::get_get_start())(Move)
|
81
|
-
{
|
68
|
+
int (*AILoader::get_get_start())(Move) {
|
82
69
|
return reinterpret_cast<int (*)(Move)>(get_symbol("get_start_wrapper"));
|
83
70
|
}
|
84
71
|
|
85
|
-
int (*AILoader::get_get_end())(Move)
|
86
|
-
{
|
72
|
+
int (*AILoader::get_get_end())(Move) {
|
87
73
|
return reinterpret_cast<int (*)(Move)>(get_symbol("get_end_wrapper"));
|
88
74
|
}
|
89
75
|
|
90
|
-
int (*AILoader::get_get_rotation())(Move)
|
91
|
-
{
|
76
|
+
int (*AILoader::get_get_rotation())(Move) {
|
92
77
|
return reinterpret_cast<int (*)(Move)>(get_symbol("get_rotation_wrapper"));
|
93
78
|
}
|
@@ -1,18 +1,18 @@
|
|
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
|
|
15
14
|
void (*get_init_zobrist())();
|
15
|
+
void (*get_reset_undo())();
|
16
16
|
void (*get_setup_board())(char **);
|
17
17
|
void (*get_print_board())();
|
18
18
|
void (*get_set_time_parameters())(int, time_t);
|
@@ -23,7 +23,7 @@ public:
|
|
23
23
|
int (*get_get_rotation())(Move);
|
24
24
|
void reload_library(const std::string &lib_path);
|
25
25
|
|
26
|
-
private:
|
26
|
+
private:
|
27
27
|
void *handle;
|
28
28
|
void load_library(const std::string &lib_path);
|
29
29
|
void *get_symbol(const std::string &symbol_name);
|