My Project
|
#include "board.h"
#include "const.h"
#include "empty.h"
#include "eval.h"
#include "hash.h"
#include "move.h"
#include "util.h"
#include <stdio.h>
Go to the source code of this file.
Classes | |
struct | Selectivity |
struct | Bound |
struct | Result |
struct | Hint |
struct | HintList |
struct | Level |
struct | Search |
Typedefs | |
typedef struct Selectivity | Selectivity |
typedef struct Bound | Bound |
typedef struct Result | Result |
typedef struct Hint | Hint |
typedef struct HintList | HintList |
typedef struct Search | Search |
Functions | |
void | search_global_init (void) |
void | search_init (Search *) |
Init the main search. More... | |
void | search_free (Search *) |
Free the search allocated ressource. More... | |
void | search_cleanup (Search *) |
Clean-up some search data. More... | |
void | search_setup (Search *) |
Set up various structure once the board has been set. More... | |
void | search_clone (Search *, Search *) |
Clone a search for parallel search. More... | |
void | search_set_board (Search *, const Board *, const int) |
Set the board to analyze. More... | |
void | search_set_level (Search *, const int, const int) |
Set the search level. More... | |
void | search_set_ponder_level (Search *, const int, const int) |
Set the search level while pondering. More... | |
void | search_resize_hashtable (Search *) |
void | search_set_game_time (Search *, const long long) |
set time to search. More... | |
void | search_set_move_time (Search *, const long long) |
set time to search. More... | |
void | search_time_init (Search *) |
Initialize the alloted time. More... | |
void | search_time_reset (Search *, const Board *) |
Reset the alloted time. More... | |
void | search_adjust_time (Search *, const bool) |
Give more time. More... | |
bool | search_continue (Search *) |
Check if it can iterate more... More... | |
void | search_check_timeout (Search *search) |
Check if it can iterate more... More... | |
void | search_set_task_number (Search *, const int) |
Change the number of task. More... | |
void | search_swap_parity (Search *, const int) |
Change parity. More... | |
void | search_get_movelist (const Search *, MoveList *) |
Get a list of legal moves. More... | |
void | search_update_endgame (Search *, const Move *) |
Update the search state after a move. More... | |
void | search_restore_endgame (Search *, const Move *) |
Restore the search state as before a move. More... | |
void | search_pass_endgame (Search *) |
Update the search state after a passing move. More... | |
void | search_update_midgame (Search *, const Move *) |
Update the search state after a move. More... | |
void | search_restore_midgame (Search *, const Move *) |
Restore the search state as before a move. More... | |
void | search_update_pass_midgame (Search *) |
Update the search state after a passing move. More... | |
void | search_restore_pass_midgame (Search *) |
Update the search state after a passing move. More... | |
long long | search_clock (Search *) |
Return the time spent by the search. More... | |
long long | search_time (Search *) |
Return the time spent by the search. More... | |
unsigned long long | search_count_nodes (Search *) |
Return the number of nodes searched. More... | |
void | search_print_pv (Search *, const int, const char *, FILE *) |
void | search_print (Search *, const int, const int, const char, FILE *) |
int | get_pv_extension (const int, const int) |
Compute the pv_extension. More... | |
void | result_print (Result *, FILE *) |
Print the current search result. More... | |
bool | search_SC_PVS (Search *, volatile int *, volatile int *, int *) |
Stability Cutoff (SC). More... | |
bool | search_SC_NWS (Search *, const int, int *) |
Stability Cutoff (TC). More... | |
bool | search_TC_PVS (HashData *, const int, const int, volatile int *, volatile int *, int *) |
Transposition Cutoff (TC). More... | |
bool | search_TC_NWS (HashData *, const int, const int, const int, int *) |
Transposition Cutoff (TC). More... | |
bool | search_ETC_PVS (Search *, MoveList *, unsigned long long, const int, const int, volatile int *, volatile int *, int *) |
bool | search_ETC_NWS (Search *, MoveList *, unsigned long long, const int, const int, const int, int *) |
Enhanced Transposition Cutoff (ETC). More... | |
NodeType | next_node_type (const NodeType parent, const bool first_move) |
int | search_solve (const Search *) |
Get the final score. More... | |
int | search_solve_0 (const Search *) |
Get the final score. More... | |
int | board_score_1 (const Board *, const int, const int) |
Get the final score. More... | |
int | NWS_endgame (Search *, const int) |
Evaluate an endgame position with a Null Window Search algorithm. More... | |
int | search_eval_0 (Search *) |
evaluate a midgame position with the evaluation function. More... | |
int | search_eval_1 (Search *, const int, int) |
Evaluate a position at depth 1. More... | |
int | search_eval_2 (Search *, int, const int) |
Evaluate a position at depth 2. More... | |
int | NWS_midgame (Search *, const int, int, struct Node *) |
Evaluate a midgame position with a Null Window Search algorithm. More... | |
int | PVS_midgame (Search *, const int, const int, int, struct Node *) |
Evaluate a position with a deep Principal Variation Search algorithm. More... | |
int | NWS_shallow (Search *, const int, int, HashTable *) |
Evaluate a midgame position with a Null Window Search algorithm. More... | |
int | PVS_shallow (Search *, int, int, int) |
Evaluate a midgame position at shallow depth. More... | |
bool | is_pv_ok (Search *, int, int) |
Check if PV is ok. More... | |
void | record_best_move (Search *, const Board *, const Move *, const int, const int, const int) |
Record best move. More... | |
int | PVS_root (Search *, const int, const int, const int) |
Principal Variation Search algorithm at the root of the tree. More... | |
int | aspiration_search (Search *, int, int, const int, int) |
Aspiration window. More... | |
void | iterative_deepening (Search *, int, int) |
Iterative deepening. More... | |
void * | search_run (void *) |
Search the bestmove of a given board. More... | |
int | search_guess (Search *, const Board *) |
Guess the bestmove of a given board. More... | |
void | search_stop_all (Search *, const Stop) |
Stop the search. More... | |
void | search_set_state (Search *, const Stop) |
Set the search running/waiting state. More... | |
void | search_observer (Result *) |
default observer. More... | |
void | search_set_observer (Search *, void(*Observer)(Result *)) |
set observer. More... | |
void | search_share (const Search *, Search *) |
Share search information. More... | |
int | search_count_tasks (const Search *) |
Count the number of tasks used in parallel search. More... | |
bool | is_depth_solving (const int, const int) |
Check if final score use pv_extension or is solved. More... | |
int | solvable_depth (const long long, int) |
Compute the deepest level that can be solved given a limited time... More... | |
void | pv_debug (Search *, const Move *, FILE *) |
Debug PV. More... | |
int | search_get_pv_cost (Search *) |
Compute a cost as a combination of node count, depth, etc. from hash_table. More... | |
void | show_current_move (FILE *f, Search *, const Move *, const int, const int, const bool) |
int | search_bound (const Search *, int) |
bound root scores according to stable squares More... | |
Variables | |
struct Level | LEVEL [61][61] |
const int | QUADRANT_ID [] |
const Selectivity | selectivity_table [] |
const int | NO_SELECTIVITY |
const int | NWS_STABILITY_THRESHOLD [] |
const int | PVS_STABILITY_THRESHOLD [] |
const int | SQUARE_TYPE [] |
typedef struct Selectivity Selectivity |
Selectivity probcut
int aspiration_search | ( | Search * | search, |
int | alpha, | ||
int | beta, | ||
const int | depth, | ||
int | score | ||
) |
Aspiration window.
search | Search. |
alpha | Alpha bound. |
beta | Beta bound. |
depth | Depth. |
score | Previous score. |
|
inline |
Get the final score.
Get the final score, when 1 empty squares remain. The following code has been adapted from Zebra by Gunnar Anderson.
board | Board to evaluate. |
beta | Beta bound. |
x | Last empty square to play. |
int get_pv_extension | ( | const int | depth, |
const int | n_empties | ||
) |
Compute the pv_extension.
depth | Depth. |
n_empties | Game stage (number of empty squares). |
bool is_depth_solving | ( | const int | depth, |
const int | n_empties | ||
) |
Check if final score use pv_extension or is solved.
depth | search depth. |
n_empties | position depth. |
bool is_pv_ok | ( | Search * | search, |
int | bestmove, | ||
int | search_depth | ||
) |
Check if PV is ok.
search | Search. |
bestmove | Best move. |
search_depth | Depth. |
void iterative_deepening | ( | Search * | search, |
int | alpha, | ||
int | beta | ||
) |
int NWS_endgame | ( | Search * | search, |
const int | alpha | ||
) |
Evaluate an endgame position with a Null Window Search algorithm.
This function is used when there are still many empty squares on the board. Move ordering, hash table cutoff, enhanced transposition cutoff, etc. are used in order to diminish the size of the tree to analyse, but at the expense of a slower speed.
search | Search. |
alpha | Alpha bound. |
Evaluate a midgame position with a Null Window Search algorithm.
This function is used when there are still many empty squares on the board. Move ordering, hash table cutoff, enhanced transposition cutoff, etc. are used in order to diminish the size of the tree to analyse, but at the expense of a slower speed.
search | Search. |
alpha | Alpha bound. |
depth | Depth. |
parent | Parent node. |
Evaluate a midgame position with a Null Window Search algorithm.
This function is used when there are still many empty squares on the board. Move ordering, hash table cutoff, enhanced transposition cutoff, etc. are used in order to diminish the size of the tree to analyse, but at the expense of a slower speed.
search | search. |
alpha | lower bound. |
depth | Search remaining depth. |
hash_table | Hash Table to use. |
Debug PV.
search | Search. |
bestmove | Best move. |
f | Output stream. |
Evaluate a position with a deep Principal Variation Search algorithm.
This function is used when there are still many empty squares on the board. Move ordering, hash table cutoff, enhanced transposition cutoff, etc. are used in order to diminish the size of the tree to analyse, but at the expense of a slower speed.
search | Search. |
alpha | Lower bound. |
beta | Upper bound. |
depth | Depth. |
parent | Parent node. |
int PVS_root | ( | Search * | search, |
const int | alpha, | ||
const int | beta, | ||
const int | depth | ||
) |
Principal Variation Search algorithm at the root of the tree.
this function solves the position provided within the limits set by the alpha and beta bounds. The movelist parameter is updated so that the bestmove is the first of the list when the search ended.
search | Search. |
alpha | Alpha bound. |
beta | Beta bound. |
depth | Remaining depth. |
int PVS_shallow | ( | Search * | search, |
int | alpha, | ||
int | beta, | ||
int | depth | ||
) |
Evaluate a midgame position at shallow depth.
This function is used when there are still many empty squares on the board. Move ordering, hash table cutoff, enhanced transposition cutoff, etc. are used in order to diminish the size of the tree to analyse, but at the expense of a slower speed.
void result_print | ( | Result * | result, |
FILE * | f | ||
) |
Print the current search result.
result | Last search result. |
f | output stream. |
void search_adjust_time | ( | Search * | search, |
const bool | once | ||
) |
Give more time.
search | Search. |
once | A flag to prevent further time extension. |
int search_bound | ( | const Search * | search, |
int | score | ||
) |
bound root scores according to stable squares
search | Position to search. |
score | score to bound. |
void search_check_timeout | ( | Search * | search | ) |
Check if it can iterate more...
search | Search. |
void search_cleanup | ( | Search * | search | ) |
Clean-up some search data.
search | search. |
long long search_clock | ( | Search * | search | ) |
Clone a search for parallel search.
search | search. |
master | search to be cloned. |
unsigned long long search_count_nodes | ( | Search * | search | ) |
int search_count_tasks | ( | const Search * | search | ) |
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).
Before looping over each moves to search at next ply, ETC looks if a cutoff is available from the hashtable. This version also looks for a cutoff based on stability.
search | Current position. |
movelist | List of moves for the current position. |
hash_code | Hashing code. |
depth | Search depth. |
selectivity | Search selectivity. |
alpha | Alpha bound. |
score | Score to return in case a cutoff is found. |
bool search_ETC_PVS | ( | Search * | , |
MoveList * | , | ||
unsigned long long | , | ||
const int | , | ||
const int | , | ||
volatile int * | , | ||
volatile int * | , | ||
int * | |||
) |
int search_eval_0 | ( | Search * | search | ) |
evaluate a midgame position with the evaluation function.
search | Position to evaluate. |
int search_eval_1 | ( | Search * | search, |
const int | alpha, | ||
int | beta | ||
) |
Evaluate a position at depth 1.
As an optimization, the last move is used to only updates the evaluation features.
search | Position to evaluate. |
alpha | Alpha bound. |
beta | Beta bound. |
int search_eval_2 | ( | Search * | search, |
int | alpha, | ||
const int | beta | ||
) |
Evaluate a position at depth 2.
Simple alpha-beta with no move sorting.
search | Position to evaluate. |
alpha | Lower bound |
beta | Upper bound |
void search_free | ( | Search * | search | ) |
Free the search allocated ressource.
Free a previously initialized search structure.
search | search. |
Get a list of legal moves.
Compute the complete list of legal moves and store it into a simple linked list, to fasten ulterior move sorting. Note: at this point the list is sorted from A1 to H8 (i.e. unsorted).
search | Search. |
movelist | List of moves. |
int search_get_pv_cost | ( | Search * | search | ) |
Compute a cost as a combination of node count, depth, etc. from hash_table.
The board is supposed to be updated by a move after the root position.
search | Search. |
void search_global_init | ( | void | ) |
Global initialisations.
void search_init | ( | Search * | search | ) |
Init the main search.
Initialize a new search structure.
search | search. |
void search_observer | ( | Result * | result | ) |
default observer.
result | search results to print. |
void search_pass_endgame | ( | Search * | search | ) |
Update the search state after a passing move.
search | search. |
void search_print | ( | Search * | , |
const int | , | ||
const int | , | ||
const char | , | ||
FILE * | |||
) |
void search_print_pv | ( | Search * | , |
const int | , | ||
const char * | , | ||
FILE * | |||
) |
void search_resize_hashtable | ( | Search * | search | ) |
Restore the search state as before a move.
search | search. |
move | played move. |
Restore the search state as before a move.
search | search. |
move | played move. |
void search_restore_pass_midgame | ( | Search * | search | ) |
Update the search state after a passing move.
search | search. |
void * search_run | ( | void * | v | ) |
Search the bestmove of a given board.
this is a function runable within its own thread. The board is supposed to have been set (by search_set_board()), and all search options (level, time, etc.) too. this function proceeds to some internal initialisations and then call the iterative deepening function, from where the search is actually done. After the search ends, some finalizations are done before the function returns.
v | Search cast as void. |
bool search_SC_NWS | ( | Search * | search, |
const int | alpha, | ||
int * | score | ||
) |
Stability Cutoff (TC).
search | Current position. |
alpha | Alpha bound. |
score | Score to return in case of a cutoff is found. |
bool search_SC_PVS | ( | Search * | search, |
volatile int * | alpha, | ||
volatile int * | beta, | ||
int * | score | ||
) |
Stability Cutoff (SC).
search | Current position. |
alpha | Alpha bound. |
beta | Beta bound, to adjust if necessary. |
score | Score to return in case of a cutoff is found. |
Set the board to analyze.
search | search. |
board | board. |
player | player's turn. |
void search_set_game_time | ( | Search * | search, |
const long long | t | ||
) |
set time to search.
This function should be called before each new search, with the accurate remaining time to do the whole search for the game.
search | Search. |
t | time in ms. |
void search_set_level | ( | Search * | search, |
const int | level, | ||
const int | n_empties | ||
) |
Set the search level.
Compute the couple (depth, selectivity) as a function of (level, n_empties)
search | search. |
level | search level. |
n_empties | Search stage. |
void search_set_move_time | ( | Search * | search, |
const long long | t | ||
) |
set time to search.
This function should be called before each new search, with the accurate remaining time to do the whole search for this move.
search | Search. |
t | time in ms. |
set observer.
search | Searched position. |
observer | call back function to print the current search. |
void search_set_ponder_level | ( | Search * | search, |
const int | level, | ||
const int | n_empties | ||
) |
Set the search running/waiting state.
search | Search. |
stop | State. |
void search_set_task_number | ( | Search * | search, |
const int | n | ||
) |
Change the number of task.
search | Search. |
n | New task number. |
void search_setup | ( | Search * | search | ) |
Set up various structure once the board has been set.
Initialize the list of empty squares, the parity and the evaluation function.
search | search. |
Share search information.
src | source search. |
dest | destination search. |
int search_solve | ( | const Search * | search | ) |
Get the final score.
Get the final score, when no move can be made.
search | Search. |
int search_solve_0 | ( | const Search * | search | ) |
Get the final score.
Get the final score, when the board is full.
search | Search. |
Stop the search.
search | Search. |
stop | Source of stopping. |
void search_swap_parity | ( | Search * | search, |
const int | x | ||
) |
Change parity.
search | Search. |
x | Played square. |
bool search_TC_NWS | ( | HashData * | data, |
const int | depth, | ||
const int | selectivity, | ||
const int | alpha, | ||
int * | score | ||
) |
bool search_TC_PVS | ( | HashData * | data, |
const int | depth, | ||
const int | selectivity, | ||
volatile int * | alpha, | ||
volatile int * | beta, | ||
int * | score | ||
) |
Transposition Cutoff (TC).
data | Transposition data. |
depth | Search depth. |
selectivity | Search selecticity level. |
alpha | Alpha bound, to adjust of necessary. |
beta | Beta bound, to adjust of necessary. |
score | Score to return in case of a cutoff is found. |
long long search_time | ( | Search * | search | ) |
Reset the alloted time.
Adjust the time when continuing the search from pondering.
search | Search. |
initial_board | Initial board. |
Update the search state after a move.
search | search. |
move | played move. |
Update the search state after a move.
search | search. |
move | played move. |
void search_update_pass_midgame | ( | Search * | search | ) |
Update the search state after a passing move.
search | search. |
void show_current_move | ( | FILE * | f, |
Search * | search, | ||
const Move * | move, | ||
const int | alpha, | ||
const int | beta, | ||
const bool | parallel | ||
) |
int solvable_depth | ( | const long long | limit, |
int | n_tasks | ||
) |
Compute the deepest level that can be solved given a limited time...
This is a very approximate computation... SMP_W & SMP_C depends on the depth and the position. The branching factor depends also of the position.
limit | Time limit in ms. |
n_tasks | Number of parallel tasks. |
struct Level LEVEL[61][61] |
|
extern |
level with no selectivity
|
extern |
threshold values to try stability cutoff during NWS search
|
extern |
threshold values to try stability cutoff during PVS search
|
extern |
a quadrant id for each square
|
extern |
predefined selectivity
|
extern |
square type