Beispiel #1
0
/*
 *******************************************************************************
 *                                                                             *
 *   Analyze() is used to handle the "analyze" command.  This mode basically   *
 *   puts Crafty into a "permanent pondering" state, where it reads a move     *
 *   from the input stream, and then "ponders" for the opposite side.          *
 *   Whenever a move is entered, Crafty reads this move, updates the game      *
 *   board, and then starts "pondering" for the other side.                    *
 *                                                                             *
 *   The purpose of this mode is to force Crafty to follow along in a game,    *
 *   providing analysis continually for the side on move until a move is       *
 *   entered, advancing the game to the next position.                         *
 *                                                                             *
 *******************************************************************************
 */
void Analyze() {
  int i, move, back_number, readstat = 1;
  TREE *const tree = block[0];

/*
 ************************************************************
 *                                                          *
 *  Initialize.                                             *
 *                                                          *
 ************************************************************
 */
  int save_swindle_mode = swindle_mode;

  swindle_mode = 0;
  ponder_move = 0;
  analyze_mode = 1;
  if (!xboard)
    display_options |= 1 + 2 + 4;
  _printf("Analyze Mode: type \"exit\" to terminate.\n");
/*
 ************************************************************
 *                                                          *
 *  Now loop waiting on input, searching the current        *
 *  position continually until a move comes in.             *
 *                                                          *
 ************************************************************
 */
  do {
    do {
      last_pv.pathd = 0;
      last_pv.pathl = 0;
      input_status = 0;
      pondering = 1;
      tree->status[1] = tree->status[0];
      Iterate(game_wtm, think, 0);
      pondering = 0;
      if (book_move)
        moves_out_of_book = 0;
      if (!xboard) {
        if (game_wtm)
          _printf("analyze.White(%d): ", move_number);
        else
          _printf("analyze.Black(%d): ", move_number);
        fflush(stdout);
      }
/*
 ************************************************************
 *                                                          *
 *  If we get back to here, something has been typed in and *
 *  is in the command buffer normally, unless the search    *
 *  terminated naturally due to finding a mate or reaching  *
 *  the max depth allowable.                                *
 *                                                          *
 ************************************************************
 */
      if (!input_status)
        do {
          readstat = Read(1, buffer);
          if (readstat < 0)
            break;
          nargs = ReadParse(buffer, args, " 	;");
          Print(128, "%s\n", buffer);
          if (strstr(args[0], "timeleft") && !xboard) {
            if (game_wtm)
              _printf("analyze.White(%d): ", move_number);
            else
              _printf("analyze.Black(%d): ", move_number);
            fflush(stdout);
          }
        } while (strstr(args[0], "timeleft"));
      else
        nargs = ReadParse(buffer, args, " 	;");
      if (readstat < 0)
        break;
      move = 0;
      if (!strcmp(args[0], "exit"))
        break;
/*
 ************************************************************
 *                                                          *
 *  First, check for the special analyze command "back n"   *
 *  and handle it if present, otherwise try Option() to see *
 *  if it recognizes the input as a command.                *
 *                                                          *
 ************************************************************
 */
      if (OptionMatch("back", args[0])) {
        if (nargs > 1)
          back_number = atoi(args[1]);
        else
          back_number = 1;
        for (i = 0; i < back_number; i++) {
          game_wtm = Flip(game_wtm);
          if (Flip(game_wtm))
            move_number--;
        }
        if (move_number == 0) {
          move_number = 1;
          game_wtm = 1;
        }
        sprintf(buffer, "reset %d", move_number);
        Option(tree);
        display = tree->position;
      } else if (Option(tree)) {
        display = tree->position;
      }
/*
 ************************************************************
 *                                                          *
 *  If InputMove() can recognize this as a move, make it,   *
 *  swap sides, and return to the top of the loop to call   *
 *  search from this new position.                          *
 *                                                          *
 ************************************************************
 */
      else if ((move = InputMove(tree, buffer, 0, game_wtm, 1, 0))) {
        char *outmove = OutputMove(tree, move, 0, game_wtm);

        if (history_file) {
          fseek(history_file, ((move_number - 1) * 2 + 1 - game_wtm) * 10,
              SEEK_SET);
          fprintf(history_file, "%9s\n", outmove);
        }
        if (game_wtm)
          Print(128, "White(%d): ", move_number);
        else
          Print(128, "Black(%d): ", move_number);
        Print(128, "%s\n", outmove);
        if (speech) {
          char announce[64];

          //strcpy(announce, SPEAK);
          //strcat(announce, outmove);
          //system(announce);

          SPEAK(outmove);
        }
        MakeMoveRoot(tree, move, game_wtm);
        display = tree->position;
        last_mate_score = 0;
        if (log_file)
          DisplayChessBoardFile(log_file, tree->position);
      }
/*
 ************************************************************
 *                                                          *
 *  If Option() didn't handle the input, then it is illegal *
 *  and should be reported to the user.                     *
 *                                                          *
 ************************************************************
 */
      else {
        pondering = 0;
        if (Option(tree) == 0)
          _printf("illegal move: %s\n", buffer);
        pondering = 1;
        display = tree->position;
      }
    } while (!move);
    if (readstat < 0 || !strcmp(args[0], "exit"))
      break;
    game_wtm = Flip(game_wtm);
    if (game_wtm)
      move_number++;
  } while (1);
  analyze_mode = 0;
  _printf("analyze complete.\n");
  pondering = 0;
  swindle_mode = save_swindle_mode;
}
void InitializeChessBoard(SEARCH_POSITION *new_pos)
{
  int i;

  if (strlen(initial_position)) {
    static char a1[80], a2[16], a3[16], a4[16], a5[16];
    static char *args[16]={a1,a2,a3,a4,a5,a5,a5,a5,a5,a5,a5,a5,a5,a5,a5,a5};
    int nargs;

    nargs=ReadParse(initial_position,args," ;");
    SetBoard(nargs,args,1);
  }
  else {
    for(i=0;i<64;i++) search.board[i]=empty;
    new_pos->rule_50_moves=0;
    opening=1;
    middle_game=0;
    end_game=0;
    largest_positional_score=60;
/*
   place pawns
*/
    for (i=0;i<8;i++) {
      search.board[i+8]=pawn;
      search.board[i+48]=-pawn;
    }
/*
   place knights
*/
    search.board[B1]=knight;
    search.board[G1]=knight;
    search.board[B8]=-knight;
    search.board[G8]=-knight;
/*
   place bishops
*/
    search.board[C1]=bishop;
    search.board[F1]=bishop;
    search.board[C8]=-bishop;
    search.board[F8]=-bishop;
/*
   place rooks
*/
    search.board[A1]=rook;
    search.board[H1]=rook;
    search.board[A8]=-rook;
    search.board[H8]=-rook;
/*
   place queens
*/
    search.board[D1]=queen;
    search.board[D8]=-queen;
/*
   place kings
*/
    search.board[E1]=king;
    search.board[E8]=-king;
/*
   initialize castling status so all castling is legal.
*/
    new_pos->w_castle=3;
    new_pos->b_castle=3;
/*
   initialize enpassant status.
*/
    new_pos->enpassant_target=0;
/*
   now, set the bit-boards.
*/
    SetChessBitBoards(new_pos);
  }
}
Beispiel #3
0
/*
 *******************************************************************************
 *                                                                             *
 *   Bench() runs a simple six-position benchmark to gauge Crafty's            *
 *   performance.  The test positons are hard-coded, and the benchmark is      *
 *   calculated much like it would with an external "test" file.  The test     *
 *   is a mix of opening, middlegame, and endgame positions, with both         *
 *   tactical and positional aspects.  (For those interested, the positions    *
 *   chosen are Bratko-Kopec 2, 4, 8, 12, 22 and 23.)  This test is a speed    *
 *   measure only; the actual solutions to the positions are ignored.          *
 *                                                                             *
 *******************************************************************************
 */
