Fix force mode after setboard
[bonanza.git] / searchr.c
index 216967d..9a1d244 100644 (file)
--- a/searchr.c
+++ b/searchr.c
@@ -12,8 +12,7 @@ static int CONV mpv_set_bound( int alpha );
 static int CONV mpv_find_min( int *pnum );
 static int CONV mpv_add_result( tree_t * restrict ptree, int value );
 static void CONV mpv_sub_result( unsigned int move );
-static void CONV mpv_out( tree_t * restrict ptree, int turn,
-                         unsigned int time );
+static void CONV mpv_out( tree_t * restrict ptree, int turn, unsigned int time, int newest );
 #endif
 
 #if defined(NO_STDOUT) && defined(NO_LOGGING)
@@ -315,6 +314,21 @@ searchr( tree_t * restrict ptree, int alpha, int beta, int turn, int depth )
 }
 
 
+#ifdef XBOARD
+void CONV
+out_xboard_move( int move, int tt )
+{
+        int from = I2From(move), to = I2To(move);
+        char inPromoZone = tt > 0 ? from >= 6*9 || to >= 6*9 : to < 3*9|| from < 3*9;
+        if(from >= nsquare)
+          Out(" %c@%c%c", "PLNSGBR"[From2Drop(from)-1], 'a'+to%9, '9'-to/9);
+        else
+          Out(" %c%c%c%c%s", 'a'+from%9, '9'-from/9, 'a'+to%9, '9'-to/9,
+              inPromoZone ? I2IsPromote(move) ? "+" : "=" : "");
+}
+#endif
+
+
 void CONV
 out_pv( tree_t * restrict ptree, int value, int turn, unsigned int time )
 {
@@ -356,7 +370,12 @@ out_pv( tree_t * restrict ptree, int value, int turn, unsigned int time )
       if ( ptree->pv[0].length )
        {
 #ifdef XBOARD
-          if(xboard_mode) Out("%2d %6d %6d %8d ", iteration_depth, value, time/10, 1); else
+          if(xboard_mode) {
+           Out("%2d %6d %6d %8d ", iteration_depth, value, time/10, 1);
+           if(game_status & flag_pondering && ! analyze_mode) {
+             Out("("); out_xboard_move( ponder_move, 1-tt ); Out(") ");
+           }
+         } else
 #endif
          if ( root_move_list[root_index].status & flag_first )
            {
@@ -370,13 +389,7 @@ out_pv( tree_t * restrict ptree, int value, int turn, unsigned int time )
     {
 #ifdef XBOARD
       if(xboard_mode && is_out) { // print PV move in WB format
-        int move = ptree->pv[0].a[ply], from = I2From(move), to = I2To(move);
-        char inPromoZone = tt > 0 ? from >= 6*9 || to >= 6*9 : to < 3*9|| from < 3*9;
-        if(from >= nsquare)
-          Out(" %c@%c%c", "PLNSGBR"[From2Drop(from)-1], 'a'+to%9, '9'-to/9);
-        else
-          Out(" %c%c%c%c%s", 'a'+from%9, '9'-from/9, 'a'+to%9, '9'-to/9,
-              inPromoZone ? I2IsPromote(move) ? "+" : "=" : "");
+        out_xboard_move( ptree->pv[0].a[ply], tt );
       } else
 #endif
       if ( is_out )
@@ -427,13 +440,7 @@ out_pv( tree_t * restrict ptree, int value, int turn, unsigned int time )
          
 #ifdef XBOARD
       if(xboard_mode && is_out) { // print PV move in WB format
-        int move = ptree->pv[0].a[ply], from = I2From(move), to = I2To(move);
-        char inPromoZone = tt > 0 ? from >= 6*9 || to >= 6*9 : to < 3*9|| from < 3*9;
-        if(from >= nsquare)
-          Out(" %c@%c%c", "PLNSGBR"[From2Drop(from)-1], 'a'+to%9, '9'-to/9);
-        else
-          Out(" %c%c%c%c%s", 'a'+from%9, '9'-from/9, 'a'+to%9, '9'-to/9,
-              inPromoZone ? I2IsPromote(move) ? "+" : "=" : "");
+        out_xboard_move( ptree->pv[0].a[ply], tt );
       } else
 #endif
          if ( is_out )
@@ -606,7 +613,7 @@ next_root_move( tree_t * restrict ptree, int turn )
 
 #if defined(MPV)
 static void CONV
-mpv_out( tree_t * restrict ptree, int turn, unsigned int time )
+mpv_out( tree_t * restrict ptree, int turn, unsigned int time, int newest )
 {
   int mpv_out, ipv, best;
 
@@ -643,12 +650,23 @@ mpv_out( tree_t * restrict ptree, int turn, unsigned int time )
 
          str = str_time_symple( time );
          ply = mpv_pv[ipv].depth;
+#ifdef XBOARD
+          if(xboard_mode) {
+            if(ipv != newest) continue; // skip all but the newest, to prevent duplicates
+            Out("%2d %6d %6d %8d ", ply, value, time/10, 1);
+          } else
+#endif
          if ( ! ipv ) { Out( "o%2d %6s %7.2f ", ply, str, dvalue ); }
          else         { Out( " %2d        %7.2f ", ply, dvalue ); }
        }
 
       for ( ply = 1; ply <= mpv_pv[ipv].length; ply++ )
        {
+#ifdef XBOARD
+      if(xboard_mode && is_out) { // print PV move in WB format
+        out_xboard_move( mpv_pv[ipv].a[ply], tt );
+      } else
+#endif
          if ( is_out )
            {
              if ( ply > 1 && ! ( (ply-1) % 5 ) )
@@ -688,6 +706,11 @@ mpv_out( tree_t * restrict ptree, int turn, unsigned int time )
                if ( mpv_pv[ipv].a[i]
                     == mpv_pv[ipv].a[ply] ) { goto rep_esc; }
              
+#ifdef XBOARD
+      if(xboard_mode && is_out) { // print PV move in WB format
+        out_xboard_move( mpv_pv[ipv].a[ply], tt );
+      } else
+#endif
              if ( is_out )
                {
                  if ( ply > 1 && ! ( (ply-1) % 5 ) )
@@ -780,7 +803,7 @@ mpv_add_result( tree_t * restrict ptree, int value )
 {
   pv_t pv_tmp, pv;
   unsigned int time;
-  int i, vmin, num;
+  int i, vmin, num, new_pv;
 
   vmin = mpv_find_min( &num );
   assert( num <= mpv_num );
@@ -825,6 +848,7 @@ mpv_add_result( tree_t * restrict ptree, int value )
 
   pv      = ptree->pv[1];
   pv.a[0] = (unsigned int)(value+32768);
+  new_pv = i; // [HGM] xboard: remember which is the new one, so we can print only that
   do {
     assert( i < mpv_num*2 );
     assert( i < root_nmove*2 );
@@ -836,7 +860,7 @@ mpv_add_result( tree_t * restrict ptree, int value )
 
   if ( get_elapsed( &time ) < 0 ) { return -1; }
 
-  mpv_out( ptree, root_turn, time - time_start );
+  mpv_out( ptree, root_turn, time - time_start, new_pv );
 
   return 1;
 }