khetai 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +2 -1
- data/ext/khetai/khetai.c +2 -2
- data/ext/khetai/khetai_lib.c +12 -8
- data/ext/khetai/khetai_lib.h +2 -1
- 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: 152a53d7588c5ecc8b763bf457852092ddebc3b10b2de158aa25695b1ce8436e
|
4
|
+
data.tar.gz: 59de4c1797063aa6d952cdc3c954b093e63a5ad874c605d891532da32fb7cd77
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a59d6d2ee6d67b3938e9fe2caa8270094dbd88f2a36efbef9c70824da7684b61baca3b64ece435d659b2c83e54940c644b67acfd1efbcbdfef2a0d32355a36c1
|
7
|
+
data.tar.gz: b92b7efea628fc6cc072b9ff74dfd3a9156c6ef1a9bec5fcc1e86d801254e1fd445d914f00c43399afa3b1ab4e3190dd435703c7798e811ad3645831cc06f059
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -51,6 +51,7 @@ 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
55
|
|
55
56
|
To release and push to rubygems.org:
|
56
57
|
|
@@ -63,4 +64,4 @@ There is a GUI test harness written in C++ using FLTK available in the `ext/khet
|
|
63
64
|
|
64
65
|
### Why does this exist?
|
65
66
|
|
66
|
-
|
67
|
+
As something to work on and learn from.
|
data/ext/khetai/khetai.c
CHANGED
@@ -40,7 +40,7 @@ VALUE move(VALUE self, VALUE board_array, VALUE _player, VALUE _max_depth, VALUE
|
|
40
40
|
VALUE element = rb_ary_entry(board_array, i);
|
41
41
|
if (!RB_TYPE_P(element, T_STRING) || RSTRING_LEN(element) != 2)
|
42
42
|
{
|
43
|
-
rb_raise(rb_eArgError, "each element in
|
43
|
+
rb_raise(rb_eArgError, "each element in board_array must be 2 characters");
|
44
44
|
}
|
45
45
|
|
46
46
|
// check if element in board_array is a valid string
|
@@ -56,7 +56,7 @@ VALUE move(VALUE self, VALUE board_array, VALUE _player, VALUE _max_depth, VALUE
|
|
56
56
|
}
|
57
57
|
if (!is_valid)
|
58
58
|
{
|
59
|
-
rb_raise(rb_eArgError, "each element in
|
59
|
+
rb_raise(rb_eArgError, "each element in board_array must be a valid piece (example: 'p1') or empty ('--')");
|
60
60
|
}
|
61
61
|
}
|
62
62
|
|
data/ext/khetai/khetai_lib.c
CHANGED
@@ -11,6 +11,7 @@ Square board[120] = {0};
|
|
11
11
|
int pharaoh_loc[2] = {0};
|
12
12
|
enum Player whose_turn;
|
13
13
|
enum Player starter;
|
14
|
+
int initial_depth = 0;
|
14
15
|
|
15
16
|
Move undo_moves[MAX_DEPTH] = {0};
|
16
17
|
int undo_capture_indices[MAX_DEPTH] = {0};
|
@@ -29,6 +30,7 @@ Move alphabeta_root(int depth, enum Player player)
|
|
29
30
|
{
|
30
31
|
whose_turn = player;
|
31
32
|
starter = player;
|
33
|
+
initial_depth = depth;
|
32
34
|
int best_score = -MAX_SCORE;
|
33
35
|
Move best_move = (Move)0;
|
34
36
|
int alpha = -MAX_SCORE;
|
@@ -71,8 +73,10 @@ int alphabeta(int depth, enum Player player, int alpha, int beta)
|
|
71
73
|
int alpha_orig = alpha;
|
72
74
|
Move valid_moves[NUM_VALID_MOVES] = {0};
|
73
75
|
int vi = 0;
|
76
|
+
|
77
|
+
int table_depth = initial_depth - depth;
|
74
78
|
HashEntry *entry = search_table(hashes[move_num]);
|
75
|
-
if (entry->key == hashes[move_num] && entry->depth
|
79
|
+
if (entry->key == hashes[move_num] && entry->depth > table_depth)
|
76
80
|
{
|
77
81
|
if (entry->flag == EXACT)
|
78
82
|
return entry->score;
|
@@ -123,19 +127,19 @@ int alphabeta(int depth, enum Player player, int alpha, int beta)
|
|
123
127
|
else if (best_score >= beta)
|
124
128
|
flag = ALPHA;
|
125
129
|
|
126
|
-
|
130
|
+
|
131
|
+
insert_table(entry, hashes[move_num], table_depth, flag, best_score, best_move);
|
127
132
|
return best_score;
|
128
133
|
}
|
129
134
|
|
130
|
-
void insert_table(uint64_t key, int
|
135
|
+
void insert_table(HashEntry *entry, uint64_t key, int table_depth, int flag, int score, Move move)
|
131
136
|
{
|
132
|
-
HashEntry *entry = search_table(key);
|
133
137
|
if (entry->key != 0)
|
134
138
|
{
|
135
|
-
if (
|
139
|
+
if (table_depth > entry->depth)
|
136
140
|
{
|
137
141
|
entry->key = key;
|
138
|
-
entry->depth =
|
142
|
+
entry->depth = table_depth;
|
139
143
|
entry->flag = flag;
|
140
144
|
entry->score = score;
|
141
145
|
entry->move = move;
|
@@ -144,7 +148,7 @@ void insert_table(uint64_t key, int depth, int flag, int score, Move move)
|
|
144
148
|
else
|
145
149
|
{
|
146
150
|
entry->key = key;
|
147
|
-
entry->depth =
|
151
|
+
entry->depth = table_depth;
|
148
152
|
entry->flag = flag;
|
149
153
|
entry->score = score;
|
150
154
|
entry->move = move;
|
@@ -154,7 +158,7 @@ void insert_table(uint64_t key, int depth, int flag, int score, Move move)
|
|
154
158
|
int calculate_score()
|
155
159
|
{
|
156
160
|
int score = 0;
|
157
|
-
int anubis_score =
|
161
|
+
int anubis_score = 800;
|
158
162
|
int pyramid_score = 1000;
|
159
163
|
int pharaoh_score = 100000;
|
160
164
|
for (int i = 0; i < 120; i++)
|
data/ext/khetai/khetai_lib.h
CHANGED
@@ -38,6 +38,7 @@ enum Orientation
|
|
38
38
|
|
39
39
|
extern enum Player whose_turn;
|
40
40
|
extern enum Player starter;
|
41
|
+
extern int initial_depth;
|
41
42
|
|
42
43
|
// north, east, south, west, diagonals
|
43
44
|
static const int directions[8] = {-12, 1, 12, -1, (12 + 1), (12 - 1), (-12 + 1), (-12 - 1)};
|
@@ -223,6 +224,6 @@ typedef struct HashEntry
|
|
223
224
|
|
224
225
|
extern HashEntry table[TABLE_SIZE];
|
225
226
|
static inline HashEntry *search_table(uint64_t key) { return &table[key % TABLE_SIZE]; };
|
226
|
-
void insert_table(uint64_t key, int depth, int flag, int score, Move move);
|
227
|
+
void insert_table(HashEntry *entry, uint64_t key, int depth, int flag, int score, Move move);
|
227
228
|
|
228
229
|
#endif // KHET_LIB_H_INCLUDED
|
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.2.
|
4
|
+
version: 0.2.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-
|
11
|
+
date: 2024-11-03 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|