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 10... | Line 10... | ||
| 10 | * a suggested move from the transposition table. Then, make this move and * |
10 | * a suggested move from the transposition table. Then, make this move and * |
| 11 | * do a search from the resulting position. While pondering, one of three * |
11 | * do a search from the resulting position. While pondering, one of three * |
| 12 | * things can happen: (1) A move is entered, and it matches the predicted * |
12 | * things can happen: (1) A move is entered, and it matches the predicted * |
| 13 | * move. We then switch from pondering to thinking and search as normal; * |
13 | * move. We then switch from pondering to thinking and search as normal; * |
| 14 | * (2) A move is entered, but it does not match the predicted move. We then * |
14 | * (2) A move is entered, but it does not match the predicted move. We then * |
| 15 | * abort the search, unmake the pondered move, and then restart with the |
15 | * abort the search, unmake the pondered move, and then restart with the * |
| 16 | * entered. (3) A command is entered. If it is a simple command, it |
16 | * move entered. (3) A command is entered. If it is a simple command, it * |
| 17 | * done without aborting the search or losing time. If not, we abort |
17 | * can be done without aborting the search or losing time. If not, we abort * |
| 18 | * search, execute the command, and then attempt to restart pondering if |
18 | * the search, execute the command, and then attempt to restart pondering if * |
| 19 | * command |
19 | * the command didn't make that impossible. * |
| 20 | * * |
20 | * * |
| 21 | ******************************************************************************* |
21 | ******************************************************************************* |
| 22 | */ |
22 | */ |
| 23 | int Ponder(int wtm) { |
23 | int Ponder(int wtm) { |
| 24 | int dalpha = -999999, dbeta = 999999, i, *n_ponder_moves, *mv; |
- | |
| 25 | int save_move_number, tlom, value; |
- | |
| 26 | TREE *const tree = block[0]; |
24 | TREE *const tree = block[0]; |
| - | 25 | int dalpha = -999999, dbeta = 999999, i; |
|
| - | 26 | unsigned *n_ponder_moves, *mv; |
|
| - | 27 | int save_move_number, tlom, value; |
|
| 27 | 28 | ||
| 28 | /* |
29 | /* |
| 29 | ************************************************************ |
30 | ************************************************************ |
| 30 | * * |
31 | * * |
| 31 | * First, let's check to see if pondering is allowed, or * |
32 | * First, let's check to see if pondering is allowed, or * |
| Line 46... | Line 47... | ||
| 46 | * legal move, we have to take action to find something to * |
47 | * legal move, we have to take action to find something to * |
| 47 | * ponder. * |
48 | * ponder. * |
| 48 | * * |
49 | * * |
| 49 | ************************************************************ |
50 | ************************************************************ |
| 50 | */ |
51 | */ |
| 51 |
|
52 | strcpy(ponder_text, "none"); |
| 52 | if (ponder_move) { |
53 | if (ponder_move) { |
| 53 | if (!VerifyMove(tree, 1, wtm, ponder_move)) { |
54 | if (!VerifyMove(tree, 1, wtm, ponder_move)) { |
| 54 | ponder_move = 0; |
55 | ponder_move = 0; |
| 55 | Print(4095, "ERROR. ponder_move is illegal (1).\n"); |
56 | Print(4095, "ERROR. ponder_move is illegal (1).\n"); |
| 56 | Print(4095, "ERROR. PV pathl=%d\n", last_pv.pathl); |
57 | Print(4095, "ERROR. PV pathl=%d\n", last_pv.pathl); |
| Line 66... | Line 67... | ||
| 66 | * legal. * |
67 | * legal. * |
| 67 | * * |
68 | * * |
| 68 | ************************************************************ |
69 | ************************************************************ |
| 69 | */ |
70 | */ |
| 70 | if (!ponder_move) { |
71 | if (!ponder_move) { |
| 71 |
|
72 | HashProbe(tree, 0, 0, wtm, dalpha, dbeta, &value); |
| 72 | if (tree->hash_move[0]) |
73 | if (tree->hash_move[0]) |
| 73 | ponder_move = tree->hash_move[0]; |
74 | ponder_move = tree->hash_move[0]; |
| 74 | if (ponder_move) { |
75 | if (ponder_move) { |
| 75 | if (!VerifyMove(tree, 1, wtm, ponder_move)) { |
76 | if (!VerifyMove(tree, 1, wtm, ponder_move)) { |
| 76 | Print(4095, "ERROR. ponder_move is illegal (2).\n"); |
77 | Print(4095, "ERROR. ponder_move is illegal (2).\n"); |
| Line 93... | Line 94... | ||
| 93 | TimeSet(puzzle); |
94 | TimeSet(puzzle); |
| 94 | if (time_limit < 20) |
95 | if (time_limit < 20) |
| 95 | return 0; |
96 | return 0; |
| 96 | puzzling = 1; |
97 | puzzling = 1; |
| 97 | tree->status[1] = tree->status[0]; |
98 | tree->status[1] = tree->status[0]; |
| 98 | Print( |
99 | Print(32, " puzzling over a move to ponder.\n"); |
| 99 | last_pv.pathl = 0; |
100 | last_pv.pathl = 0; |
| 100 | last_pv.pathd = 0; |
101 | last_pv.pathd = 0; |
| 101 | for (i = 0; i < MAXPLY; i++) { |
102 | for (i = 0; i < MAXPLY; i++) { |
| 102 | tree->killers[i].move1 = 0; |
103 | tree->killers[i].move1 = 0; |
| 103 | tree->killers[i].move2 = 0; |
104 | tree->killers[i].move2 = 0; |
| 104 | } |
105 | } |
| 105 |
|
106 | Iterate(wtm, puzzle, 0); |
| 106 | for (i = 0; i < MAXPLY; i++) { |
107 | for (i = 0; i < MAXPLY; i++) { |
| 107 | tree->killers[i].move1 = 0; |
108 | tree->killers[i].move1 = 0; |
| 108 | tree->killers[i].move2 = 0; |
109 | tree->killers[i].move2 = 0; |
| 109 | } |
110 | } |
| 110 | puzzling = 0; |
111 | puzzling = 0; |
| Line 129... | Line 130... | ||
| 129 | * Display the move we are going to "ponder". * |
130 | * Display the move we are going to "ponder". * |
| 130 | * * |
131 | * * |
| 131 | ************************************************************ |
132 | ************************************************************ |
| 132 | */ |
133 | */ |
| 133 | if (wtm) |
134 | if (wtm) |
| 134 | Print( |
135 | Print(32, "White(%d): %s [pondering]\n", move_number, OutputMove(tree, 0, |
| 135 |
|
136 | wtm, ponder_move)); |
| 136 | else |
137 | else |
| 137 | Print( |
138 | Print(32, "Black(%d): %s [pondering]\n", move_number, OutputMove(tree, 0, |
| 138 |
|
139 | wtm, ponder_move)); |
| 139 |
|
140 | sprintf(ponder_text, "%s", OutputMove(tree, 0, wtm, ponder_move)); |
| 140 | if (post) |
141 | if (post) |
| 141 | printf("Hint: %s\n", |
142 | printf("Hint: %s\n", ponder_text); |
| 142 | /* |
143 | /* |
| 143 | ************************************************************ |
144 | ************************************************************ |
| 144 | * * |
145 | * * |
| 145 | * Set the ponder move list and eliminate illegal moves. * |
146 | * Set the ponder move list and eliminate illegal moves. * |
| 146 | * This list is used to test the move entered while we are * |
147 | * This list is used to test the move entered while we are * |
| Line 151... | Line 152... | ||
| 151 | */ |
152 | */ |
| 152 | n_ponder_moves = GenerateCaptures(tree, 0, wtm, ponder_moves); |
153 | n_ponder_moves = GenerateCaptures(tree, 0, wtm, ponder_moves); |
| 153 | num_ponder_moves = |
154 | num_ponder_moves = |
| 154 | GenerateNoncaptures(tree, 0, wtm, n_ponder_moves) - ponder_moves; |
155 | GenerateNoncaptures(tree, 0, wtm, n_ponder_moves) - ponder_moves; |
| 155 | for (mv = ponder_moves; mv < ponder_moves + num_ponder_moves; mv++) { |
156 | for (mv = ponder_moves; mv < ponder_moves + num_ponder_moves; mv++) { |
| 156 | MakeMove(tree, 0, |
157 | MakeMove(tree, 0, wtm, *mv); |
| 157 | if (Check(wtm)) { |
158 | if (Check(wtm)) { |
| 158 | UnmakeMove(tree, 0, |
159 | UnmakeMove(tree, 0, wtm, *mv); |
| 159 | *mv = 0; |
160 | *mv = 0; |
| 160 | } else |
161 | } else |
| 161 | UnmakeMove(tree, 0, |
162 | UnmakeMove(tree, 0, wtm, *mv); |
| 162 | } |
163 | } |
| 163 | /* |
164 | /* |
| 164 | ************************************************************ |
165 | ************************************************************ |
| 165 | * * |
166 | * * |
| 166 | * Now, perform an iterated search, but with the special * |
167 | * Now, perform an iterated search, but with the special * |
| Line 168... | Line 169... | ||
| 168 | * since there is no need to stop searching until the * |
169 | * since there is no need to stop searching until the * |
| 169 | * opponent makes a move. * |
170 | * opponent makes a move. * |
| 170 | * * |
171 | * * |
| 171 | ************************************************************ |
172 | ************************************************************ |
| 172 | */ |
173 | */ |
| 173 | MakeMove(tree, 0, |
174 | MakeMove(tree, 0, wtm, ponder_move); |
| - | 175 | tree->curmv[0] = ponder_move; |
|
| 174 | tree->rep_list[++ |
176 | tree->rep_list[++rep_index] = HashKey; |
| 175 | tlom = last_opponent_move; |
177 | tlom = last_opponent_move; |
| 176 | last_opponent_move = ponder_move; |
178 | last_opponent_move = ponder_move; |
| 177 | if (kibitz) |
179 | if (kibitz) |
| 178 |
|
180 | strcpy(kibitz_text, "n/a"); |
| 179 | thinking = 0; |
181 | thinking = 0; |
| 180 | pondering = 1; |
182 | pondering = 1; |
| 181 | if (!wtm) |
183 | if (!wtm) |
| 182 | move_number++; |
184 | move_number++; |
| 183 | ponder_value = Iterate(Flip(wtm), think, 0); |
185 | ponder_value = Iterate(Flip(wtm), think, 0); |
| 184 |
|
186 | rep_index--; |
| 185 | move_number = save_move_number; |
187 | move_number = save_move_number; |
| 186 | pondering = 0; |
188 | pondering = 0; |
| 187 | thinking = 0; |
189 | thinking = 0; |
| 188 | last_opponent_move = tlom; |
190 | last_opponent_move = tlom; |
| 189 | UnmakeMove(tree, 0, |
191 | UnmakeMove(tree, 0, wtm, ponder_move); |
| 190 | /* |
192 | /* |
| 191 | ************************************************************ |
193 | ************************************************************ |
| 192 | * * |
194 | * * |
| 193 | * Search completed. the possible return values are: * |
195 | * Search completed. the possible return values are: * |
| 194 | * * |
196 | * * |
| Line 202... | Line 204... | ||
| 202 | * terminated due to either finding a mate, or the * |
204 | * terminated due to either finding a mate, or the * |
| 203 | * maximum search depth was reached. The result of * |
205 | * maximum search depth was reached. The result of * |
| 204 | * this ponder search are valid, but only if the * |
206 | * this ponder search are valid, but only if the * |
| 205 | * opponent makes the correct (predicted) move. * |
207 | * opponent makes the correct (predicted) move. * |
| 206 | * * |
208 | * * |
| 207 | * (3) Pondering was done, but the opponent either made |
209 | * (3) Pondering was done, but the opponent either made a * |
| 208 | * |
210 | * different move, or entered a command that has to * |
| 209 | * interrupt the pondering search before the command * |
211 | * interrupt the pondering search before the command * |
| 210 | * (or move) can be processed. This forces Main() to * |
212 | * (or move) can be processed. This forces Main() to * |
| 211 | * avoid reading in a move/command since one has been * |
213 | * avoid reading in a move/command since one has been * |
| 212 | * read into the command buffer already. * |
214 | * read into the command buffer already. * |
| 213 | * * |
215 | * * |