Add XBoard protocol drivers
[bonanza.git] / searchr.c
index a3aba06..5484e16 100644 (file)
--- a/searchr.c
+++ b/searchr.c
@@ -24,6 +24,10 @@ static int next_root_move( tree_t * restrict ptree );
 static int next_root_move( tree_t * restrict ptree, int turn );
 #endif
 
+#ifdef XBOARD
+extern char xboard_mode;
+#endif
+
 int
 searchr( tree_t * restrict ptree, int alpha, int beta, int turn, int depth )
 {
@@ -242,6 +246,9 @@ out_pv( tree_t * restrict ptree, int value, int turn, unsigned int time )
       if ( ptree->pv[0].length )
        {
          int i = find_root_move( ptree->pv[0].a[1] );
+#ifdef XBOARD
+        if(xboard_mode) Out("%2d %6d %6d %8d ", iteration_depth, value, time/10, 1); else
+#endif
          if ( root_move_list[i].status & flag_first )
            {
              Out( " %2d %6s %7.2f ", iteration_depth, str, dvalue );
@@ -252,6 +259,17 @@ out_pv( tree_t * restrict ptree, int value, int turn, unsigned int time )
 
   for ( ply = 1; ply <= ptree->pv[0].length; ply++ )
     {
+#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) ? "+" : "=" : "");
+      } else
+#endif
       if ( is_out )
        {
          if ( ply > 1 && ! ( (ply-1) % 4 ) )
@@ -287,6 +305,17 @@ out_pv( tree_t * restrict ptree, int value, int turn, unsigned int time )
          for ( i = 1; i < ply; i++ )
            if ( ptree->pv[0].a[i] == ptree->pv[0].a[ply] ) { goto rep_esc; }
          
+#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) ? "+" : "=" : "");
+      } else
+#endif
          if ( is_out )
            {
              if ( ply > 1 && ! ( (ply-1) % 4 ) )
@@ -401,6 +430,9 @@ next_root_move( tree_t * restrict ptree, int turn )
       ptree->current_move[1]    = root_move_list[i].move;
 
 #if ! ( defined(NO_STDOUT) && defined(NO_LOGGING) )
+#ifdef XBOARD
+      if(!xboard_mode)
+#endif
       if ( iteration_depth > 5 )
        {
          const char *str_move;