-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbook_generator.jai
77 lines (65 loc) · 1.81 KB
/
book_generator.jai
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// generates an opening book based
// off of the google drive set of
// grandmaster games.
main :: () {
init_xiangqi_tables();
random_seed(0xcafe_babe_10_31_1517);
FILE_NAME :: "xiangqi_games.txt";
text, success := read_entire_file(FILE_NAME);
if !success {
print("Error. % cannot be opened.", FILE_NAME);
return;
}
table: Table(Xiangqi, string,
(xiangqi)=>xiangqi.hash,
(a,b) => a.hash == b.hash);
xiangqi: Xiangqi;
xiangqi_startpos(*xiangqi);
for i: 0..1_000_000_000 {
print("Game Number %\n", i);
found, line, rest := split_from_left(text, #char "\n");
if found == false {
break;
}
defer {
text = rest;
}
reset_temporary_storage();
replace_chars(line, "',", #char " ");
xiangqi_startpos(*xiangqi);
mov1 := (random_get() % 30) 5;
mov2 := (random_get() % 30) 5;
mov3 := (random_get() % 30) 5;
for index: 0..cast(u64)1_000_000 {
line = eat_spaces(line);
token, found := parse_token(*line);
if found == false {
break;
}
move := to_move32(*xiangqi, token);
make_move(*xiangqi, move);
if mov1 != index && mov2 != index && mov3 != index then {
continue;
}
fenstring := to_fenstring(*xiangqi);
if table_find_pointer(*table, xiangqi) == null {
table_add(*table, xiangqi, copy_string(fenstring));
}
}
}
builder: String_Builder;
append(*builder, "xiangqi_openings :: string.[\n");
for value, key: table {
print_to_builder(*builder, " \"%\",\n", value);
}
append(*builder, "];\n");
data := builder_to_string(*builder);
write_entire_file("opening_book.jai", data);
}
#import "Basic";
#import "File";
#import "String";
#import "Random";
#load "board.jai";
#import "Math";
#import "Hash_Table";