41 score = w[f[ 0]] + w[f[ 1]] + w[f[ 2]] + w[f[ 3]]
42 + w[f[ 4]] + w[f[ 5]] + w[f[ 6]] + w[f[ 7]]
43 + w[f[ 8]] + w[f[ 9]] + w[f[10]] + w[f[11]]
44 + w[f[12]] + w[f[13]] + w[f[14]] + w[f[15]]
45 + w[f[16]] + w[f[17]] + w[f[18]] + w[f[19]]
46 + w[f[20]] + w[f[21]] + w[f[22]] + w[f[23]]
48 + w[f[26]] + w[f[27]] + w[f[28]] + w[f[29]]
49 + w[f[30]] + w[f[31]] + w[f[32]] + w[f[33]]
50 + w[f[34]] + w[f[35]] + w[f[36]] + w[f[37]]
51 + w[f[38]] + w[f[39]] + w[f[40]] + w[f[41]]
52 + w[f[42]] + w[f[43]] + w[f[44]] + w[f[45]]
55 if (score > 0) score += 64;
else score -= 64;
79 register int score, bestscore;
92 if (moves & empty->
b) {
98 score = -w[f[ 0]] - w[f[ 1]] - w[f[ 2]] - w[f[ 3]]
99 - w[f[ 4]] - w[f[ 5]] - w[f[ 6]] - w[f[ 7]]
100 - w[f[ 8]] - w[f[ 9]] - w[f[10]] - w[f[11]]
101 - w[f[12]] - w[f[13]] - w[f[14]] - w[f[15]]
102 - w[f[16]] - w[f[17]] - w[f[18]] - w[f[19]]
103 - w[f[20]] - w[f[21]] - w[f[22]] - w[f[23]]
104 - w[f[24]] - w[f[25]]
105 - w[f[26]] - w[f[27]] - w[f[28]] - w[f[29]]
106 - w[f[30]] - w[f[31]] - w[f[32]] - w[f[33]]
107 - w[f[34]] - w[f[35]] - w[f[36]] - w[f[37]]
108 - w[f[38]] - w[f[39]] - w[f[40]] - w[f[41]]
109 - w[f[42]] - w[f[43]] - w[f[44]] - w[f[45]]
113 if (score > 0) score += 64;
else score -= 64;
116 if (score > bestscore) {
118 if (bestscore >= beta)
break;
149 register int bestscore, score;
160 assert(alpha <= beta);
165 if (moves & empty->
b) {
170 if (score > bestscore) {
172 if (bestscore >= beta)
break;
173 else if (bestscore > alpha) alpha = bestscore;
223 assert(search != NULL);
224 assert(parent != NULL);
230 int probcut_error, eval_error;
231 int probcut_depth, probcut_beta, probcut_alpha;
232 int eval_score, eval_beta, eval_alpha;
234 const int beta = alpha + 1;
243 if (probcut_depth == 0) probcut_depth = depth - 2;
244 assert(probcut_depth > 1 && probcut_depth <= depth - 2 && (probcut_depth & 1) == (depth & 1));
252 eval_beta = beta - eval_error;
253 probcut_beta = beta + probcut_error;
254 probcut_alpha = probcut_beta - 1;
255 if (eval_score >= eval_beta && probcut_beta <
SCORE_MAX) {
258 score =
NWS_midgame(search, probcut_alpha, probcut_depth, parent);
260 if (score >= probcut_beta) {
268 eval_alpha = alpha + eval_error;
269 probcut_alpha = alpha - probcut_error;
270 if (eval_score < eval_alpha && probcut_alpha >
SCORE_MIN) {
273 score =
NWS_midgame(search, probcut_alpha, probcut_depth, parent);
275 if (score <= probcut_alpha) {
303 unsigned long long hash_code;
304 const int beta = alpha + 1;
309 int bestscore, bestmove;
310 long long cost = -search->
n_nodes;
320 assert(hash_table != NULL);
333 bestscore = -
NWS_shallow(search, -beta, depth, hash_table);
349 score = -
NWS_shallow(search, -beta, depth - 1, hash_table);
351 if (score > bestscore) {
354 if (bestscore >= beta)
break;
385 unsigned long long hash_code;
390 int bestscore, bestmove;
391 long long cost = -search->
n_nodes;
403 if (
search_SC_PVS(search, &alpha, &beta, &score))
return score;
408 hash_get(hash_table, board, hash_code, hash_data);
415 bestscore = -
PVS_shallow(search, -beta, -alpha, depth);
433 score = -
PVS_shallow(search, -beta, -lower, depth - 1);
435 score = -
NWS_shallow(search, -lower - 1, depth - 1, hash_table);
436 if (alpha < score && score < beta) {
437 score = -
PVS_shallow(search, -beta, -lower, depth - 1);
441 if (score > bestscore) {
444 if (bestscore >= beta)
break;
445 else if (bestscore > lower) lower = bestscore;
478 unsigned long long hash_code;
479 const int beta = alpha + 1;
486 int hash_selectivity;
489 assert((2 <= depth && depth < search->n_empties) || depth == search->
n_empties);
491 assert(parent != NULL);
494 if (search->
stop)
return alpha;
496 else if (depth <= 3 && depth < search->n_empties)
return NWS_shallow(search, alpha, depth, hash_table);
507 if ((
hash_get(hash_table, board, hash_code, hash_data) ||
hash_get(pv_table, board, hash_code, hash_data)) &&
search_TC_NWS(hash_data, depth, search->
selectivity, alpha, &score))
return score;
522 if (
search_probcut(search, alpha, depth, parent, &score))
return score;
590 unsigned long long hash_code;
597 int reduced_depth, depth_pv_extension, saved_selectivity;
598 int hash_selectivity;
603 assert(depth <= search->n_empties);
606 assert(alpha <= beta);
610 if (search->
stop)
return alpha;
638 if (!
hash_get(pv_table, board, hash_code, hash_data))
hash_get(hash_table, board, hash_code, hash_data);
641 else reduced_depth = depth - 2;
642 if (reduced_depth >= 3) {
647 hash_get(pv_table, board, hash_code, hash_data);
668 const int alpha = node->
alpha;
671 if (!search->
stop && alpha < move->score && move->
score < beta) {
DLL_API int bit_count(unsigned long long b)
Count the number of bits set to one in an unsigned long long.
Definition bit.c:72
DLL_API int last_bit(unsigned long long b)
Search the last bit set (same as log2()).
Definition bit.c:264
unsigned long long board_get_hash_code(const Board *board)
Compute a hash code.
Definition board.c:1134
unsigned long long board_get_move(const Board *board, const int x, Move *move)
Compute a move.
Definition board.c:438
DLL_API unsigned long long get_moves(const unsigned long long P, const unsigned long long O)
Get legal moves.
Definition board.c:621
DLL_API bool can_move(const unsigned long long P, const unsigned long long O)
Check if a player can move.
Definition board.c:797
#define SCORE_MAX
Definition const.h:58
#define SCORE_INF
Definition const.h:52
@ PASS
Definition const.h:37
@ NOMOVE
Definition const.h:37
NodeType
Definition const.h:80
@ CUT_NODE
Definition const.h:82
@ PV_NODE
Definition const.h:81
@ ALL_NODE
Definition const.h:83
#define SCORE_MIN
Definition const.h:55
#define foreach_empty(empty, list)
Definition empty.h:46
int NWS_endgame(Search *search, const int alpha)
Evaluate an endgame position with a Null Window Search algorithm.
Definition endgame.c:449
int search_solve(const Search *search)
Get the final score.
Definition endgame.c:52
int search_solve_0(const Search *search)
Get the final score.
Definition endgame.c:80
void eval_restore(Eval *eval, const Move *move)
Definition eval.c:810
void eval_update(Eval *eval, const Move *move)
Definition eval.c:681
double eval_sigma(const int n_empty, const int depth, const int probcut_depth)
Compute the error-type of the evaluation function according to the depths.
Definition eval.c:843
short *** EVAL_WEIGHT
Definition eval.c:231
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
void hash_store(HashTable *hash_table, const unsigned long long hash_code, const int depth, const int selectivity, const int cost, const int alpha, const int beta, const int score, const int move)
Store an hashtable item.
Definition hash-lock-free.c:543
int search_eval_2(Search *search, int alpha, const int beta)
Evaluate a position at depth 2.
Definition midgame.c:147
static void search_update_probcut(Search *search, const NodeType node_type)
Definition midgame.c:192
int NWS_midgame(Search *search, const int alpha, int depth, Node *parent)
Evaluate a midgame position with a Null Window Search algorithm.
Definition midgame.c:473
static bool search_probcut(Search *search, const int alpha, const int depth, Node *parent, int *value)
Probcut.
Definition midgame.c:220
int search_eval_0(Search *search)
evaluate a midgame position with the evaluation function.
Definition midgame.c:32
int PVS_midgame(Search *search, const int alpha, const int beta, int depth, Node *parent)
Evaluate a position with a deep Principal Variation Search algorithm.
Definition midgame.c:585
int PVS_shallow(Search *search, int alpha, int beta, int depth)
Evaluate a midgame position at shallow depth.
Definition midgame.c:381
#define RCD
Definition midgame.c:24
static void search_restore_probcut(Search *search, const NodeType node_type, const int selectivity)
Definition midgame.c:200
int search_eval_1(Search *search, const int alpha, int beta)
Evaluate a position at depth 1.
Definition midgame.c:74
int NWS_shallow(Search *search, const int alpha, int depth, HashTable *hash_table)
Evaluate a midgame position with a Null Window Search algorithm.
Definition midgame.c:300
bool movelist_is_empty(const MoveList *movelist)
Check if the list is empty.
Definition move.c:537
bool move_wipeout(const Move *move, const Board *board)
Check if a move wins 64-0.
Definition move.c:148
void movelist_sort(MoveList *movelist)
Sort all moves.
Definition move.c:505
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
#define foreach_move(iter, movelist)
Definition move.h:78
Options options
Definition options.c:22
const int NO_SELECTIVITY
Definition search.c:94
bool search_TC_NWS(HashData *data, const int depth, const int selectivity, const int alpha, int *score)
Transposition Cutoff (TC).
Definition search.c:1230
void search_check_timeout(Search *search)
Check if it can iterate more...
Definition search.c:800
bool search_SC_PVS(Search *search, volatile int *alpha, volatile int *beta, int *score)
Stability Cutoff (SC).
Definition search.c:1146
const Selectivity selectivity_table[]
Definition search.c:97
void search_get_movelist(const Search *search, MoveList *movelist)
Get a list of legal moves.
Definition search.c:875
void search_restore_pass_midgame(Search *search)
Update the search state after a passing move.
Definition search.c:998
unsigned long long search_count_nodes(Search *search)
Return the number of nodes searched.
Definition search.c:1073
void search_restore_midgame(Search *search, const Move *move)
Restore the search state as before a move.
Definition search.c:964
const int SQUARE_TYPE[]
Definition search.c:132
void search_update_midgame(Search *search, const Move *move)
Update the search state after a move.
Definition search.c:942
bool search_ETC_NWS(Search *search, MoveList *movelist, unsigned long long hash_code, const int depth, const int selectivity, const int alpha, int *score)
Enhanced Transposition Cutoff (ETC).
Definition search.c:1264
void search_update_pass_midgame(Search *search)
Update the search state after a passing move.
Definition search.c:983
bool search_SC_NWS(Search *search, const int alpha, int *score)
Stability Cutoff (TC).
Definition search.c:1170
#define LIMIT_RECURSIVE_PROBCUT(x)
Definition settings.h:42
#define USE_IID
Definition settings.h:59
#define USE_PV_EXTENSION
Definition settings.h:80
#define ITERATIVE_MIN_EMPTIES
Definition settings.h:89
#define USE_PROBCUT
Definition settings.h:36
#define USE_RECURSIVE_PROBCUT
Definition settings.h:39
#define DEPTH_MIDGAME_TO_ENDGAME
Definition settings.h:86
#define PV_HASH_HEIGHT
Definition settings.h:92
Statistics statistics
Definition stats.c:21
#define SEARCH_UPDATE_EVAL_NODES()
Definition stats.h:47
#define PROBCUT_STATS(x)
Definition stats.h:33
#define SQUARE_STATS(x)
Definition stats.h:29
#define SEARCH_UPDATE_INTERNAL_NODES()
Definition stats.h:40
#define SEARCH_STATS(x)
Definition stats.h:27
unsigned long long player
Definition board.h:27
unsigned long long opponent
Definition board.h:27
evaluation function
Definition eval.h:18
int player
Definition eval.h:20
int * feature
Definition eval.h:19
unsigned char move[2]
Definition hash.h:31
int n_moves
Definition move.h:31
int score
Definition move.h:23
int x
Definition move.h:22
int beta
Definition ybwc.h:52
bool pv_node
Definition ybwc.h:53
volatile int alpha
Definition ybwc.h:51
volatile int bestscore
Definition ybwc.h:50
volatile int bestmove
Definition ybwc.h:49
int inc_sort_depth[3]
Definition options.h:27
double probcut_d
Definition options.h:69
int n_empties
Definition search.h:99
volatile unsigned long long child_nodes
Definition search.h:156
int depth_pv_extension
Definition search.h:121
int height
Definition search.h:133
SquareList empties[BOARD_SIZE+2]
Definition search.h:97
int probcut_level
Definition search.h:119
HashTable pv_table[1]
Definition search.h:104
HashTable hash_table[1]
Definition search.h:103
volatile Stop stop
Definition search.h:122
volatile unsigned long long n_nodes
Definition search.h:155
HashTable shallow_table[1]
Definition search.h:105
int selectivity
Definition search.h:118
Eval eval[1]
Definition search.h:106
NodeType node_type[GAME_SIZE]
Definition search.h:134
Board board[1]
Definition search.h:96
double t
Definition search.h:26
unsigned long long b
Definition empty.h:16
int x
Definition empty.h:17
unsigned long long n_search_eval_1
Definition stats.h:88
unsigned long long n_probcut_high_try
Definition stats.h:107
unsigned long long n_probcut_high_cutoff
Definition stats.h:107
unsigned long long n_probcut_low_cutoff
Definition stats.h:106
unsigned long long n_PVS_shallow
Definition stats.h:80
unsigned long long n_search_eval_0
Definition stats.h:87
unsigned long long n_search_eval_2
Definition stats.h:89
unsigned long long n_played_square[BOARD_SIZE][10]
Definition stats.h:110
unsigned long long n_NWS_midgame
Definition stats.h:78
unsigned long long n_good_square[BOARD_SIZE][10]
Definition stats.h:111
unsigned long long n_probcut_try
Definition stats.h:105
unsigned long long n_PVS_midgame
Definition stats.h:77
unsigned long long n_probcut_low_try
Definition stats.h:106
Move * node_next_move(Node *node)
Get the next move of the move list.
Definition ybwc.c:345
void node_wait_slaves(Node *node)
Wait for slaves termination.
Definition ybwc.c:212
bool node_split(Node *node, Move *move)
Node split.
Definition ybwc.c:167
void node_free(Node *node)
Free Resources allocated by a node.
Definition ybwc.c:95
Move * node_first_move(Node *node, MoveList *movelist)
Get the first move of the move list.
Definition ybwc.c:297
void node_update(Node *node, Move *move)
Update a node.
Definition ybwc.c:261
void node_init(Node *node, Search *search, const int alpha, const int beta, const int depth, const int n_moves, Node *parent)
Initialize a node.
Definition ybwc.c:59