Subversion Repositories Games.Chess Giants

Rev

Rev 33 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 33 Rev 108
Line 7... Line 7...
7
 *                                                                             *
7
 *                                                                             *
8
 *   Interrupt() is used to read in a move when the operator types something   *
8
 *   Interrupt() is used to read in a move when the operator types something   *
9
 *   while a search is in progress (during pondering as one example.)  This    *
9
 *   while a search is in progress (during pondering as one example.)  This    *
10
 *   routine reads in a command (move) and then makes two attempts to use this *
10
 *   routine reads in a command (move) and then makes two attempts to use this *
11
 *   input:  (1) call Option() to see if the command can be executed;  (2) try *
11
 *   input:  (1) call Option() to see if the command can be executed;  (2) try *
12
 *   InputMove() to see if this input is a legal move;  If so, and we are      *
12
 *   InputMove() to see if this input is a legal move; If so, and we are       *
13
 *   pondering see if it matches the move we are pondering.                    *
13
 *   pondering see if it matches the move we are pondering.                    *
14
 *                                                                             *
14
 *                                                                             *
15
 *******************************************************************************
15
 *******************************************************************************
16
 */
16
 */
17
void Interrupt(int ply) {
17
void Interrupt(int ply) {
18
  int temp, i, left = 0, readstat, result, time_used;
-
 
19
  int save_move_number;
-
 
20
  TREE *const tree = block[0];
18
  TREE *const tree = block[0];
-
 
19
  int temp, i, left = 0, readstat, result, time_used, save_move_number;
21
 
20
 
22
/*
21
/*
23
 ************************************************************
22
 ************************************************************
24
 *                                                          *
23
 *                                                          *
25
 *  If trying to find a move to ponder, and the operator    *
24
 *  If trying to find a move to ponder, and the operator    *
Line 40... Line 39...
40
 *                                                          *
39
 *                                                          *
41
 ************************************************************
40
 ************************************************************
42
 */
41
 */
43
  else
42
  else
44
    do {
43
    do {
45
      readstat = Read(0, buffer, sizeof (buffer)); // Pierre-Marie Baty -- use safe version
44
      readstat = Read(0, buffer);
46
      if (readstat <= 0)
45
      if (readstat <= 0)
47
        break;
46
        break;
48
      nargs = ReadParse(buffer, args, "         ;");
47
      nargs = ReadParse(buffer, args, " \t;");
49
      if (nargs == 0) {
48
      if (nargs == 0) {
50
        Print(128, "ok.\n");
49
        Print(32, "ok.\n");
51
        break;
50
        break;
52
      }
51
      }
53
      if (strcmp(args[0], ".")) {
52
      if (strcmp(args[0], ".")) {
54
        save_move_number = move_number;
53
        save_move_number = move_number;
55
        if (!game_wtm)
54
        if (!game_wtm)
56
          move_number--;
55
          move_number--;
57
        if (root_wtm)
56
        if (root_wtm)
58
          Print(128, "Black(%d): %s\n", move_number, buffer);
57
          Print(32, "Black(%d): %s\n", move_number, buffer);
59
        else
58
        else
60
          Print(128, "White(%d): %s\n", move_number, buffer);
59
          Print(32, "White(%d): %s\n", move_number, buffer);
61
        move_number = save_move_number;
60
        move_number = save_move_number;
62
      }
61
      }
63
/*
62
/*
64
 ************************************************************
63
 ************************************************************
65
 *                                                          *
64
 *                                                          *
Line 72... Line 71...
72
        if (xboard) {
71
        if (xboard) {
73
          end_time = ReadClock();
72
          end_time = ReadClock();
74
          time_used = (end_time - start_time);
73
          time_used = (end_time - start_time);
75
          printf("stat01: %d ", time_used);
74
          printf("stat01: %d ", time_used);
76
          printf("%" PRIu64 " ", tree->nodes_searched);
75
          printf("%" PRIu64 " ", tree->nodes_searched);
77
          printf("%d ", iteration_depth);
76
          printf("%d ", iteration);
78
          for (i = 0; i < n_root_moves; i++)
77
          for (i = 0; i < n_root_moves; i++)
79
            if (!(root_moves[i].status & 8))
78
            if (!(root_moves[i].status & 8))
80
              left++;
79
              left++;
81
          printf("%d %d\n", left, n_root_moves);
80
          printf("%d %d\n", left, n_root_moves);
82
          fflush(stdout);
81
          fflush(stdout);
Line 84... Line 83...
84
        } else {
83
        } else {
85
          end_time = ReadClock();
84
          end_time = ReadClock();
86
          time_used = (end_time - start_time);
85
          time_used = (end_time - start_time);
87
          printf("time:%s ", DisplayTime(time_used));
86
          printf("time:%s ", DisplayTime(time_used));
88
          printf("nodes:%" PRIu64 "\n", tree->nodes_searched);
87
          printf("nodes:%" PRIu64 "\n", tree->nodes_searched);
-
 
88
#if (CPUS > 1)
89
          DisplayTreeState(block[0], 1, 0, ply);
89
          ThreadTrace(block[0], 0, 1);
-
 
90
#endif
90
        }
91
        }
91
      }
92
      }
92
/*
93
/*
93
 ************************************************************
94
 ************************************************************
94
 *                                                          *
95
 *                                                          *
Line 97... Line 98...
97
 ************************************************************
98
 ************************************************************
98
 */
99
 */
99
      else if (!strcmp(args[0], "?")) {
100
      else if (!strcmp(args[0], "?")) {
100
        if (thinking) {
101
        if (thinking) {
101
          abort_search = 1;
102
          abort_search = 1;
-
 
103
        }
-
 
104
      }
-
 
105
/*
-
 
106
 ************************************************************
-
 
107
 *                                                          *
-
 
108
 *  "@" command says "assume ponder move was played."       *
-
 
109
 *                                                          *
-
 
110
 ************************************************************
-
 
111
 */
-
 
112
      else if (!strcmp(args[0], "@")) {
-
 
113
        if (pondering) {
-
 
114
          predicted++;
-
 
115
          input_status = 1;
-
 
116
          pondering = 0;
-
 
117
          thinking = 1;
-
 
118
          opponent_end_time = ReadClock();
-
 
119
          program_start_time = ReadClock();
-
 
120
          Print(32, "predicted move made.\n");
102
        }
121
        }
103
      }
122
      }
104
/*
123
/*
105
 ************************************************************
124
 ************************************************************
106
 *                                                          *
125
 *                                                          *
Line 119... Line 138...
119
          move_number--;
138
          move_number--;
120
        result = Option(tree);
139
        result = Option(tree);
121
        move_number = save_move_number;
140
        move_number = save_move_number;
122
        if (result >= 2) {
141
        if (result >= 2) {
123
          if (thinking && result != 3)
142
          if (thinking && result != 3)
124
            Print(128, "command not legal now.\n");
143
            Print(32, "command not legal now.\n");
125
          else {
144
          else {
126
            abort_search = 2;
145
            abort_search = 2;
127
            input_status = 2;
146
            input_status = 2;
128
            break;
147
            break;
129
          }
148
          }
Line 144... Line 163...
144
 *                                                          *
163
 *                                                          *
145
 ************************************************************
164
 ************************************************************
146
 */
165
 */
147
        else if (!result) {
166
        else if (!result) {
148
          if (pondering) {
167
          if (pondering) {
149
            nargs = ReadParse(buffer, args, "   ;");
168
            nargs = ReadParse(buffer, args, " \t;");
150
            temp = InputMove(tree, args[0], 0, Flip(root_wtm), 1, 1);
169
            temp = InputMove(tree, 0, Flip(root_wtm), 1, 1, args[0]);
151
            if (temp) {
170
            if (temp) {
152
              if ((From(temp) == From(ponder_move))
171
              if ((From(temp) == From(ponder_move))
153
                  && (To(temp) == To(ponder_move))
172
                  && (To(temp) == To(ponder_move))
154
                  && (Piece(temp) == Piece(ponder_move))
173
                  && (Piece(temp) == Piece(ponder_move))
155
                  && (Captured(temp) == Captured(ponder_move))
174
                  && (Captured(temp) == Captured(ponder_move))
Line 158... Line 177...
158
                input_status = 1;
177
                input_status = 1;
159
                pondering = 0;
178
                pondering = 0;
160
                thinking = 1;
179
                thinking = 1;
161
                opponent_end_time = ReadClock();
180
                opponent_end_time = ReadClock();
162
                program_start_time = ReadClock();
181
                program_start_time = ReadClock();
163
                Print(128, "predicted move made.\n");
182
                Print(32, "predicted move made.\n");
164
              } else {
183
              } else {
165
                input_status = 2;
184
                input_status = 2;
166
                abort_search = 2;
185
                abort_search = 2;
167
                break;
186
                break;
168
              }
187
              }