int Bench(int increase, int autotune) {
  uint64_t nodes = 0;
  int old_do, old_st, old_sd, total_time_used, pos, begin, end;
  FILE *old_books, *old_book;
  TREE *const tree = block[0];
  char fen[6][80] = {
    {"3r1k2/4npp1/1ppr3p/p6P/P2PPPP1/1NR5/5K2/2R5 w - - 0 1"},
    {"rnbqkb1r/p3pppp/1p6/2ppP3/3N4/2P5/PPP1QPPP/R1B1KB1R w KQkq - 0 1"},
    {"4b3/p3kp2/6p1/3pP2p/2pP1P2/4K1P1/P3N2P/8 w - - 0 1"},
    {"r3r1k1/ppqb1ppp/8/4p1NQ/8/2P5/PP3PPP/R3R1K1 b - - 0 1"},
    {"2r2rk1/1bqnbpp1/1p1ppn1p/pP6/N1P1P3/P2B1N1P/1B2QPP1/R2R2K1 b - - 0 1"},
    {"r1bqk2r/pp2bppp/2p5/3pP3/P2Q1P2/2N1B3/1PP3PP/R4RK1 b kq - 0 1"}
  };
  int fen_depth[6] = { 24, 20, 25, 21, 18, 19 };

/*
 ************************************************************
 *                                                          *
 *  Initialize.                                             *
 *                                                          *
 ************************************************************
 */
  begin = ReadClock();
  total_time_used = 0;
  old_st = search_time_limit;
  old_sd = search_depth;
  old_do = display_options;
  search_time_limit = 90000;
  display_options = 1;
  old_book = book_file;
  book_file = 0;
  old_books = books_file;
  books_file = 0;
  if (!autotune) {
    if (increase)
      Print(4095, "Running benchmark (modifying depth by %d plies). . .\n",
          increase);
    else
      Print(4095, "Running benchmark. . .\n");
    fflush(stdout);
  }
/*
 ************************************************************
 *                                                          *
 *  Now we loop through the six positions.  We use the      *
 *  ReadParse() procedure to break the FEN into tokens and  *
 *  then call SetBoard() to set up the positions.  Then a   *
 *  call to Iterate() and we are done.                      *
 *                                                          *
 ************************************************************
 */
  for (pos = 0; pos < 6; pos++) {
    strcpy(buffer, fen[pos]);
    nargs = ReadParse(buffer, args, " \t;=");
    SetBoard(tree, nargs, args, 0);
    search_depth = fen_depth[pos] + increase;
    InitializeHashTables();
    last_pv.pathd = 0;
    thinking = 1;
    tree->status[1] = tree->status[0];
    InitializeHashTables();
    Iterate(game_wtm, think, 0);
    thinking = 0;
    nodes += tree->nodes_searched;
    total_time_used += (program_end_time - program_start_time);
    printf(".");
    fflush(stdout);
  }
/*
 ************************************************************
 *                                                          *
 *  Benchmark done.  Now dump the results.                  *
 *                                                          *
 ************************************************************
 */
  if (!autotune)
    printf("\n");
  if (!autotune) {
    Print(4095, "Total nodes: %" PRIu64 "\n", nodes);
    Print(4095, "Raw nodes per second: %d\n",
        (int) ((double) nodes / ((double) total_time_used / (double) 100.0)));
    Print(4095, "Total elapsed time: %.2f\n",
        ((double) total_time_used / (double) 100.0));
  }
  input_stream = stdin;
  early_exit = 99;
  display_options = old_do;
  search_time_limit = old_st;
  search_depth = old_sd;
  books_file = old_books;
  book_file = old_book;
  NewGame(0);
  end = ReadClock();
  return end - begin;
}
Beispiel #4
0
/*
 *******************************************************************************
 *                                                                             *
 *   Interrupt() is used to read in a move when the operator types something   *
 *   while a search is in progress (during pondering as one example.)  This    *
 *   routine reads in a command (move) and then makes two attempts to use this *
 *   input:  (1) call Option() to see if the command can be executed;  (2) try *
 *   InputMove() to see if this input is a legal move;  If so, and we are      *
 *   pondering see if it matches the move we are pondering.                    *
 *                                                                             *
 *******************************************************************************
 */
