33 const int n_discs_o = 64 - n_empties - n_discs_p;
34 register int score = n_discs_p - n_discs_o;
38 if (score < 0) score -= n_empties;
39 else if (score > 0) score += n_empties;
98 register int score, n_flips;
114 score += n_flips + 2;
138 register int score, bestscore;
139 const int beta = alpha + 1;
149 if (bestscore < beta) {
153 if (score > bestscore) bestscore = score;
164 if (bestscore > alpha) {
168 if (score < bestscore) bestscore = score;
177 assert((bestscore & 1) == 0);
196 int x2 = (empty = empty->
next)->x;
197 int x3 = empty->
next->
x;
198 register int score, bestscore;
199 const int beta = alpha + 1;
207 int tmp = x1; x1 = x2; x2 = tmp;
209 int tmp = x1; x1 = x3; x3 = x2; x2 = tmp;
216 if (bestscore >= beta)
return bestscore;
221 if (score >= beta)
return score;
222 else if (score > bestscore) bestscore = score;
227 if (score > bestscore) bestscore = score;
235 if (bestscore <= alpha)
return bestscore;
240 if (score <= alpha)
return score;
241 else if (score < bestscore) bestscore = score;
246 if (score < bestscore) bestscore = score;
271 int x2 = (empty = empty->
next)->x;
272 int x3 = (empty = empty->
next)->x;
273 int x4 = empty->
next->
x;
275 int score, bestscore;
276 const int beta = alpha + 1;
291 int tmp = x1; x1 = x2; x2 = x3; x3 = tmp;
293 int tmp = x1; x1 = x2; x2 = x4; x4 = x3; x3 = tmp;
296 int tmp = x1; x1 = x3; x3 = tmp; tmp = x2; x2 = x4; x4 = tmp;
301 int tmp = x2; x2 = x3; x3 = tmp;
303 int tmp = x2; x2 = x4; x4 = x3; x3 = tmp;
313 if (bestscore >= beta)
return bestscore;
320 if (score >= beta)
return score;
321 else if (score > bestscore) bestscore = score;
328 if (score >= beta)
return score;
329 else if (score > bestscore) bestscore = score;
336 if (score > bestscore) bestscore = score;
372 const int beta = alpha + 1;
392 if (score >= beta)
return score;
393 else if (score > bestscore) bestscore = score;
404 if (score >= beta)
return score;
405 else if (score > bestscore) bestscore = score;
416 if (score >= beta)
return score;
417 else if (score > bestscore) bestscore = score;
453 unsigned long long hash_code;
454 const int beta = alpha + 1;
458 Move *move, *bestmove;
461 if (search->
stop)
return alpha;
506 if (bestmove->
score >= beta)
break;
520 assert((bestmove->
score & 1) == 0);
521 return bestmove->
score;
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
const unsigned long long NEIGHBOUR[]
Definition bit.c:39
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_pass_next(const Board *board, const int x, Board *next)
Compute a board resulting of an opponent move played on a previous board.
Definition board.c:538
unsigned long long board_get_move(const Board *board, const int x, Move *move)
Compute a move.
Definition board.c:438
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
unsigned long long board_next(const Board *board, const int x, Board *next)
Compute a board resulting of a move played on a previous board.
Definition board.c:517
#define SCORE_MAX
Definition const.h:58
#define SCORE_INF
Definition const.h:52
@ PASS
Definition const.h:37
@ NOMOVE
Definition const.h:37
#define SCORE_MIN
Definition const.h:55
int(* count_last_flip[])(const unsigned long long)
Definition count_flip.c:1234
#define foreach_empty(empty, list)
Definition empty.h:46
#define foreach_odd_empty(empty, list, parity)
Definition empty.h:54
#define foreach_even_empty(empty, list, parity)
Definition empty.h:50
static int search_solve_3(Search *search, const int alpha)
Get the final score.
Definition endgame.c:190
static int board_solve_2(Board *board, int alpha, const int x1, const int x2, Search *search)
Get the final score.
Definition endgame.c:135
int NWS_endgame(Search *search, const int alpha)
Evaluate an endgame position with a Null Window Search algorithm.
Definition endgame.c:449
static int board_solve(const Board *board, const int n_empties)
Get the final score.
Definition endgame.c:30
int board_score_1(const Board *board, const int beta, const int x)
Get the final score.
Definition endgame.c:96
int search_solve(const Search *search)
Get the final score.
Definition endgame.c:52
static int board_solve_0(const Board *board)
Get the final score.
Definition endgame.c:65
static int search_shallow(Search *search, const int alpha)
Evaluate a position using a shallow NWS.
Definition endgame.c:366
int search_solve_0(const Search *search)
Get the final score.
Definition endgame.c:80
static int search_solve_4(Search *search, const int alpha)
Get the final score.
Definition endgame.c:266
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
bool movelist_is_empty(const MoveList *movelist)
Check if the list is empty.
Definition move.c:537
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
#define foreach_best_move(iter, movelist)
Definition move.h:82
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_pass_endgame(Search *search)
Update the search state after a passing move.
Definition search.c:928
void search_get_movelist(const Search *search, MoveList *movelist)
Get a list of legal moves.
Definition search.c:875
const int QUADRANT_ID[]
Definition search.c:81
void search_restore_endgame(Search *search, const Move *move)
Restore the search state as before a move.
Definition search.c:915
void search_update_endgame(Search *search, const Move *move)
Update the search state after a move.
Definition search.c:900
const int SQUARE_TYPE[]
Definition search.c:132
bool search_SC_NWS(Search *search, const int alpha, int *score)
Stability Cutoff (TC).
Definition search.c:1170
#define DEPTH_TO_SHALLOW_SEARCH
Definition settings.h:83
Statistics statistics
Definition stats.c:21
#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
Move move[MAX_MOVE+2]
Definition move.h:30
int score
Definition move.h:23
struct Move * next
Definition move.h:25
int x
Definition move.h:22
unsigned int parity
Definition search.h:120
int n_empties
Definition search.h:99
SquareList empties[BOARD_SIZE+2]
Definition search.h:97
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
Board board[1]
Definition search.h:96
struct SquareList * next
Definition empty.h:20
int x
Definition empty.h:17
unsigned long long n_NWS_endgame
Definition stats.h:79
unsigned long long n_search_solve_4
Definition stats.h:86
unsigned long long n_board_solve_2
Definition stats.h:84
unsigned long long n_search_solve_3
Definition stats.h:85
unsigned long long n_search_solve_0
Definition stats.h:83
unsigned long long n_search_solve
Definition stats.h:82
unsigned long long n_NWS_shallow
Definition stats.h:81
unsigned long long n_played_square[BOARD_SIZE][10]
Definition stats.h:110
unsigned long long n_good_square[BOARD_SIZE][10]
Definition stats.h:111