if (searching_pv) {
searching_pv = FALSE;
/* make the pv have highest move ordering: */
if (from == pv[1][ply].from && target == pv[1][ply].target
&& promoted == pv[1][ply].promoted) {
searching_pv = TRUE;
move_ordering[i] += INF;
else {
/* add the history heuristic bonus: */
move_ordering[i] += (history_h[from][target]>>i_depth);
/* add the killer move heuristic bonuses: */
/* if not searching the pv: */
else {
/* give captures precedence in move ordering, and order captures by
material gain */
killers...etc....
order_moves is also called by qsearch() and search(). root_search() calls search() only. search() calls search() only.
When does searching_pv = FALSE? Is it only TRUE if searching the first move at the root? Could it be false anywhere else? TRUE again later? Thanks!
It is likely true when walking the PV at the beginning of a new depth iteration. When the search is depened, you want to try the moves from the PV from last iteration first. So searching_pv is true at the nodes all the way down the left side of the search tree.
at root...
searching_pv = true
move_ordering()
make
if legal
search -beta -alpha
unmake
if score > alpha
return best_move
move_ordering()
if searching_pv {
searching_pv = false
if (from == pv[1][ply].from && target == pv[1][ply].target
&& promoted == pv[1][ply].promoted) {
searching_pv = true
else{
other move ordering
So will the way this flag is set still work with PVS? Because Im thinking when search() is called from the root the flag will always = true the way it is now, regardless if the call is from -alpha alpha.