void Interrupt(int ply) {
  int temp, i, left = 0, readstat, result, time_used;
  int save_move_number;
  TREE *const tree = block[0];

/*
 ************************************************************
 *                                                          *
 *   If trying to find a move to ponder, and the operator   *
 *   types a command, exit a.s.a.p.                         *
 *                                                          *
 ************************************************************
 */
  if (puzzling)
    abort_search = 1;
/*
 ************************************************************
 *                                                          *
 *   First check to see if this is a command by calling     *
 *   Option().  Option() will return a 0 if it didn't       *
 *   recognize the command; otherwise it returns a 1 if     *
 *   the command was executed, or a 2 if we need to abort   *
 *   the search to execute the command.                     *
 *                                                          *
 ************************************************************
 */
  else
    do {
      readstat = Read(0, buffer);
      if (readstat <= 0)
        break;
      nargs = ReadParse(buffer, args, " 	;");
      if (nargs == 0) {
        Print(128, "ok.\n");
        break;
      }
      if (strcmp(args[0], ".")) {
        save_move_number = move_number;
        if (!wtm)
          move_number--;
        if (root_wtm)
          Print(128, "Black(%d): %s\n", move_number, buffer);
        else
          Print(128, "White(%d): %s\n", move_number, buffer);
        move_number = save_move_number;
      }
/*
 ************************************************************
 *                                                          *
 *   "." command displays status of current search.         *
 *                                                          *
 ************************************************************
 */
      if (!strcmp(args[0], ".")) {
        if (xboard) {
          end_time = ReadClock();
          time_used = (end_time - start_time);
          printf("stat01: %d ", time_used);
          printf(BMF " ", tree->nodes_searched);
          printf("%d ", iteration_depth);
          for (i = 0; i < n_root_moves; i++)
            if (!(root_moves[i].status & 128))
              left++;
          printf("%d %d\n", left, n_root_moves);
          fflush(stdout);
          break;
        } else {
          end_time = ReadClock();
          time_used = (end_time - start_time);
          printf("time:%s ", DisplayTime(time_used));
          printf("nodes:" BMF "\n", tree->nodes_searched);
          DisplayTreeState(block[0], 1, 0, ply);
        }
      }
/*
 ************************************************************
 *                                                          *
 *   "mn" command is used to set the move number to a       *
 *   specific value...                                      *
 *                                                          *
 ************************************************************
 */
      else if (!strcmp("mn", args[0])) {
        if (nargs == 2) {
          move_number = atoi(args[1]);
          Print(128, "move number set to %d\n", move_number);
        }
      }
/*
 ************************************************************
 *                                                          *
 *   "?" command says "move now!"                           *
 *                                                          *
 ************************************************************
 */
      else if (!strcmp(args[0], "?")) {
        if (thinking) {
          time_abort = 1;
          abort_search = 1;
        }
      }
/*
 ************************************************************
 *                                                          *
 *   Next see if Option() recognizes this as a command.     *
 *                                                          *
 ************************************************************
 */
      else {
        save_move_number = move_number;
        if (!analyze_mode && !wtm)
          move_number--;
        result = Option(tree);
        move_number = save_move_number;
        if (result >= 2) {
          if (thinking && result != 3)
            Print(128, "command not legal now.\n");
          else {
            abort_search = 1;
            input_status = 2;
            break;
          }
        } else if ((result != 1) && analyze_mode) {
          abort_search = 1;
          input_status = 2;
          break;
        }
/*
 ************************************************************
 *                                                          *
 *   Now, check to see if the operator typed a move.  If    *
 *   so, and it matched the predicted move, switch from     *
 *   pondering to thinking to start the timer.  If this     *
 *   is a move, but not the predicted move, abort the       *
 *   search, and start over with the right move.            *
 *                                                          *
 ************************************************************
 */
        else if (!result) {
          if (pondering) {
            nargs = ReadParse(buffer, args, " 	;");
            temp = InputMove(tree, args[0], 0, Flip(root_wtm), 1, 1);
            if (temp) {
              if ((From(temp) == From(ponder_move)) &&
                  (To(temp) == To(ponder_move)) &&
                  (Piece(temp) == Piece(ponder_move)) &&
                  (Captured(temp) == Captured(ponder_move)) &&
                  (Promote(temp) == Promote(ponder_move))) {
                predicted++;
                input_status = 1;
                pondering = 0;
                thinking = 1;
                opponent_end_time = ReadClock();
                program_start_time = ReadClock();
                Print(128, "predicted move made.\n");
              } else {
                input_status = 2;
                abort_search = 1;
                break;
              }
            } else if (!strcmp(args[0], "go") || !strcmp(args[0], "move") ||
                !strcmp(args[0], "SP")) {
              abort_search = 1;
              break;
            } else
              Print(4095, "Illegal move: %s\n", args[0]);
          } else
            Print(4095, "unrecognized/illegal command: %s\n", args[0]);
        }
      }
    } while (1);
  if (log_file)
    fflush(log_file);
}
Beispiel #5
0
/*
 *******************************************************************************
 *                                                                             *
 *   Bench_PGO() runs a 64 position benchmark during the build process.  The   *
 *   test positons are hard-coded, and the benchmark is similiar to the normal *
 *   bench command.  It designed specifically to run with the makefile for     *
 *   profile guided optimizations.                                             *
 *                                                                             *
 *******************************************************************************
 */
