/* * Extracts a command from the engine input buffer. * * The command is removed from the buffer. * If the command is a move, the move is made. */ void NextEngineCmd( void ) { char engineinput[BUF_SIZE]=""; char enginemovestr[BUF_SIZE]=""; leaf* enginemove; if ( strlen( engineinputbuf ) > 0 ) { if ( GetNextLine( engineinputbuf, engineinput ) > 0 ) { dbg_printf("< ENGINE: %s\n", engineinput); if ( strncmp( engineinput, "move", 4 ) == 0 ) { /* Input from engine is a move */ sscanf( engineinput, "move %s", enginemovestr ); enginemove = ValidateMove( enginemovestr ); if ( enginemove == (leaf *) NULL ) { dbg_printf( "Bad move from engine\n" ); } else { dbg_printf( "Engine move: <%s> (%d,%d)\n", enginemovestr, (enginemove!=NULL ? enginemove->move : -1), (enginemove!=NULL ? enginemove->score : -1) ); SANMove (enginemove->move, 1); MakeMove( board.side, &(enginemove->move) ); strcpy (Game[GameCnt].SANmv, SANmv); if ( !(flags & XBOARD) ) { //ShowBoard(); dbg_printf("USER <: My move is : %s\n", SANmv); //printf( "\nMy move is : %s\n", SANmv ); printf( "\n<%i:%i>\n", FROMSQ(enginemove->move), TOSQ(enginemove->move) ); fflush( stdout ); } else { dbg_printf("USER <: %d. ... %s\n", GameCnt/2 + 1, enginemovestr ); printf ("%d. ... %s\n", GameCnt/2 + 1, enginemovestr ); fflush( stdout ); dbg_printf("USER <: My move is : %s\n", enginemovestr); printf( "My move is : %s\n", enginemovestr ); fflush( stdout ); } RealGameCnt = GameCnt; showprompt = 1; /* Check if the color must be changed, e.g. after a go command. */ if ( changeColor ) { RealGameCnt = GameCnt; RealSide = board.side; } } } else { dbg_printf( "USER <: %s\n",engineinput ); printf( "%s", engineinput ); if ( flags & XBOARD ) { fflush( stdout ); } } } } }
inline void ShowThinking (leaf *p, int ply) { if (flags & XBOARD) return; if (!(flags & POST)) return; if (NodeCnt < 500000 && (flags & SOLVE)) { /* printf("NodeCnt = %d\n",NodeCnt); getchar(); */ return; } SANMove (p->move, ply); fprintf (stderr, "\r%2d. %2d/%2d%10s ", Idepth/DEPTH, (int) (p-TreePtr[ply]+1), (int) (TreePtr[ply+1]-TreePtr[ply]), SANmv); fflush (stderr); }
void ShowMoveList (int ply) /************************************************************************** * * Print out the move list. * **************************************************************************/ { leaf *node; int i = 0; for (node = TreePtr[ply]; node < TreePtr[ply+1]; node++) { SANMove (node->move, ply); printf ("%5s %3d\t", SANmv, SwapOff(node->move)); if (++i == 5) { printf ("\n"); i = 0; } } printf ("\n"); }
void ShowLine (int move __attribute__ ((unused)), int score, char c) /***************************************************************************** * * Print out the latest PV found during the search. * The only move we know is the root move. The rest of the PV is taken * from the hash table. This strategy avoids all the headaches associated * with returning the PV up from the leaf to the root. * *****************************************************************************/ { int i, len; int pvar[MAXPLYDEPTH]; /* SMC */ if (!(flags & POST)) return; if (NodeCnt < 500000 && (flags & SOLVE)) { /* printf("NodeCnt = %d\n",NodeCnt); getchar(); */ return; } if (Idepth == DEPTH && c == '&') return; if ((flags & XBOARD) && c == '&') return; if (rootscore == -INFINITY-1) return; GetElapsed (); /* * What is the reason for these different output formats, in * particular for et? */ if (flags & XBOARD) { if (score > MATE-255) { printf ("%d%c Mat%d %d %lu\t", Idepth/DEPTH, c, (int)(MATE+2-abs(score))/2, (int)(et*100), NodeCnt+QuiesCnt); if (ofp != stdout) fprintf (ofp,"%2d%c%7.2f Mat%02d%10lu\t", Idepth/DEPTH, c, et, (MATE+2-abs(score))/2, NodeCnt+QuiesCnt); } else if (score < -MATE+255) { printf ("%d%c -Mat%2d %d %lu\t", Idepth/DEPTH, c, (int)(MATE+2-abs(score))/2, (int)(et*100), NodeCnt+QuiesCnt); if (ofp != stdout) fprintf (ofp,"%2d%c%7.2f -Mat%02d%10lu\t", Idepth/DEPTH, c, et, (MATE+2-abs(score))/2, NodeCnt+QuiesCnt); } else { printf ("%d%c %d %d %lu\t", Idepth/DEPTH, c, (int)score, (int)(et*100), NodeCnt+QuiesCnt); if (ofp != stdout) fprintf (ofp,"%2d%c%7.2f%7d%10lu\t", Idepth/DEPTH, c, et, score, NodeCnt+QuiesCnt); } } else { if (score > MATE-255) { printf ("\r%2d%c%7.2f Mat%02d%10lu\t", Idepth/DEPTH, c, et, (MATE+2-abs(score))/2, NodeCnt+QuiesCnt); if (ofp != stdout) fprintf (ofp,"\r%2d%c%7.2f Mat%02d%10lu\t", Idepth/DEPTH, c, et, (MATE+2-abs(score))/2, NodeCnt+QuiesCnt); } else if (score < -MATE+255) { printf ("\r%2d%c%7.2f -Mat%02d%10lu\t", Idepth/DEPTH, c, et, (MATE+2-abs(score))/2, NodeCnt+QuiesCnt); if (ofp != stdout) fprintf (ofp,"\r%2d%c%7.2f -Mat%02d%10lu\t", Idepth/DEPTH, c, et, (MATE+2-abs(score))/2, NodeCnt+QuiesCnt); } else { printf ("\r%2d%c%7.2f%7d%10lu\t", Idepth/DEPTH, c, et, score, NodeCnt+QuiesCnt); if (ofp != stdout) fprintf (ofp,"\r%2d%c%7.2f%7d%10lu\t", Idepth/DEPTH, c, et, score, NodeCnt+QuiesCnt); } } if (c == '-') { printf ("\n"); if (ofp != stdout) fprintf(ofp, "\n"); return; } else if (c == '+') { SANMove (RootPV, 1); printf (" %s\n", SANmv); if (ofp != stdout) fprintf (ofp," %s\n", SANmv); return; } SANMove (RootPV, 1); printf (" %s", SANmv); if (ofp != stdout) fprintf (ofp," %s", SANmv); MakeMove (board.side, &RootPV); TreePtr[3] = TreePtr[2]; GenMoves (2); len = strlen (SANmv); i = 2; pvar[1] = RootPV; /* We fill the rest of the PV with moves from the hash table */ if ((flags & USEHASH)) { while (TTGetPV (board.side, i, rootscore, &pvar[i])) { if ((MATESCORE(score) && abs(score) == MATE+2-i) || Repeat ()) break; if (len >= 32) { printf ("\n\t\t\t\t"); if (ofp != stdout) fprintf (ofp,"\n\t\t\t\t"); len = 0; } SANMove (pvar[i], i); printf (" %s", SANmv); if (ofp != stdout) fprintf (ofp," %s", SANmv); MakeMove (board.side, &pvar[i]); TreePtr[i+2] = TreePtr[i+1]; GenMoves (++i); len += strlen (SANmv); } } printf ("\n"); if (ofp != stdout) fprintf(ofp,"\n"); for (--i; i; i--) UnmakeMove (board.side, &pvar[i]); fflush (stdout); if (ofp != stdout) fflush (ofp); }