30 18, 4, 16, 12, 12, 16, 4, 18,
31 4, 2, 6, 8, 8, 6, 2, 4,
32 16, 6, 14, 10, 10, 14, 6, 16,
33 12, 8, 10, 0, 0, 10, 8, 12,
34 12, 8, 10, 0, 0, 10, 8, 12,
35 16, 6, 14, 10, 10, 14, 6, 16,
36 4, 2, 6, 8, 8, 6, 2, 4,
37 18, 4, 16, 12, 12, 16, 4, 18
49 if (
A1 <= x && x <=
H8) {
51 x = ((x & 070) | (7 - (x & 7)));
54 x = ((070 - (x & 070)) | (x & 7));
57 x = (((x & 070) >> 3) | ((x & 7) << 3));
59 assert(
A1 <= x && x <=
H8);
81 }
else if (x ==
PASS) {
84 }
else if (x >=
A1 && x <=
H8) {
92 if (player ==
BLACK) {
117 }
else if (x ==
PASS) {
120 }
else if (x >=
A1 && x <=
H8) {
128 if (player ==
BLACK) {
129 s[0] = toupper(s[0]);
130 s[1] = toupper(s[1]);
154static int w_hash = 1 << 15;
155static int w_eval = 1 << 15;
156static int w_mobility = 1 << 15;
157static int w_corner_stability = 1 << 11;
158static int w_edge_stability = 1 << 11;
159static int w_potential_mobility = 1 << 5;
160static int w_low_parity = 1 << 3;
161static int w_mid_parity = 1 << 2;
162static int w_high_parity = 1 << 1;
189 const int w_hash = 1 << 15;
190 const int w_eval = 1 << 15;
191 const int w_mobility = 1 << 15;
192 const int w_corner_stability = 1 << 11;
193 const int w_edge_stability = 1 << 11;
194 const int w_potential_mobility = 1 << 5;
195 const int w_low_parity = 1 << 3;
196 const int w_mid_parity = 1 << 2;
197 const int w_high_parity = 1 << 1;
204 else if (move->
x == hash_data->
move[0]) move->
score = (1 << 29);
205 else if (move->
x == hash_data->
move[1]) move->
score = (1 << 28);
213 if (sort_depth < 0) {
255 unsigned long long best_n_nodes;
256 unsigned long long n_nodes, t;
259 if (strcmp(w_name,
"w_eval") == 0) w = &w_eval;
260 else if (strcmp(w_name,
"w_mobility") == 0) w = &w_mobility;
261 else if (strcmp(w_name,
"w_corner_stability") == 0) w = &w_corner_stability;
262 else if (strcmp(w_name,
"w_edge_stability") == 0) w = &w_edge_stability;
263 else if (strcmp(w_name,
"w_potential_mobility") == 0) w = &w_potential_mobility;
264 else if (strcmp(w_name,
"w_low_parity") == 0) w = &w_low_parity;
265 else if (strcmp(w_name,
"w_mid_parity") == 0) w = &w_mid_parity;
266 else if (strcmp(w_name,
"w_high_parity") == 0) w = &w_high_parity;
268 warn(
"unknown parameter %s\n", w_name);
272 best_n_nodes = ULLONG_MAX;
275 for (i = -1; i <= 20; ++i) {
276 *w = (i >= 0 ? 1 << i : 0);
278 n_nodes = solver(search, filename);
280 printf(
"%s %d : nodes %llu : time %.3f\n", w_name, *w, n_nodes, 0.001 * t);
281 if (n_nodes < best_n_nodes) {
282 best_n_nodes = n_nodes;
286 printf(
"Best %s %d : %llu\n", w_name, best_w, best_n_nodes);
308 previous = previous->
next = move;
311 previous->
next = NULL;
334 for (iter = movelist->
move->
next; iter != NULL; iter = iter->
next) {
336 fprintf(f,
"[%d] ", iter->
score);
348 if (previous_best->
next) {
350 best = previous_best;
351 for (move = best->
next; move->
next != NULL; move = move->
next) {
356 if (previous_best != best) {
360 previous_best->
next = move;
364 return previous_best->
next;
375 if (previous_best->
next) {
377 best = previous_best;
378 for (move = best->
next; move->
next != NULL; move = move->
next) {
383 if (previous_best != best) {
387 previous_best->
next = move;
391 return previous_best->
next;
438 int sort_depth, min_depth;
444 if (depth >= min_depth) {
445 sort_depth = (depth - 15) / 3;
446 if (hash_data && hash_data->
upper < alpha) sort_depth -= 2;
447 if (search->
n_empties >= 27) ++sort_depth;
448 if (sort_depth < 0) sort_depth = 0;
else if (sort_depth > 6) sort_depth = 6;
455 move_evaluate(move, search, hash_data, sort_alpha, sort_depth);
470 Move *iter, *previous;
472 for (iter = (previous = movelist->
move)->
next; iter != NULL; iter = (previous = iter)->
next) {
473 if (iter->
x == move) {
495 if (iter->
x == hash_data->
move[0]) iter->
cost = INT_MAX;
496 else if (iter->
x == hash_data->
move[1]) iter->
cost = INT_MAX - 1;
518 Move *iter, *previous;
520 for (iter = (previous = movelist->
move)->
next; iter != NULL; iter = (previous = iter)->
next) {
521 if (iter->
x == move) {
552 line->
color = player;
567 for (i = 0; i < line->
n_moves; ++i) {
568 assert(line->
move[i] != x || x ==
PASS);
595 for (i = from; i < src->
n_moves; ++i) {
613 int player = line->
color;
614 int w = 2 + (separator ? strlen(separator) : 0);
615 int len = abs(width);
617 for (i = 0; i < line->
n_moves && len > w; ++i, len -= w) {
619 if (separator && i) fputs(separator, f);
622 for (len =
MIN(len, width); len > w; len -= w) {
623 fputc(
' ', f);fputc(
' ', f);
if (separator) fputs(separator, f);
638 int player = line->
color;
639 int w = 2 + (separator ? strlen(separator) : 0);
641 for (i = 0; i < line->
n_moves && i < n; ++i) {
644 if (separator) strcpy(
string + w * i + 2, separator);
646 string[w * i] =
'\0';
674 array->
n = array->
size = 0;
696 for (i = 0; i < array->
n; ++i) {
700 if (array->
size < array->
n + 1) {
702 if (array->
item == NULL)
fatal_error(
"Cannot re-allocate board array.\n");
705 array->
item[array->
n].
x = x;
719 hash->
size = (1 << bitsize);
749 unsigned long long h;
#define foreach_bit(i, b)
Definition bit.h:39
unsigned long long board_get_hash_code(const Board *board)
Compute a hash code.
Definition board.c:1134
void board_restore(Board *board, const Move *move)
Restore a board.
Definition board.c:487
void board_update(Board *board, const Move *move)
Update a board.
Definition board.c:469
int get_potential_mobility(const unsigned long long P, const unsigned long long O)
Get potential mobility.
Definition board.c:882
unsigned long long board_get_move(const Board *board, const int x, Move *move)
Compute a move.
Definition board.c:438
int get_corner_stability(const unsigned long long P)
Estimate corner stability.
Definition board.c:1122
int board_unique(const Board *board, Board *unique)
unique board
Definition board.c:379
int get_mobility(const unsigned long long P, const unsigned long long O)
Count legal moves.
Definition board.c:833
int get_edge_stability(const unsigned long long P, const unsigned long long O)
Estimate the stability of edges.
Definition board.c:1106
bool board_equal(const Board *b1, const Board *b2)
Compare two board for equality.
Definition board.c:335
DLL_API unsigned long long get_moves(const unsigned long long P, const unsigned long long O)
Get legal moves.
Definition board.c:621
int get_weighted_mobility(const unsigned long long P, const unsigned long long O)
Definition board.c:838
#define SCORE_MAX
Definition const.h:58
#define SCORE_INF
Definition const.h:52
#define GAME_SIZE
Definition const.h:25
@ PASS
Definition const.h:37
@ NOMOVE
Definition const.h:37
@ A1
Definition const.h:29
@ H8
Definition const.h:36
@ BLACK
Definition const.h:42
#define SCORE_MIN
Definition const.h:55
bool hash_get(HashTable *hash_table, const unsigned long long hash_code, HashData *data)
Find an hash table entry according to the evaluated board hash codes.
Definition hash-lock-free.c:600
int search_eval_2(Search *search, int alpha, const int beta)
Evaluate a position at depth 2.
Definition midgame.c:147
int search_eval_0(Search *search)
evaluate a midgame position with the evaluation function.
Definition midgame.c:32
int PVS_shallow(Search *search, int alpha, int beta, int depth)
Evaluate a midgame position at shallow depth.
Definition midgame.c:381
int search_eval_1(Search *search, const int alpha, int beta)
Evaluate a position at depth 1.
Definition midgame.c:74
Move * movelist_best(MoveList *movelist)
Return the best move of the list.
Definition move.c:411
void line_print(const Line *line, int width, const char *separator, FILE *f)
Print a move sequence.
Definition move.c:610
Move * move_next_most_expensive(Move *previous_best)
Return the next best move from the list.
Definition move.c:373
const int SQUARE_VALUE[]
Definition move.c:28
bool movelist_is_empty(const MoveList *movelist)
Check if the list is empty.
Definition move.c:537
void line_push(Line *line, const int x)
Add a move to the sequence.
Definition move.c:561
void movehash_delete(MoveHash *hash)
Free the hash table.
Definition move.c:730
bool move_wipeout(const Move *move, const Board *board)
Check if a move wins 64-0.
Definition move.c:148
void movehash_init(MoveHash *hash, int bitsize)
Initialisation of the hash table.
Definition move.c:715
void movelist_print(const MoveList *movelist, const int player, FILE *f)
Print out a movelist.
Definition move.c:330
void move_print(const int x, const int player, FILE *f)
Print out a move.
Definition move.c:110
const Move MOVE_PASS
Definition move.c:26
void movelist_sort(MoveList *movelist)
Sort all moves.
Definition move.c:505
struct MoveArray MoveArray
static void move_evaluate(Move *move, Search *search, const HashData *hash_data, const int sort_alpha, const int sort_depth)
Evaluate a list of move.
Definition move.c:186
Move * movelist_first(MoveList *movelist)
Return the first move of the list.
Definition move.c:422
bool movehash_append(MoveHash *hash, const Board *b, const int x)
Append a position to the hash table.
Definition move.c:745
static void movearray_delete(MoveArray *array)
array supression.
Definition move.c:681
Move * move_next(Move *move)
Return the next move from the list.
Definition move.c:400
static bool movearray_append(MoveArray *array, const Board *b, const int x)
Append a position.
Definition move.c:693
void line_init(Line *line, const int player)
Initialize a sequence of moves.
Definition move.c:549
Move * move_next_best(Move *previous_best)
Return the next best move from the list.
Definition move.c:346
void movelist_sort_cost(MoveList *movelist, const HashData *hash_data)
Sort all moves except the first, based on move cost & hash_table storage.
Definition move.c:489
void movelist_evaluate(MoveList *movelist, Search *search, const HashData *hash_data, const int alpha, const int depth)
Evaluate a list of move in order to sort it.
Definition move.c:436
void line_pop(Line *line)
Remove the last move from a sequence.
Definition move.c:578
int movelist_get_moves(MoveList *movelist, const Board *board)
Get moves from a position.
Definition move.c:298
char * line_to_string(const Line *line, int n, const char *separator, char *string)
Line to string.
Definition move.c:635
Move * movelist_exclude(MoveList *movelist, const int move)
Exclude a move.
Definition move.c:516
const Move MOVE_INIT
Definition move.c:25
char * move_to_string(const int x, const int player, char *s)
Print out a move.
Definition move.c:76
int symetry(int x, const int sym)
Get a symetric square coordinate.
Definition move.c:47
static void movearray_init(MoveArray *array)
array initialisation.
Definition move.c:671
void line_copy(Line *dest, const Line *src, const int from)
Copy part of a sequence to another sequence.
Definition move.c:591
Move * movelist_sort_bestmove(MoveList *movelist, const int move)
Sort a move as best.
Definition move.c:468
#define foreach_move(iter, movelist)
Definition move.h:78
#define foreach_best_move(iter, movelist)
Definition move.h:82
void tune_move_evaluate(struct Search *, const char *, const char *)
const int NO_SELECTIVITY
Definition search.c:94
const int QUADRANT_ID[]
Definition search.c:81
void search_restore_midgame(Search *search, const Move *move)
Restore the search state as before a move.
Definition search.c:964
void search_update_midgame(Search *search, const Move *move)
Update the search state after a move.
Definition search.c:942
#define SORT_ALPHA_DELTA
Definition settings.h:98
#define SEARCH_UPDATE_ALL_NODES()
Definition stats.h:54
#define SEARCH_UPDATE_INTERNAL_NODES()
Definition stats.h:40
unsigned long long player
Definition board.h:27
unsigned long long opponent
Definition board.h:27
unsigned char move[2]
Definition hash.h:31
signed char upper
Definition hash.h:30
int n_moves
Definition move.h:37
char move[GAME_SIZE]
Definition move.h:36
int color
Definition move.h:38
Board board
Definition move.c:654
int x
Definition move.c:655
int n
Definition move.c:663
int size
Definition move.c:664
MBoard * item
Definition move.c:662
int mask
Definition move.h:96
int size
Definition move.h:95
struct MoveArray * array
Definition move.h:94
int n_moves
Definition move.h:31
Move move[MAX_MOVE+2]
Definition move.h:30
unsigned int cost
Definition move.h:24
int score
Definition move.h:23
struct Move * next
Definition move.h:25
unsigned long long flipped
Definition move.h:21
int x
Definition move.h:22
unsigned int parity
Definition search.h:120
int n_empties
Definition search.h:99
HashTable hash_table[1]
Definition search.h:103
int selectivity
Definition search.h:118
Board board[1]
Definition search.h:96
long long(* time_clock)(void)
Time clock.
Definition util.c:122
#define MIN(a, b)
Definition util.h:101
#define fatal_error(...)
Display an error message as "FATAL_ERROR : file name : function name : line number : ....
Definition util.h:349
#define warn(...)
Display a warning message as "WARNING : ... ".
Definition util.h:373
#define MAX(a, b)
Definition util.h:98