int Bench_PGO(int increase, int autotune) {
  uint64_t nodes = 0;
  int old_do, old_st, old_sd, total_time_used, pos, begin, end, old_mt;
  FILE *old_books, *old_book;
  TREE *const tree = block[0];
  char fen[64][80] = {
    {"3q2k1/pb3p1p/4pbp1/2r5/PpN2N2/1P2P2P/5PP1/Q2R2K1 b"},
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4 w"},
    {"r4k2/pb2bp1r/1p1qp2p/3pNp2/3P1P2/2N3P1/PPP1Q2P/2KRR3 w"},
    {"r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w"}
  };
  int fen_depth = 16;

 /*
  ************************************************************
  *                                                          *
  *  Initialize.                                             *
  *                                                          *
  ************************************************************
  */
  begin = ReadClock();
  total_time_used = 0;
  old_st = search_time_limit;
  old_sd = search_depth;
  old_do = display_options;
  search_time_limit = 90000;
  display_options = 1;
  old_book = book_file;
  book_file = 0;
  old_books = books_file;
  books_file = 0;
  if (!autotune) {
    if (increase)
      Print(4095, "Running benchmark (modifying depth by %d plies). . .\n",
          increase);
    else
      Print(4095, "Running benchmark. . .\n");
    fflush(stdout);
  }
 /*
  ************************************************************
  *                                                          *
  *  Now we loop through the 64 positions.  We use the      *
  *  ReadParse() procedure to break the FEN into tokens and  *
  *  then call SetBoard() to set up the positions.  Then a   *
  *  call to Iterate() and we are done.                      *
  *                                                          *
  ************************************************************
  */
  for (pos = 0; pos < 64; pos++) {
    strcpy(buffer, fen[pos]);
    nargs = ReadParse(buffer, args, " \t;=");
    SetBoard(tree, nargs, args, 0);
    search_depth = fen_depth + increase;
    InitializeHashTables();
    last_pv.pathd = 0;
    thinking = 1;
    tree->status[1] = tree->status[0];
    InitializeHashTables();
    Iterate(game_wtm, think, 0);
    thinking = 0;
    nodes += tree->nodes_searched;
    total_time_used += (program_end_time - program_start_time);
    nodes_per_second =
        (uint64_t) tree->nodes_searched * 100 /
        Max((uint64_t) program_end_time - program_start_time, 1);
    if (pos % 7 == 0)
      Print(4095, "pos: ");
    Print(4095, "%d", pos + 1);
    Print(4095, "(%s) ", DisplayKMB(nodes_per_second, 0));
    if (pos % 7 == 6)
      Print(4095, "\n");
    fflush(stdout);
  }
  Print(4095, "\n");
 /*
  ************************************************************
  *                                                          *
  *  Benchmark done.  Now dump the results.                  *
  *                                                          *
  ************************************************************
  */
  if (!autotune)
    printf("\n");
  if (!autotune) {
    Print(4095, "Total nodes: %" PRIu64 "\n", nodes);
    Print(4095, "Raw nodes per second: %d\n",
        (int) ((double) nodes / ((double) total_time_used / (double) 100.0)));
    Print(4095, "Total elapsed time: %.2f\n\n",
        ((double) total_time_used / (double) 100.0));
  }
  Print(4095, "Performing SMP PGO...\n");
  old_mt = smp_max_threads;
  smp_max_threads = 2;
  fflush(stdout);
  for (pos = 63; pos < 64; pos++) {
    strcpy(buffer, fen[pos]);
    nargs = ReadParse(buffer, args, " \t;=");
    SetBoard(tree, nargs, args, 0);
    search_depth = fen_depth + increase;
    InitializeHashTables();
    last_pv.pathd = 0;
    thinking = 1;
    tree->status[1] = tree->status[0];
    InitializeHashTables();
    Iterate(game_wtm, think, 0);
    thinking = 0;
    nodes += tree->nodes_searched;
    total_time_used += (program_end_time - program_start_time);
    nodes_per_second =
        (uint64_t) tree->nodes_searched * 100 /
        Max((uint64_t) program_end_time - program_start_time, 1);
    Print(4095, " Running two threads...\n");
    Print(4095, "pos: %d(%s)\n", pos + 1, DisplayKMB(nodes_per_second, 0));
  }
  input_stream = stdin;
  early_exit = 99;
  display_options = old_do;
  search_time_limit = old_st;
  search_depth = old_sd;
  smp_max_threads = Max(1, old_mt);
  books_file = old_books;
  book_file = old_book;
  NewGame(0);
  end = ReadClock();
  return end - begin;
}