khetai 0.3.0 → 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/Gemfile.lock +1 -1
- data/ext/khetai/dev/fltk-ui/game_board_util.cpp +3 -11
- data/ext/khetai/khetai.c +9 -2
- data/ext/khetai/khetai_lib.c +32 -15
- data/ext/khetai/khetai_lib.h +3 -40
- data/lib/khetai/version.rb +1 -1
- metadata +2 -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/Gemfile.lock
CHANGED
@@ -96,14 +96,6 @@ Move call_ai_move(AILoader &ai_loader, const std::vector<std::vector<std::string
|
|
96
96
|
}
|
97
97
|
|
98
98
|
void get_row_col(int index, int &row, int &col) {
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
int adjusted_index = index;
|
103
|
-
|
104
|
-
int row_with_border = adjusted_index / width_with_border;
|
105
|
-
int col_with_border = adjusted_index % width_with_border;
|
106
|
-
|
107
|
-
row = row_with_border - border_width;
|
108
|
-
col = col_with_border - border_width;
|
109
|
-
}
|
99
|
+
row = (index / 12) - 1;
|
100
|
+
col = (index % 12) - 1;
|
101
|
+
}
|
data/ext/khetai/khetai.c
CHANGED
@@ -3,6 +3,13 @@
|
|
3
3
|
#include <stdlib.h>
|
4
4
|
#include <time.h>
|
5
5
|
|
6
|
+
static int convert_index(int i) {
|
7
|
+
int row = (i / 12) - 1;
|
8
|
+
int col = (i % 12) - 1;
|
9
|
+
|
10
|
+
return (row * 10) + col;
|
11
|
+
}
|
12
|
+
|
6
13
|
VALUE move(VALUE self, VALUE board_array, VALUE _player, VALUE _max_depth, VALUE _max_time) {
|
7
14
|
// verify parameters
|
8
15
|
int player = NUM2INT(_player);
|
@@ -90,8 +97,8 @@ VALUE move(VALUE self, VALUE board_array, VALUE _player, VALUE _max_depth, VALUE
|
|
90
97
|
make_move(best_move);
|
91
98
|
|
92
99
|
VALUE out = rb_ary_new2(3);
|
93
|
-
rb_ary_store(out, 0, INT2NUM(get_start(best_move)));
|
94
|
-
rb_ary_store(out, 1, INT2NUM(get_end(best_move)));
|
100
|
+
rb_ary_store(out, 0, INT2NUM(convert_index(get_start(best_move))));
|
101
|
+
rb_ary_store(out, 1, INT2NUM(convert_index(get_end(best_move))));
|
95
102
|
rb_ary_store(out, 2, INT2NUM(get_rotation(best_move)));
|
96
103
|
|
97
104
|
return out;
|
data/ext/khetai/khetai_lib.c
CHANGED
@@ -6,26 +6,43 @@
|
|
6
6
|
int max_time;
|
7
7
|
time_t start_time;
|
8
8
|
|
9
|
-
Square board[120] = {0};
|
10
|
-
int pharaoh_loc[2] = {0};
|
11
|
-
enum Player whose_turn;
|
12
|
-
enum Player starter;
|
13
|
-
int initial_depth = 0;
|
9
|
+
static Square board[120] = {0};
|
10
|
+
static int pharaoh_loc[2] = {0};
|
11
|
+
static enum Player whose_turn;
|
12
|
+
static enum Player starter;
|
13
|
+
static int initial_depth = 0;
|
14
14
|
|
15
|
-
Move undo_moves[MAX_DEPTH] = {0};
|
16
|
-
int undo_capture_indices[MAX_DEPTH] = {0};
|
17
|
-
Square undo_capture_squares[MAX_DEPTH] = {0};
|
15
|
+
static Move undo_moves[MAX_DEPTH] = {0};
|
16
|
+
static int undo_capture_indices[MAX_DEPTH] = {0};
|
17
|
+
static Square undo_capture_squares[MAX_DEPTH] = {0};
|
18
18
|
|
19
19
|
PieceTracker piece_trackers[2] = {0};
|
20
20
|
|
21
21
|
HashEntry table[TABLE_SIZE] = {0};
|
22
|
-
uint64_t hashes[MAX_DEPTH] = {0};
|
23
|
-
uint64_t keys[0xFF][120] = {0};
|
24
|
-
uint64_t turn_key = 0;
|
25
|
-
|
26
|
-
int undo_index = 0;
|
27
|
-
int hashes_index = 0;
|
28
|
-
bool checkmate = false;
|
22
|
+
static uint64_t hashes[MAX_DEPTH] = {0};
|
23
|
+
static uint64_t keys[0xFF][120] = {0};
|
24
|
+
static uint64_t turn_key = 0;
|
25
|
+
|
26
|
+
static int undo_index = 0;
|
27
|
+
static int hashes_index = 0;
|
28
|
+
static bool checkmate = false;
|
29
|
+
|
30
|
+
static int alphabeta(int depth, enum Player player, int alpha, int beta);
|
31
|
+
static void insert_table(HashEntry *entry, uint64_t key, int depth, int flag, int score, Move move);
|
32
|
+
static int calculate_score(void);
|
33
|
+
static int distance_from_pharaoh(int i, int p);
|
34
|
+
static void fire_laser(uint64_t *hash);
|
35
|
+
static void undo_move();
|
36
|
+
static void find_valid_moves(Move *valid_moves, int *vi);
|
37
|
+
static void find_valid_anubis_pyramid_moves(int i, Move *valid_moves, int *vi);
|
38
|
+
static void find_valid_scarab_moves(int i, Move *valid_moves, int *vi);
|
39
|
+
static void find_valid_pharaoh_moves(int i, Move *valid_moves, int *vi);
|
40
|
+
static void find_valid_sphinx_moves(int i, Move *valid_moves, int *vi);
|
41
|
+
static uint64_t get_board_hash();
|
42
|
+
static void init_piece_trackers();
|
43
|
+
static bool is_move_legal(Move move);
|
44
|
+
static Square str_to_square(char *str);
|
45
|
+
static void print_piece(Square s);
|
29
46
|
|
30
47
|
Move alphabeta_root(int depth, enum Player player) {
|
31
48
|
whose_turn = player;
|
data/ext/khetai/khetai_lib.h
CHANGED
@@ -34,23 +34,11 @@ enum Orientation {
|
|
34
34
|
WEST
|
35
35
|
};
|
36
36
|
|
37
|
-
extern enum Player whose_turn;
|
38
|
-
extern enum Player starter;
|
39
|
-
extern int initial_depth;
|
40
|
-
|
41
37
|
// north, east, south, west, diagonals
|
42
38
|
static const int directions[8] = {-12, 1, 12, -1, (12 + 1), (12 - 1), (-12 + 1), (-12 - 1)};
|
43
39
|
static const int rotations[2] = {1, -1};
|
44
40
|
static const int sphinx_loc[2] = {106, 13};
|
45
41
|
|
46
|
-
extern int pharaoh_loc[2];
|
47
|
-
|
48
|
-
extern Square board[120];
|
49
|
-
extern Move undo_moves[MAX_DEPTH];
|
50
|
-
extern int undo_capture_indices[MAX_DEPTH];
|
51
|
-
extern Square undo_capture_squares[MAX_DEPTH];
|
52
|
-
extern int undo_index;
|
53
|
-
|
54
42
|
static const int can_move[2][120] = {
|
55
43
|
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
56
44
|
0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0,
|
@@ -105,23 +93,6 @@ void print_board();
|
|
105
93
|
}
|
106
94
|
#endif
|
107
95
|
|
108
|
-
Square str_to_square(char *str);
|
109
|
-
void print_piece(Square s);
|
110
|
-
|
111
|
-
void find_valid_moves(Move *valid_moves, int *vi);
|
112
|
-
void find_valid_anubis_pyramid_moves(int i, Move *valid_moves, int *vi);
|
113
|
-
void find_valid_scarab_moves(int i, Move *valid_moves, int *vi);
|
114
|
-
void find_valid_pharaoh_moves(int i, Move *valid_moves, int *vi);
|
115
|
-
void find_valid_sphinx_moves(int i, Move *valid_moves, int *vi);
|
116
|
-
|
117
|
-
int alphabeta(int depth, enum Player player, int alpha, int beta);
|
118
|
-
int calculate_score();
|
119
|
-
int distance_from_pharaoh(int i, int p);
|
120
|
-
|
121
|
-
void undo_move();
|
122
|
-
void fire_laser(uint64_t *hash);
|
123
|
-
bool is_move_legal(Move move);
|
124
|
-
|
125
96
|
static inline bool is_piece(Square s) { return s > 0; }
|
126
97
|
|
127
98
|
static inline enum Player get_owner(Square s) { return (enum Player)(s >> 1 & 0x1); }
|
@@ -186,13 +157,6 @@ static const int reflections[4][5][4] = {
|
|
186
157
|
{DEAD, DEAD, DEAD, DEAD},
|
187
158
|
{ABSORBED, ABSORBED, ABSORBED, ABSORBED}}};
|
188
159
|
|
189
|
-
extern uint64_t keys[0xFF][120];
|
190
|
-
extern uint64_t hashes[MAX_DEPTH];
|
191
|
-
extern uint64_t turn_key;
|
192
|
-
extern int hashes_index;
|
193
|
-
extern bool checkmate;
|
194
|
-
|
195
|
-
uint64_t get_board_hash();
|
196
160
|
static uint64_t seed = 1070372;
|
197
161
|
static inline uint64_t random_number() {
|
198
162
|
seed ^= seed >> 12;
|
@@ -201,7 +165,8 @@ static inline uint64_t random_number() {
|
|
201
165
|
return seed * 0x2545F4914F6CDD1DLL;
|
202
166
|
}
|
203
167
|
|
204
|
-
#define TABLE_SIZE
|
168
|
+
#define TABLE_SIZE 0x400000
|
169
|
+
#define TABLE_MASK 0x3FFFFF
|
205
170
|
|
206
171
|
#define EXACT 0
|
207
172
|
#define LOWERBOUND 1
|
@@ -215,8 +180,7 @@ typedef struct HashEntry {
|
|
215
180
|
} HashEntry;
|
216
181
|
|
217
182
|
extern HashEntry table[TABLE_SIZE];
|
218
|
-
static inline HashEntry *search_table(uint64_t key) { return &table[key
|
219
|
-
void insert_table(HashEntry *entry, uint64_t key, int depth, int flag, int score, Move move);
|
183
|
+
static inline HashEntry *search_table(uint64_t key) { return &table[key & TABLE_MASK]; };
|
220
184
|
|
221
185
|
#define EPT 0xFF
|
222
186
|
typedef struct PieceTracker {
|
@@ -224,7 +188,6 @@ typedef struct PieceTracker {
|
|
224
188
|
uint8_t board_idx_position[120];
|
225
189
|
} PieceTracker;
|
226
190
|
extern PieceTracker piece_trackers[2];
|
227
|
-
void init_piece_trackers();
|
228
191
|
|
229
192
|
static inline uint8_t get_board_index(enum Player player, uint8_t pos_idx) { return piece_trackers[player].positions[pos_idx]; }
|
230
193
|
static inline uint8_t get_position_index(enum Player player, uint8_t board_idx) { return piece_trackers[player].board_idx_position[board_idx]; }
|
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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jkugs
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-12-
|
11
|
+
date: 2024-12-07 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|