home *** CD-ROM | disk | FTP | other *** search
/ Dream 57 / Amiga_Dream_57.iso / Amiga / Jeux / Reflexion / Crafty-15.19.lha / crafty-15.19 / src / analyze.c next >
C/C++ Source or Header  |  1998-09-13  |  4KB  |  120 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include "chess.h"
  5. #include "data.h"
  6.  
  7. /* last modified 05/19/97 */
  8. /*
  9. ********************************************************************************
  10. *                                                                              *
  11. *   Analyze() is used to handle the "analyze" command.  this mode basically    *
  12. *   puts Crafty into a "permanent pondering" state, where it reads a move from *
  13. *   the input stream, and then "ponders" for the opposite side.  whenever a    *
  14. *   move is entered, Crafty reads this move, updates the game board, and then  *
  15. *   starts "pondering" for the other side.                                     *
  16. *                                                                              *
  17. ********************************************************************************
  18. */
  19. void Analyze() {
  20.   int i, move, back_number, readstat=1;
  21.   TREE *tree=local[0];
  22. /*
  23.  ----------------------------------------------------------
  24. |                                                          |
  25. |  initialize.                                             |
  26. |                                                          |
  27.  ----------------------------------------------------------
  28. */
  29.     ponder_move=0;
  30.     analyze_mode=1;
  31.     draw_score_normal=1;
  32.     if (!xboard) display_options|=1+2+4;
  33.     printf("Analyze Mode: type \"exit\" to terminate.\n");
  34. /*
  35.  ----------------------------------------------------------
  36. |                                                          |
  37. |  now loop waiting on input, searching the current        |
  38. |  position continually until a move comes in.             |
  39. |                                                          |
  40.  ----------------------------------------------------------
  41. */
  42.     do {
  43.       do {
  44.         last_pv.path_iteration_depth=0;
  45.         last_pv.path_length=0;
  46.         analyze_move_read=0;
  47.         pondering=1;
  48.         tree->position[1]=tree->position[0];
  49.         (void) Iterate(wtm,think,0);
  50.         pondering=0;
  51.         if (book_move) moves_out_of_book=0;
  52.         if (!xboard) {
  53.           if (wtm) printf("analyze.White(%d): ",move_number);
  54.           else printf("analyze.Black(%d): ",move_number);
  55.           fflush(stdout);
  56.         }
  57.         if (!analyze_move_read) do {
  58.           readstat=Read(1,buffer);
  59.           if (readstat < 0) break;
  60.           nargs=ReadParse(buffer,args,"     ;");
  61.           Print(4095,"%s\n",buffer);
  62.           if (strstr(args[0],"timeleft") && !xboard) {
  63.             if (wtm) printf("analyze.White(%d): ",move_number);
  64.             else printf("analyze.Black(%d): ",move_number);
  65.             fflush(stdout);
  66.           }
  67.         } while (strstr(args[0],"timeleft"));
  68.         else nargs=ReadParse(buffer,args,"     ;");
  69.         if (readstat < 0) break;
  70.         move=0;
  71.         if (!strcmp(args[0],"exit")) break;
  72.         move=InputMove(tree,args[0],0,wtm,1,0);
  73.         if (move) {
  74.           fseek(history_file,((move_number-1)*2+1-wtm)*10,SEEK_SET);
  75.           fprintf(history_file,"%9s\n",OutputMove(tree,move,0,wtm));
  76.           if (!xboard) {
  77.             if (wtm) Print(128,"White(%d): ",move_number);
  78.               else Print(128,"Black(%d): ",move_number);
  79.             Print(128,"%s\n",OutputMove(tree,move,0,wtm));
  80.           }
  81.           else {
  82.             if (wtm) Print(128,"White(%d): ",move_number);
  83.               else Print(128,"Black(%d): ",move_number);
  84.             Print(128,"%s\n",OutputMove(tree,move,0,wtm));
  85.           }
  86.           MakeMoveRoot(tree,move,wtm);
  87.           display=tree->pos;
  88.           last_mate_score=0;
  89.         }
  90.         else if (OptionMatch("back",args[0])) {
  91.           if (nargs > 1) back_number=atoi(args[1]);
  92.           else back_number=1;
  93.           for (i=0;i<back_number;i++) {
  94.             wtm=ChangeSide(wtm);
  95.             if (ChangeSide(wtm)) move_number--;
  96.           }
  97.           if (move_number == 0) {
  98.             move_number=1;
  99.             wtm=1;
  100.           }
  101.           sprintf(buffer,"reset %d",move_number);
  102.           (void) Option(tree);
  103.           display=tree->pos;
  104.         }
  105.         else {
  106.           pondering=0;
  107.           if (Option(tree) == 0) printf("illegal move.\n");
  108.           pondering=1;
  109.           display=tree->pos;
  110.         }
  111.       } while (!move);
  112.       if (readstat < 0 || !strcmp(args[0],"exit")) break;
  113.       wtm=ChangeSide(wtm);
  114.       if (wtm) move_number++;
  115.     } while (1);
  116.     analyze_mode=0;
  117.     printf("analyze complete.\n");
  118.     pondering=0;
  119. }
  120.