khetai 0.1.7 → 0.1.8
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/.gitignore +5 -0
- data/Gemfile.lock +2 -2
- data/README.md +18 -12
- data/ext/khetai/khetai_lib.c +3 -3
- data/ext/khetai/khetai_lib.h +25 -25
- data/lib/khetai/version.rb +1 -1
- metadata +3 -4
- data/README_ORIGINAL.md +0 -40
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9a457af540807b38fdb38ab47052c7b8b7b1133d5ffe8970a6390ccf7aace592
|
4
|
+
data.tar.gz: 3cdb7b43ac5644d6e8739ff1c2f0f126b2a597a9c72602dc9e692cd3e09dae70
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5234eec49f64360cb846b61fd5754e9faa5f2a8e343e876e9f9be86c7c04efda27e629309308c76417f1d4e6aacd4d889dc87fac9bfc5b61416895714c0024a2
|
7
|
+
data.tar.gz: e81fff6aff170e53cd62e3d8ef2e8783bf8f297faff6a6d66c5a001953f7276aa96c01919ee82ce24d51f4136e7e96d98e500ebe7d33ce5b0778be1b9b13bd9f
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,18 +1,17 @@
|
|
1
1
|
# KhetAI
|
2
2
|
|
3
|
-
##
|
4
|
-
|
5
|
-
gem install khetai
|
6
|
-
```
|
3
|
+
## Installation
|
4
|
+
|
5
|
+
$ gem install khetai
|
7
6
|
|
8
7
|
## Usage
|
9
|
-
```
|
8
|
+
```ruby
|
10
9
|
require 'khetai'
|
11
10
|
move = KhetAI.move(board, whose_turn, max_search_depth, max_search_time)
|
12
11
|
```
|
13
12
|
|
14
13
|
## Example
|
15
|
-
```
|
14
|
+
```ruby
|
16
15
|
require 'khetai'
|
17
16
|
|
18
17
|
# initial board setup:
|
@@ -42,11 +41,18 @@ move = KhetAI.move(board, whose_turn, max_search_depth, max_search_time)
|
|
42
41
|
# move[2] = rotation (1, -1, 0) (clockwise, anticlockwise, none)
|
43
42
|
```
|
44
43
|
|
44
|
+
## Development
|
45
|
+
The internals of the gem are written in C, located in `ext/khetai`.
|
46
|
+
|
47
|
+
|
45
48
|
## Build and Deploy Commands
|
46
|
-
```
|
47
|
-
bundle exec rake compile
|
48
|
-
bundle exec rake build
|
49
|
-
bundle exec rake release
|
50
49
|
|
51
|
-
|
52
|
-
|
50
|
+
$ bundle exec rake compile
|
51
|
+
$ bundle exec rake build
|
52
|
+
$ gem install pkg/khetai-<version>.gem
|
53
|
+
|
54
|
+
|
55
|
+
To release and push to rubygems.org:
|
56
|
+
|
57
|
+
$ bundle exec rake release
|
58
|
+
$ gem push pkg/<gem>
|
data/ext/khetai/khetai_lib.c
CHANGED
@@ -167,7 +167,7 @@ int calculate_score()
|
|
167
167
|
value += rand() % 20;
|
168
168
|
break;
|
169
169
|
case Scarab:
|
170
|
-
value += 100 /
|
170
|
+
value += (100 / distance_from_pharaoh(i, pharaoh_loc[opposite_player(get_owner(s))])) * 10;
|
171
171
|
value += rand() % 10;
|
172
172
|
break;
|
173
173
|
case Pharaoh:
|
@@ -225,7 +225,7 @@ void make_move(Move move)
|
|
225
225
|
hash ^= keys[board[start]][start];
|
226
226
|
|
227
227
|
if (get_piece(moving_piece) == Pharaoh)
|
228
|
-
pharaoh_loc[
|
228
|
+
pharaoh_loc[get_owner(moving_piece)] = end;
|
229
229
|
}
|
230
230
|
|
231
231
|
undo_moves[undo_index] = new_move(end, start, -rotation);
|
@@ -314,7 +314,7 @@ void undo_move()
|
|
314
314
|
board[end] = moving_piece;
|
315
315
|
|
316
316
|
if (get_piece(moving_piece) == Pharaoh)
|
317
|
-
pharaoh_loc[get_owner(
|
317
|
+
pharaoh_loc[get_owner(moving_piece)] = end;
|
318
318
|
}
|
319
319
|
checkmate = false;
|
320
320
|
}
|
data/ext/khetai/khetai_lib.h
CHANGED
@@ -83,27 +83,27 @@ static const int on_board[120] = {
|
|
83
83
|
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0,
|
84
84
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
85
85
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
86
|
+
void setup_board(char *init_board[120]);
|
87
|
+
Square str_to_square(char *str);
|
88
|
+
void print_board();
|
89
|
+
void print_piece(Square s);
|
90
|
+
void reset_undo();
|
91
|
+
|
92
|
+
void find_valid_moves(Move *valid_moves, int *vi);
|
93
|
+
void find_valid_anubis_pyramid_moves(int i, Move *valid_moves, int *vi);
|
94
|
+
void find_valid_scarab_moves(int i, Move *valid_moves, int *vi);
|
95
|
+
void find_valid_pharaoh_moves(int i, Move *valid_moves, int *vi);
|
96
|
+
void find_valid_sphinx_moves(int i, Move *valid_moves, int *vi);
|
97
|
+
|
98
|
+
Move alphabeta_root(int depth, enum Player player);
|
99
|
+
int alphabeta(int depth, enum Player player, int alpha, int beta);
|
100
|
+
int calculate_score();
|
101
|
+
int distance_from_pharaoh(int i, int p);
|
102
|
+
|
103
|
+
void make_move(Move move);
|
104
|
+
void undo_move();
|
105
|
+
void fire_laser(uint64_t *hash);
|
106
|
+
bool is_move_legal(Move move);
|
107
107
|
|
108
108
|
static inline bool is_piece(Square s) { return s > 0; }
|
109
109
|
|
@@ -169,8 +169,8 @@ extern uint64_t turn_key;
|
|
169
169
|
extern int move_num;
|
170
170
|
extern bool checkmate;
|
171
171
|
|
172
|
-
|
173
|
-
|
172
|
+
void init_zobrist();
|
173
|
+
uint64_t get_board_hash();
|
174
174
|
static uint64_t seed = 1070372;
|
175
175
|
static inline uint64_t random_number()
|
176
176
|
{
|
@@ -196,6 +196,6 @@ typedef struct HashEntry
|
|
196
196
|
|
197
197
|
extern HashEntry table[TABLE_SIZE];
|
198
198
|
static inline HashEntry *search_table(uint64_t key) { return &table[key % TABLE_SIZE]; };
|
199
|
-
|
199
|
+
void insert_table(uint64_t key, int depth, int flag, int score, Move move);
|
200
200
|
|
201
|
-
#endif // KHET_LIB_H_INCLUDED
|
201
|
+
#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.1.
|
4
|
+
version: 0.1.8
|
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: 2024-03-16 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|
@@ -23,7 +23,6 @@ files:
|
|
23
23
|
- Gemfile.lock
|
24
24
|
- LICENSE.txt
|
25
25
|
- README.md
|
26
|
-
- README_ORIGINAL.md
|
27
26
|
- Rakefile
|
28
27
|
- bin/console
|
29
28
|
- bin/setup
|
@@ -58,7 +57,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
58
57
|
- !ruby/object:Gem::Version
|
59
58
|
version: '0'
|
60
59
|
requirements: []
|
61
|
-
rubygems_version: 3.
|
60
|
+
rubygems_version: 3.4.10
|
62
61
|
signing_key:
|
63
62
|
specification_version: 4
|
64
63
|
summary: Khet AI
|
data/README_ORIGINAL.md
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
# Khetai
|
2
|
-
|
3
|
-
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/khetai`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
6
|
-
|
7
|
-
## Installation
|
8
|
-
|
9
|
-
Add this line to your application's Gemfile:
|
10
|
-
|
11
|
-
```ruby
|
12
|
-
gem 'khetai'
|
13
|
-
```
|
14
|
-
|
15
|
-
And then execute:
|
16
|
-
|
17
|
-
$ bundle install
|
18
|
-
|
19
|
-
Or install it yourself as:
|
20
|
-
|
21
|
-
$ gem install khetai
|
22
|
-
|
23
|
-
## Usage
|
24
|
-
|
25
|
-
TODO: Write usage instructions here
|
26
|
-
|
27
|
-
## Development
|
28
|
-
|
29
|
-
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
-
|
31
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
-
|
33
|
-
## Contributing
|
34
|
-
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/khetai.
|
36
|
-
|
37
|
-
|
38
|
-
## License
|
39
|
-
|
40
|
-
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|