khetai 0.3.4 → 0.3.5
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 +5 -1
- data/.gitignore +8 -4
- data/Gemfile.lock +1 -1
- data/README.md +48 -28
- data/ext/khetai/khetai.c +1 -1
- data/ext/khetai/khetai_lib.c +2 -1
- data/ext/khetai/khetai_lib.h +0 -4
- data/khetai.gemspec +1 -1
- data/lib/khetai/version.rb +1 -1
- metadata +2 -54
- data/bin/console +0 -14
- data/bin/setup +0 -8
- data/ext/khetai/dev/CMakeLists.txt +0 -5
- data/ext/khetai/dev/README.md +0 -15
- data/ext/khetai/dev/fltk-ui/Makefile +0 -65
- data/ext/khetai/dev/fltk-ui/Makefile.khetai +0 -46
- data/ext/khetai/dev/fltk-ui/README.md +0 -34
- data/ext/khetai/dev/fltk-ui/ai_loader.cpp +0 -78
- data/ext/khetai/dev/fltk-ui/ai_loader.h +0 -33
- data/ext/khetai/dev/fltk-ui/assets/anubis_red_e.png +0 -0
- data/ext/khetai/dev/fltk-ui/assets/anubis_red_n.png +0 -0
- data/ext/khetai/dev/fltk-ui/assets/anubis_red_s.png +0 -0
- data/ext/khetai/dev/fltk-ui/assets/anubis_red_w.png +0 -0
- data/ext/khetai/dev/fltk-ui/assets/anubis_silver_e.png +0 -0
- data/ext/khetai/dev/fltk-ui/assets/anubis_silver_n.png +0 -0
- data/ext/khetai/dev/fltk-ui/assets/anubis_silver_s.png +0 -0
- data/ext/khetai/dev/fltk-ui/assets/anubis_silver_w.png +0 -0
- data/ext/khetai/dev/fltk-ui/assets/example_board.png +0 -0
- data/ext/khetai/dev/fltk-ui/assets/laser_red_e.png +0 -0
- data/ext/khetai/dev/fltk-ui/assets/laser_red_n.png +0 -0
- data/ext/khetai/dev/fltk-ui/assets/laser_red_s.png +0 -0
- data/ext/khetai/dev/fltk-ui/assets/laser_red_w.png +0 -0
- data/ext/khetai/dev/fltk-ui/assets/laser_silver_e.png +0 -0
- data/ext/khetai/dev/fltk-ui/assets/laser_silver_n.png +0 -0
- data/ext/khetai/dev/fltk-ui/assets/laser_silver_s.png +0 -0
- data/ext/khetai/dev/fltk-ui/assets/laser_silver_w.png +0 -0
- data/ext/khetai/dev/fltk-ui/assets/pharaoh_red.png +0 -0
- data/ext/khetai/dev/fltk-ui/assets/pharaoh_silver.png +0 -0
- data/ext/khetai/dev/fltk-ui/assets/pyramid_red_e.png +0 -0
- data/ext/khetai/dev/fltk-ui/assets/pyramid_red_n.png +0 -0
- data/ext/khetai/dev/fltk-ui/assets/pyramid_red_s.png +0 -0
- data/ext/khetai/dev/fltk-ui/assets/pyramid_red_w.png +0 -0
- data/ext/khetai/dev/fltk-ui/assets/pyramid_silver_e.png +0 -0
- data/ext/khetai/dev/fltk-ui/assets/pyramid_silver_n.png +0 -0
- data/ext/khetai/dev/fltk-ui/assets/pyramid_silver_s.png +0 -0
- data/ext/khetai/dev/fltk-ui/assets/pyramid_silver_w.png +0 -0
- data/ext/khetai/dev/fltk-ui/assets/scarab_red_e.png +0 -0
- data/ext/khetai/dev/fltk-ui/assets/scarab_red_n.png +0 -0
- data/ext/khetai/dev/fltk-ui/assets/scarab_red_s.png +0 -0
- data/ext/khetai/dev/fltk-ui/assets/scarab_red_w.png +0 -0
- data/ext/khetai/dev/fltk-ui/assets/scarab_silver_e.png +0 -0
- data/ext/khetai/dev/fltk-ui/assets/scarab_silver_n.png +0 -0
- data/ext/khetai/dev/fltk-ui/assets/scarab_silver_s.png +0 -0
- data/ext/khetai/dev/fltk-ui/assets/scarab_silver_w.png +0 -0
- data/ext/khetai/dev/fltk-ui/build_khetai.sh +0 -9
- data/ext/khetai/dev/fltk-ui/game_board.cpp +0 -794
- data/ext/khetai/dev/fltk-ui/game_board.h +0 -98
- data/ext/khetai/dev/fltk-ui/game_board_util.cpp +0 -101
- data/ext/khetai/dev/fltk-ui/game_board_util.h +0 -15
- data/ext/khetai/dev/fltk-ui/khet.cpp +0 -54
- data/ext/khetai/dev/main.c +0 -49
- data/ext/khetai/dev/main.rb +0 -14
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4180faa9b1b6f2e37a105b4d10d086e4ff0abcc56965a3859d6cbf17c3457041
|
|
4
|
+
data.tar.gz: 337d513e93969ba3d2bbdf69d6aef355709716ef389aa141f4d5b15f4a938987
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5183344cf972f36b283f2045adcf1bbdc876fefdd8aab1f9433e72b3d5df2e17ede6d6f78e1d1560a7c9012458cba1456f4a1e7a15db42ea95491a554376e75e
|
|
7
|
+
data.tar.gz: 35a431bb7de2dca1080468af770da146acb1883a8123fac542a46f1ea2cf2c528fd1b43b1a9d300be9a86fb822c60c9d2632d1d74ddf0ba45ddfcfb69360ea98
|
data/.clang-format
CHANGED
data/.gitignore
CHANGED
|
@@ -6,11 +6,15 @@
|
|
|
6
6
|
/pkg/
|
|
7
7
|
/spec/reports/
|
|
8
8
|
/tmp/
|
|
9
|
-
/build/
|
|
10
9
|
/scripts/
|
|
11
|
-
/
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
**/SDL3-wasm/
|
|
11
|
+
**/build/
|
|
12
|
+
**/build-wasm/
|
|
13
|
+
**/build_khetai/
|
|
14
|
+
**/.cache/
|
|
15
|
+
**/.clangd
|
|
16
|
+
**/compile_commands.json
|
|
17
|
+
/ext/khetai/dev/sdl-ui/commands.txt
|
|
14
18
|
.vscode
|
|
15
19
|
*.so
|
|
16
20
|
*.o
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
|
@@ -1,25 +1,24 @@
|
|
|
1
1
|
# KhetAI
|
|
2
2
|
|
|
3
|
-
An AI engine for the board game Khet.
|
|
3
|
+
An AI engine and multi-platform implementation for the board game [Khet](https://en.wikipedia.org/wiki/Khet_(game)).
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
This project started as a Ruby gem and over time, new ways to interact with the core C code were built (see the [Subprojects](#subprojects) section below).
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
---
|
|
8
8
|
|
|
9
|
-
##
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
## AI Engine
|
|
10
|
+
|
|
11
|
+
The core AI engine is written in C for performance and uses bit-packing, alpha-beta pruning, and Zobrist hashing. The code lives in the [ext/khetai](/ext/khetai) directory.
|
|
12
|
+
|
|
13
|
+
Example (via the Ruby gem):
|
|
14
14
|
|
|
15
|
-
## Example
|
|
16
15
|
```ruby
|
|
17
16
|
require 'khetai'
|
|
18
17
|
|
|
19
18
|
# initial board setup:
|
|
20
19
|
# A = anubis, P = pyramid, S = scarab, X = pharaoh, L = sphinx
|
|
21
20
|
# capital letters = red, lowercase letters = silver
|
|
22
|
-
#
|
|
21
|
+
# numbers = 1 north, 2 east, 3 south, 4 west
|
|
23
22
|
board = ["L2", "--", "--", "--", "A2", "X2", "A2", "P1", "--", "--",
|
|
24
23
|
"--", "--", "P2", "--", "--", "--", "--", "--", "--", "--",
|
|
25
24
|
"--", "--", "--", "p3", "--", "--", "--", "--", "--", "--",
|
|
@@ -30,33 +29,56 @@ board = ["L2", "--", "--", "--", "A2", "X2", "A2", "P1", "--", "--",
|
|
|
30
29
|
"--", "--", "p3", "a0", "x0", "a0", "--", "--", "--", "l0"]
|
|
31
30
|
|
|
32
31
|
whose_turn = 1 # silver = 0, red = 1
|
|
33
|
-
max_search_depth = 25 #
|
|
34
|
-
max_search_time = 5 #
|
|
32
|
+
max_search_depth = 25 # between 2 and 25
|
|
33
|
+
max_search_time = 5 # in seconds
|
|
35
34
|
|
|
36
|
-
# returns [start_index, end_index, rotation]
|
|
37
35
|
move = KhetAI.move(board, whose_turn, max_search_depth, max_search_time)
|
|
38
|
-
|
|
39
|
-
#
|
|
40
|
-
# move[1] = end index
|
|
41
|
-
# move[2] = rotation (1, -1, 0) (clockwise, anticlockwise, none)
|
|
36
|
+
#=> [start_index, end_index, rotation]
|
|
37
|
+
# rotation = 0 none, 1 clockwise, -1 counterclockwise
|
|
42
38
|
```
|
|
43
39
|
|
|
44
|
-
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
## Subprojects
|
|
43
|
+
|
|
44
|
+
### [sdl-ui](/ext/khetai/dev/sdl-ui)
|
|
45
|
+
|
|
46
|
+
Uses [SDL3](https://github.com/libsdl-org/SDL) for its rendering and input processing. The laser is animated in real time using vector math and the pieces are all drawn with `SDL_RenderGeometry` calls. It also runs in the browser via WebAssembly, compiled with Emscripten.
|
|
45
47
|
|
|
46
|
-
|
|
48
|
+
<a href="https://jkugs.github.io/">
|
|
49
|
+
<img src="ext/khetai/dev/sdl-ui/images/sdl-khet.png" alt="board" width="500">
|
|
50
|
+
</a>
|
|
47
51
|
|
|
48
|
-
|
|
52
|
+
Playable here: [https://jkugs.github.io/](https://jkugs.github.io/)
|
|
53
|
+
|
|
54
|
+
Located in the [ext/khetai/dev/sdl-ui](/ext/khetai/dev/sdl-ui) directory.
|
|
55
|
+
|
|
56
|
+
### [fltk-ui](/ext/khetai/dev/fltk-ui)
|
|
57
|
+
|
|
58
|
+
A C++ FLTK GUI that allows manual testing of the AI and gameplay. Supports live reloading of the AI during runtime using `Shift + K`.
|
|
59
|
+
|
|
60
|
+
<img src="ext/khetai/dev/fltk-ui/assets/example_board.png" alt="board" width="500">
|
|
61
|
+
|
|
62
|
+
Located in the [ext/khetai/dev/fltk-ui](/ext/khetai/dev/fltk-ui) directory.
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
## Ruby Gem Notes
|
|
67
|
+
|
|
68
|
+
### Install
|
|
69
|
+
|
|
70
|
+
$ gem install khetai
|
|
49
71
|
|
|
50
72
|
## Development System Requirements
|
|
51
73
|
|
|
52
74
|
To build the gem from source, you'll need:
|
|
53
|
-
- Ruby >= 2.
|
|
75
|
+
- Ruby >= `2.3.0`
|
|
54
76
|
- GCC or compatible C compiler
|
|
55
77
|
- Development headers (usually provided by ruby-dev or ruby-devel package)
|
|
56
78
|
|
|
57
79
|
## Build and Deploy Commands
|
|
58
80
|
|
|
59
|
-
This project uses `asdf` as the version manager for Ruby. However, any Ruby version
|
|
81
|
+
This project uses `asdf` as the version manager for Ruby. However, any Ruby version >= `2.3.0` should work to compile this gem.
|
|
60
82
|
|
|
61
83
|
$ gem install bundler
|
|
62
84
|
$ bundle install
|
|
@@ -64,7 +86,7 @@ This project uses `asdf` as the version manager for Ruby. However, any Ruby vers
|
|
|
64
86
|
$ bundle exec rake build
|
|
65
87
|
$ gem install pkg/khetai-<version>.gem
|
|
66
88
|
|
|
67
|
-
Once tested and verified, bump the version number in
|
|
89
|
+
Once tested and verified, bump the version number in [lib/khetai/version.rb](lib/khetai/version.rb) and commit changes.
|
|
68
90
|
|
|
69
91
|
To release and push to rubygems.org:
|
|
70
92
|
|
|
@@ -74,10 +96,8 @@ To push a pre-built gem manually:
|
|
|
74
96
|
|
|
75
97
|
$ gem push pkg/<gem>
|
|
76
98
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
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.
|
|
99
|
+
---
|
|
80
100
|
|
|
81
|
-
|
|
101
|
+
#### Why Does This Exist?
|
|
82
102
|
|
|
83
|
-
|
|
103
|
+
To build and learn from... 🐢
|
data/ext/khetai/khetai.c
CHANGED
|
@@ -35,7 +35,7 @@ VALUE move(VALUE self, VALUE board_array, VALUE _player, VALUE _max_depth, VALUE
|
|
|
35
35
|
if (array_size != 80) {
|
|
36
36
|
rb_raise(rb_eArgError, "board_array must have exactly 80 elements");
|
|
37
37
|
}
|
|
38
|
-
const char valid_pieces[] = {'L', 'A', 'X', 'P', 'S', '
|
|
38
|
+
const char valid_pieces[] = {'L', 'A', 'X', 'P', 'S', 'l', 'a', 'x', 'p', 's'};
|
|
39
39
|
size_t valid_pieces_count = 10;
|
|
40
40
|
for (unsigned int i = 0; i < array_size; i++) {
|
|
41
41
|
VALUE element = rb_ary_entry(board_array, i);
|
data/ext/khetai/khetai_lib.c
CHANGED
|
@@ -166,11 +166,12 @@ int calculate_score() {
|
|
|
166
166
|
value += pyramid_score;
|
|
167
167
|
value += (rand() % 51) - 25;
|
|
168
168
|
break;
|
|
169
|
-
case SCARAB:
|
|
169
|
+
case SCARAB: {
|
|
170
170
|
int max_distance = 16;
|
|
171
171
|
int base_score = 1000;
|
|
172
172
|
value += (max_distance - distance_from_pharaoh(i, pharaoh_loc[opposite_player(player)])) * base_score / max_distance;
|
|
173
173
|
break;
|
|
174
|
+
}
|
|
174
175
|
case PHARAOH:
|
|
175
176
|
value += pharaoh_score;
|
|
176
177
|
break;
|
data/ext/khetai/khetai_lib.h
CHANGED
data/khetai.gemspec
CHANGED
|
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
|
|
|
17
17
|
# Specify which files should be added to the gem when it is released.
|
|
18
18
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
19
19
|
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
|
20
|
-
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
20
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|ext/khetai/dev)/}) }
|
|
21
21
|
end
|
|
22
22
|
spec.bindir = "exe"
|
|
23
23
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
data/lib/khetai/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: khetai
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.3.
|
|
4
|
+
version: 0.3.5
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- jkugs
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2026-02-14 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description:
|
|
14
14
|
email:
|
|
@@ -26,58 +26,6 @@ files:
|
|
|
26
26
|
- LICENSE.txt
|
|
27
27
|
- README.md
|
|
28
28
|
- Rakefile
|
|
29
|
-
- bin/console
|
|
30
|
-
- bin/setup
|
|
31
|
-
- ext/khetai/dev/CMakeLists.txt
|
|
32
|
-
- ext/khetai/dev/README.md
|
|
33
|
-
- ext/khetai/dev/fltk-ui/Makefile
|
|
34
|
-
- ext/khetai/dev/fltk-ui/Makefile.khetai
|
|
35
|
-
- ext/khetai/dev/fltk-ui/README.md
|
|
36
|
-
- ext/khetai/dev/fltk-ui/ai_loader.cpp
|
|
37
|
-
- ext/khetai/dev/fltk-ui/ai_loader.h
|
|
38
|
-
- ext/khetai/dev/fltk-ui/assets/anubis_red_e.png
|
|
39
|
-
- ext/khetai/dev/fltk-ui/assets/anubis_red_n.png
|
|
40
|
-
- ext/khetai/dev/fltk-ui/assets/anubis_red_s.png
|
|
41
|
-
- ext/khetai/dev/fltk-ui/assets/anubis_red_w.png
|
|
42
|
-
- ext/khetai/dev/fltk-ui/assets/anubis_silver_e.png
|
|
43
|
-
- ext/khetai/dev/fltk-ui/assets/anubis_silver_n.png
|
|
44
|
-
- ext/khetai/dev/fltk-ui/assets/anubis_silver_s.png
|
|
45
|
-
- ext/khetai/dev/fltk-ui/assets/anubis_silver_w.png
|
|
46
|
-
- ext/khetai/dev/fltk-ui/assets/example_board.png
|
|
47
|
-
- ext/khetai/dev/fltk-ui/assets/laser_red_e.png
|
|
48
|
-
- ext/khetai/dev/fltk-ui/assets/laser_red_n.png
|
|
49
|
-
- ext/khetai/dev/fltk-ui/assets/laser_red_s.png
|
|
50
|
-
- ext/khetai/dev/fltk-ui/assets/laser_red_w.png
|
|
51
|
-
- ext/khetai/dev/fltk-ui/assets/laser_silver_e.png
|
|
52
|
-
- ext/khetai/dev/fltk-ui/assets/laser_silver_n.png
|
|
53
|
-
- ext/khetai/dev/fltk-ui/assets/laser_silver_s.png
|
|
54
|
-
- ext/khetai/dev/fltk-ui/assets/laser_silver_w.png
|
|
55
|
-
- ext/khetai/dev/fltk-ui/assets/pharaoh_red.png
|
|
56
|
-
- ext/khetai/dev/fltk-ui/assets/pharaoh_silver.png
|
|
57
|
-
- ext/khetai/dev/fltk-ui/assets/pyramid_red_e.png
|
|
58
|
-
- ext/khetai/dev/fltk-ui/assets/pyramid_red_n.png
|
|
59
|
-
- ext/khetai/dev/fltk-ui/assets/pyramid_red_s.png
|
|
60
|
-
- ext/khetai/dev/fltk-ui/assets/pyramid_red_w.png
|
|
61
|
-
- ext/khetai/dev/fltk-ui/assets/pyramid_silver_e.png
|
|
62
|
-
- ext/khetai/dev/fltk-ui/assets/pyramid_silver_n.png
|
|
63
|
-
- ext/khetai/dev/fltk-ui/assets/pyramid_silver_s.png
|
|
64
|
-
- ext/khetai/dev/fltk-ui/assets/pyramid_silver_w.png
|
|
65
|
-
- ext/khetai/dev/fltk-ui/assets/scarab_red_e.png
|
|
66
|
-
- ext/khetai/dev/fltk-ui/assets/scarab_red_n.png
|
|
67
|
-
- ext/khetai/dev/fltk-ui/assets/scarab_red_s.png
|
|
68
|
-
- ext/khetai/dev/fltk-ui/assets/scarab_red_w.png
|
|
69
|
-
- ext/khetai/dev/fltk-ui/assets/scarab_silver_e.png
|
|
70
|
-
- ext/khetai/dev/fltk-ui/assets/scarab_silver_n.png
|
|
71
|
-
- ext/khetai/dev/fltk-ui/assets/scarab_silver_s.png
|
|
72
|
-
- ext/khetai/dev/fltk-ui/assets/scarab_silver_w.png
|
|
73
|
-
- ext/khetai/dev/fltk-ui/build_khetai.sh
|
|
74
|
-
- ext/khetai/dev/fltk-ui/game_board.cpp
|
|
75
|
-
- ext/khetai/dev/fltk-ui/game_board.h
|
|
76
|
-
- ext/khetai/dev/fltk-ui/game_board_util.cpp
|
|
77
|
-
- ext/khetai/dev/fltk-ui/game_board_util.h
|
|
78
|
-
- ext/khetai/dev/fltk-ui/khet.cpp
|
|
79
|
-
- ext/khetai/dev/main.c
|
|
80
|
-
- ext/khetai/dev/main.rb
|
|
81
29
|
- ext/khetai/extconf.rb
|
|
82
30
|
- ext/khetai/khetai.c
|
|
83
31
|
- ext/khetai/khetai_lib.c
|
data/bin/console
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env ruby
|
|
2
|
-
|
|
3
|
-
require "bundler/setup"
|
|
4
|
-
require "khetai"
|
|
5
|
-
|
|
6
|
-
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
|
-
# with your gem easier. You can also use a different console, if you like.
|
|
8
|
-
|
|
9
|
-
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
10
|
-
# require "pry"
|
|
11
|
-
# Pry.start
|
|
12
|
-
|
|
13
|
-
require "irb"
|
|
14
|
-
IRB.start(__FILE__)
|
data/bin/setup
DELETED
data/ext/khetai/dev/README.md
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
# Dev Tools
|
|
2
|
-
|
|
3
|
-
A few ways to test the khetai_lib...
|
|
4
|
-
|
|
5
|
-
### main.c
|
|
6
|
-
|
|
7
|
-
A small C program to execute a single move from the starting position.
|
|
8
|
-
|
|
9
|
-
### main.rb
|
|
10
|
-
|
|
11
|
-
A small Ruby program that will execute a single move form the starting position.
|
|
12
|
-
|
|
13
|
-
### fltk-ui
|
|
14
|
-
|
|
15
|
-
A C++ FLTK GUI that allows you set up the board however you want and request a move.
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
# Makefile for both the C++ FLTK GUI and the KhetAI lib as a shared object
|
|
2
|
-
|
|
3
|
-
# Compiler settings
|
|
4
|
-
CXX = g++
|
|
5
|
-
CC = gcc
|
|
6
|
-
CXXFLAGS = -std=c++17 $(shell fltk-config --cxxflags) -fPIC -MMD -MP
|
|
7
|
-
CFLAGS = -std=c11 -fPIC -MMD -MP
|
|
8
|
-
LDFLAGS = $(shell fltk-config --ldflags) -lfltk_images -lfltk_png -lfltk_z -ldl
|
|
9
|
-
|
|
10
|
-
# Application name
|
|
11
|
-
APP = khet
|
|
12
|
-
|
|
13
|
-
# Source directory
|
|
14
|
-
SRC_DIR = .
|
|
15
|
-
|
|
16
|
-
# Build directory
|
|
17
|
-
BUILD_DIR = build
|
|
18
|
-
|
|
19
|
-
# Source files
|
|
20
|
-
SRC_CPP = $(wildcard $(SRC_DIR)/*.cpp)
|
|
21
|
-
SRC_C = ../../khetai_lib.c
|
|
22
|
-
|
|
23
|
-
# Object files
|
|
24
|
-
OBJ_CPP = $(patsubst $(SRC_DIR)/%.cpp,$(BUILD_DIR)/%.o,$(SRC_CPP))
|
|
25
|
-
OBJ_C = $(patsubst ../../%.c,$(BUILD_DIR)/%.o,$(SRC_C))
|
|
26
|
-
|
|
27
|
-
# All object files
|
|
28
|
-
OBJ = $(OBJ_CPP) $(OBJ_C)
|
|
29
|
-
|
|
30
|
-
# AI Library
|
|
31
|
-
AI_LIB = libkhetai.so
|
|
32
|
-
|
|
33
|
-
# Default target
|
|
34
|
-
all: $(BUILD_DIR) $(APP) $(AI_LIB)
|
|
35
|
-
|
|
36
|
-
# Create the build directory
|
|
37
|
-
$(BUILD_DIR):
|
|
38
|
-
mkdir -p $(BUILD_DIR)
|
|
39
|
-
|
|
40
|
-
# Link the application
|
|
41
|
-
$(APP): $(OBJ)
|
|
42
|
-
$(CXX) -o $@ $^ $(LDFLAGS)
|
|
43
|
-
|
|
44
|
-
# Compile C++ source files into object files
|
|
45
|
-
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.cpp
|
|
46
|
-
$(CXX) -c $< -o $@ $(CXXFLAGS)
|
|
47
|
-
|
|
48
|
-
# Compile C source files into object files
|
|
49
|
-
$(BUILD_DIR)/%.o: ../../%.c
|
|
50
|
-
$(CC) -c $< -o $@ $(CFLAGS)
|
|
51
|
-
|
|
52
|
-
# Compile AI library
|
|
53
|
-
$(AI_LIB): $(OBJ_C)
|
|
54
|
-
$(CC) -shared -o $@ $^ $(CFLAGS)
|
|
55
|
-
|
|
56
|
-
# Include generated dependency files
|
|
57
|
-
-include $(OBJ_CPP:.o=.d)
|
|
58
|
-
-include $(OBJ_C:.o=.d)
|
|
59
|
-
|
|
60
|
-
# Clean target
|
|
61
|
-
clean:
|
|
62
|
-
rm -f $(OBJ) $(APP) $(AI_LIB) $(BUILD_DIR)/*.d
|
|
63
|
-
rm -rf $(BUILD_DIR)
|
|
64
|
-
|
|
65
|
-
.PHONY: all clean
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
# Makefile for the KhetAI lib as a shared object
|
|
2
|
-
# Used for hot reloading while the GUI is running
|
|
3
|
-
|
|
4
|
-
# Compiler settings
|
|
5
|
-
CC = gcc
|
|
6
|
-
CFLAGS = -std=c11 -fPIC -O3 -MMD -MP
|
|
7
|
-
|
|
8
|
-
# Source directory
|
|
9
|
-
SRC_DIR = ../../
|
|
10
|
-
|
|
11
|
-
# Build directory
|
|
12
|
-
BUILD_DIR = build_khetai
|
|
13
|
-
|
|
14
|
-
# Source files
|
|
15
|
-
SRC = $(SRC_DIR)khetai_lib.c
|
|
16
|
-
|
|
17
|
-
# Object files
|
|
18
|
-
OBJ = $(BUILD_DIR)/khetai_lib.o
|
|
19
|
-
|
|
20
|
-
# Library name
|
|
21
|
-
LIB = libkhetai.so
|
|
22
|
-
|
|
23
|
-
# Default target
|
|
24
|
-
all: $(BUILD_DIR) $(LIB)
|
|
25
|
-
|
|
26
|
-
# Create the build directory
|
|
27
|
-
$(BUILD_DIR):
|
|
28
|
-
mkdir -p $(BUILD_DIR)
|
|
29
|
-
|
|
30
|
-
# Compile the library
|
|
31
|
-
$(LIB): $(OBJ)
|
|
32
|
-
$(CC) -shared -o $@ $^ $(CFLAGS)
|
|
33
|
-
|
|
34
|
-
# Compile C source files into object files
|
|
35
|
-
$(BUILD_DIR)/%.o: $(SRC_DIR)%.c
|
|
36
|
-
$(CC) -c $< -o $@ $(CFLAGS)
|
|
37
|
-
|
|
38
|
-
# Include generated dependency files
|
|
39
|
-
-include $(OBJ:.o=.d)
|
|
40
|
-
|
|
41
|
-
# Clean target
|
|
42
|
-
clean:
|
|
43
|
-
rm -f $(OBJ) $(LIB) $(BUILD_DIR)/*.d
|
|
44
|
-
rm -rf $(BUILD_DIR)
|
|
45
|
-
|
|
46
|
-
.PHONY: all clean
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
# KhetAI Test Harness
|
|
2
|
-
|
|
3
|
-
## Overview
|
|
4
|
-
|
|
5
|
-
The KhetAI Test Harness provides a GUI for interacting with the KhetAI library. It is built in C++ using the Fast Light Toolkit ([FLTK](https://www.fltk.org/)).
|
|
6
|
-
|
|
7
|
-
### Hot Reload KhetAI Lib
|
|
8
|
-
|
|
9
|
-
- While the GUI is running, you can edit the AI code and reload it into the app by pressing: `Shift + k`
|
|
10
|
-
|
|
11
|
-
### Select and Move Piece
|
|
12
|
-
|
|
13
|
-
- **Click** a square with a piece on it.
|
|
14
|
-
- **Click** another square. If there is a piece on it, the two pieces will swap. Otherwise, the piece from the first square will just move to the newly selected square.
|
|
15
|
-
|
|
16
|
-
### Rotate Piece
|
|
17
|
-
|
|
18
|
-
- **Arrow Keys**: Rotate a piece after it has been clicked. Use the following keys to rotate the selected piece:
|
|
19
|
-
- `Left Arrow`: Rotate piece counter-clockwise
|
|
20
|
-
- `Right Arrow`: Rotate piece clockwise
|
|
21
|
-
|
|
22
|
-
### Fire the Laser
|
|
23
|
-
|
|
24
|
-
- `Space`: Fires the laser from whichever is selected. This is just used for visualization purposes.
|
|
25
|
-
|
|
26
|
-
### Request AI Move
|
|
27
|
-
|
|
28
|
-
- `Enter`: Uses `khetai_lib` to determine a move for Red. The pieces will move and the laser will fire automatically once it finishes.
|
|
29
|
-
|
|
30
|
-
### Reset Pieces
|
|
31
|
-
|
|
32
|
-
- Reset all pieces back to their original places by pressing: `r`
|
|
33
|
-
|
|
34
|
-

|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
#include "ai_loader.h"
|
|
2
|
-
|
|
3
|
-
AILoader::AILoader(const std::string &lib_path) : handle(nullptr) {
|
|
4
|
-
load_library(lib_path);
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
AILoader::~AILoader() {
|
|
8
|
-
if (handle) {
|
|
9
|
-
dlclose(handle);
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
void AILoader::load_library(const std::string &lib_path) {
|
|
14
|
-
handle = dlopen(lib_path.c_str(), RTLD_LAZY);
|
|
15
|
-
if (!handle) {
|
|
16
|
-
throw std::runtime_error("Failed to load KhetAI: " + std::string(dlerror()));
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
void AILoader::reload_library(const std::string &lib_path) {
|
|
21
|
-
if (handle) {
|
|
22
|
-
dlclose(handle);
|
|
23
|
-
}
|
|
24
|
-
load_library(lib_path);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
void *AILoader::get_symbol(const std::string &symbol_name) {
|
|
28
|
-
void *symbol = dlsym(handle, symbol_name.c_str());
|
|
29
|
-
check_error();
|
|
30
|
-
return symbol;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
void AILoader::check_error() {
|
|
34
|
-
const char *error = dlerror();
|
|
35
|
-
if (error) {
|
|
36
|
-
throw std::runtime_error("Error in dynamic loading: " + std::string(error));
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
void (*AILoader::get_init_zobrist())() {
|
|
41
|
-
return reinterpret_cast<void (*)()>(get_symbol("init_zobrist"));
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
void (*AILoader::get_reset_undo())() {
|
|
45
|
-
return reinterpret_cast<void (*)()>(get_symbol("reset_undo"));
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
void (*AILoader::get_setup_board())(char **) {
|
|
49
|
-
return reinterpret_cast<void (*)(char **)>(get_symbol("setup_board"));
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
void (*AILoader::get_print_board())() {
|
|
53
|
-
return reinterpret_cast<void (*)()>(get_symbol("print_board"));
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
void (*AILoader::get_set_time_parameters())(int, time_t) {
|
|
57
|
-
return reinterpret_cast<void (*)(int, time_t)>(get_symbol("set_time_parameters"));
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
Move (*AILoader::get_alphabeta_root())(int, enum Player) {
|
|
61
|
-
return reinterpret_cast<Move (*)(int, enum Player)>(get_symbol("alphabeta_root"));
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
void (*AILoader::get_make_move())(Move) {
|
|
65
|
-
return reinterpret_cast<void (*)(Move)>(get_symbol("make_move"));
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
int (*AILoader::get_get_start())(Move) {
|
|
69
|
-
return reinterpret_cast<int (*)(Move)>(get_symbol("get_start_wrapper"));
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
int (*AILoader::get_get_end())(Move) {
|
|
73
|
-
return reinterpret_cast<int (*)(Move)>(get_symbol("get_end_wrapper"));
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
int (*AILoader::get_get_rotation())(Move) {
|
|
77
|
-
return reinterpret_cast<int (*)(Move)>(get_symbol("get_rotation_wrapper"));
|
|
78
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
#ifndef AI_LOADER_H
|
|
2
|
-
#define AI_LOADER_H
|
|
3
|
-
|
|
4
|
-
#include "../../khetai_lib.h"
|
|
5
|
-
#include <dlfcn.h>
|
|
6
|
-
#include <stdexcept>
|
|
7
|
-
#include <string>
|
|
8
|
-
|
|
9
|
-
class AILoader {
|
|
10
|
-
public:
|
|
11
|
-
AILoader(const std::string &lib_path);
|
|
12
|
-
~AILoader();
|
|
13
|
-
|
|
14
|
-
void (*get_init_zobrist())();
|
|
15
|
-
void (*get_reset_undo())();
|
|
16
|
-
void (*get_setup_board())(char **);
|
|
17
|
-
void (*get_print_board())();
|
|
18
|
-
void (*get_set_time_parameters())(int, time_t);
|
|
19
|
-
Move (*get_alphabeta_root())(int, enum Player);
|
|
20
|
-
void (*get_make_move())(Move);
|
|
21
|
-
int (*get_get_start())(Move);
|
|
22
|
-
int (*get_get_end())(Move);
|
|
23
|
-
int (*get_get_rotation())(Move);
|
|
24
|
-
void reload_library(const std::string &lib_path);
|
|
25
|
-
|
|
26
|
-
private:
|
|
27
|
-
void *handle;
|
|
28
|
-
void load_library(const std::string &lib_path);
|
|
29
|
-
void *get_symbol(const std::string &symbol_name);
|
|
30
|
-
void check_error();
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
#endif // AI_LOADER_H
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|