1 #include "chess.h"
2 #include "data.h"
3 #if defined(UNIX)
4 # include <unistd.h>
5 # include <pwd.h>
6 # include <sys/types.h>
7 #endif
8 #include <signal.h>
9 #if defined(SYZYGY)
10 # include "tbprobe.h"
11 #endif
12 /* last modified 08/03/16 */
13 /*
14 *******************************************************************************
15 * *
16 * Crafty, copyright 1996-2016 by Robert M. Hyatt, Ph.D. *
17 * *
18 * Crafty is a team project consisting of the following members. These are *
19 * the people involved in the continuing development of this program, there *
20 * are no particular members responsible for any specific aspect of Crafty, *
21 * although R. Hyatt wrote 99%+ of the existing code, excepting the Magic . *
22 * move stuff by Pradu Kaanan, syzygy code written by Ronald de Man, and the *
23 * epd stuff written by S. Edwards. *
24 * *
25 * Robert Hyatt, Pelham, AL. *
26 * Mike Byrne, Pen Argyl, PA. *
27 * Tracy Riegle, Hershey, PA. *
28 * Peter Skinner, Edmonton, AB Canada. *
29 * *
30 * All rights reserved. No part of this program may be reproduced in any *
31 * form or by any means, for other than your personal use, without the *
32 * express written permission of the authors. This program may not be used *
33 * in whole, nor in part, to enter any computer chess competition without *
34 * written permission from the authors. Such permission will include the *
35 * requirement that the program be entered under the name "Crafty" so that *
36 * the program's ancestry will be known. *
37 * *
38 * Copies of the source must contain the original copyright notice intact. *
39 * *
40 * Any changes made to this software must also be made public to comply with *
41 * the original intent of this software distribution project. These *
42 * restrictions apply whether the distribution is being done for free or as *
43 * part or all of a commercial product. The authors retain sole ownership *
44 * and copyright on this program except for 'personal use' explained below. *
45 * *
46 * Personal use includes any use you make of the program yourself, either by *
47 * playing games with it yourself, or allowing others to play it on your *
48 * machine, and requires that if others use the program, it must be clearly *
49 * identified as "Crafty" to anyone playing it (on a chess server as one *
50 * example). Personal use does not allow anyone to enter this into a chess *
51 * tournament where other program authors are invited to participate. IE you *
52 * can do your own local tournament, with Crafty + other programs, since this *
53 * is for your personal enjoyment. But you may not enter Crafty into an *
54 * event where it will be in competition with other programs/programmers *
55 * without permission as stated previously. *
56 * *
57 * Crafty is the "son" (direct descendent) of Cray Blitz. it is designed *
58 * totally around the bit-board data structure for reasons of speed of ex- *
59 * ecution, ease of adding new knowledge, and a *significantly* cleaner *
60 * overall design. it is written totally in ANSI C with some few UNIX system *
61 * calls required for I/O, etc. *
62 * *
63 * main() is the driver for the chess program. Its primary function is to *
64 * cycle between asking the user for a move and calling for a tree search *
65 * to produce a move for the program. After accepting an input string from *
66 * the user, this string is first passed to Option() which checks to see if *
67 * it is a command to the program. If Option() returns a non-zero result, *
68 * the input was a command and was executed, otherwise the input should be *
69 * passed to input() for conversion to the internal move format. *
70 * *
71 * The following diagram shows how bit numbers / squares match up in Crafty's *
72 * bitboard arrays. Note that bit zero (LSB) corresponds to square A, which *
73 * makes this a mental challenge to take a 64 bit value and visualize it as *
74 * chess board, since the files are reversed. This was done for the *
75 * following reasons: (1) bit 0 needs to be the LSB, and bit 63 needs to be *
76 * the MSB so that the Intel BSF/BSR instructions return the proper square *
77 * number without any remapping. (2) the lower 3 bits (file number) are now *
78 * 0 for A, 1 for B, ..., 7 for H. The upper 3 bits (rank number) are then *
79 * 0 for rank 1, 1 for rank 2, ..., 7 for rank 8. *
80 * *
81 * A8 B8 C8 D8 E8 F8 G8 H8 *
82 * A7 B7 C7 D7 E7 F7 G7 H7 *
83 * A6 B6 C6 D6 E6 F6 G6 H6 *
84 * A5 B5 C5 D5 E5 F5 G5 H5 *
85 * A4 B4 C4 D4 E4 F4 G4 H4 *
86 * A3 B3 C3 D3 E3 F3 G3 H3 *
87 * A2 B2 C2 D2 E2 F2 G2 H2 *
88 * A1 B1 C1 D1 E1 F1 G1 H1 *
89 * *
90 * 56 57 58 59 60 61 62 63 *
91 * 48 49 50 51 52 53 54 55 *
92 * 40 41 42 43 44 45 46 47 *
93 * 32 33 34 35 36 37 38 39 *
94 * 24 25 26 27 28 29 30 31 *
95 * 16 17 18 19 20 21 22 23 *
96 * 8 9 10 11 12 13 14 15 *
97 * 0 1 2 3 4 5 6 7 *
98 * *
99 * version description *
100 * *
101 * 1.0 First version of the bit-board program to play a legitimate game *
102 * even though significant features are missing: transposition *
103 * table, sophisticated scoring, etc. *
104 * *
105 * 1.1 Added the minimal window search. At each ply in the tree, the *
106 * first branch is searched with the normal alpha/beta window, while *
107 * remaining nodes are searched with value/value+1 which was *
108 * returned from searching the first branch. If such a search *
109 * returns the upper bound, this position is once again searched *
110 * with the normal window. *
111 * *
112 * 1.2 Added the classic null-move search. The program searches the *
113 * sub-tree below the null move (typically) one play shallower than *
114 * the normal search, saving a lot of time. *
115 * *
116 * 1.3 Added the transposition table support. This also includes the *
117 * code in Iterate() necessary to propagate the principal variation *
118 * from one iteration to the next to improve move ordering. *
119 * *
120 * 1.4 Modified the transposition table to use three tables, one for 64 *
121 * bits of white entry, one for 64 bits of black entry, and one with *
122 * the remaining 32 bits of white and black entry combined into one *
123 * 64 bit word. Eliminated the "bit fields" since they seemed to be *
124 * erratic on most compilers and made portability nearly impossible. *
125 * *
126 * 1.5 Pawn scoring added. This required three additions to the code: *
127 * (1) InitializePawnMasks() which produces the necessary masks to *
128 * let us efficiently detect isolated, backward, passed, etc. pawns; *
129 * (2) a pawn hash table to store recently computed pawn scores so *
130 * it won't be too expensive to do complex analysis; (3) Evaluate() *
131 * now evaluates pawns if the current pawn position is not in the *
132 * pawn hash table. *
133 * *
134 * 1.6 Piece scoring added, although it is not yet complete. Also, the *
135 * search now uses the familiar zero-width window search for all but *
136 * the first move at the root, in order to reduce the size of the *
137 * tree to a nearly optimal size. This means that a move that is *
138 * only one point better than the first move will "fail high" and *
139 * have to be re-searched a second time to get the true value. If *
140 * the new best move is significantly better, it may have to be *
141 * searched a third time to increase the window enough to return the *
142 * score. *
143 * *
144 * 1.7 Replaced the old "killer" move ordering heuristic with the newer *
145 * "history" ordering heuristic. This version uses the 12-bit key *
146 * formed by <from><to> to index into the history table. *
147 * *
148 * 1.8 Added pondering for both PC and UNIX-based machines. Also other *
149 * improvements include the old Cray Blitz algorithm that takes the *
150 * P.V. returned by the tree search, and "extends" it by looking up *
151 * positions in the transposition table, which improves move *
152 * ordering significantly. Repetitions are now handled correctly. *
153 * *
154 * 1.9 Added an opening book with flags to control which moves are *
155 * selected for play. The book maintenance code is stubbed directly *
156 * into the program, so that no additional executables are needed. *
157 * *
158 * 1.10 Added king safety + hashing (as done in the old Cray Blitz). *
159 * Nothing novel other than the use of bit-masks to speed up some of *
160 * the tests. *
161 * *
162 * 1.11 Additional evaluation knowledge plus log_file so that program *
163 * saves a record of the game statistics for later analysis. Added *
164 * the "annotate" command to make the program analyze a game or part *
165 * of a game for testing/debugging. *
166 * *
167 * 1.12 Added ICS (Internet Chess Server) support for Xboard support so *
168 * that Crafty can play on ICS in an automated manner. Added new *
169 * commands to be compatible with Xboard. Crafty also has a new *
170 * command-line interface that allows options to be entered on the *
171 * command-line directly, ie: "crafty alarm=off verbose=2" will *
172 * start the program, set the move alarm off, and set verbose to *
173 * 2. This allows an "alias" to easily customize the program. *
174 * *
175 * 1.13 Added time-control logic to the program. It now monitors how *
176 * much time both it and its opponent uses when thinking about a *
177 * move to make. When pondering, it only times itself from the *
178 * point that a move is actually entered. *
179 * *
180 * 1.14 Added the piece/square tables to the program to move static *
181 * scoring to the root of the tree since it never changes (things *
182 * like centralization of pieces, etc.) also some minor tuning of *
183 * numbers to bring positional score "swings" down some. *
184 * *
185 * 1.15 Added edit so that positions can be altered (and so ICS games *
186 * can be resumed after they are adjourned). Also added a "force" *
187 * command to force the program to play a different move than the *
188 * search selected. Search timing allocation slightly altered to *
189 * improve ICS performance. *
190 * *
191 * 1.16 Significant adjustments to evaluation weights to bring positional *
192 * scores down to below a pawn for "normal" positions. Some small *
193 * "tweaks" to king safety as well to keep the king safer. *
194 * *
195 * 1.17 Added "development" evaluation routine to encourage development *
196 * and castling before starting on any tactical "sorties." Also *
197 * repaired many "bugs" in evaluation routines. *
198 * *
199 * 1.18 Added the famous Cray Blitz "square of the king" passed pawn *
200 * evaluation routine. This will evaluate positions where one *
201 * side has passed pawns and the other side has no pieces, to see *
202 * if the pawn can outrun the defending king and promote. Note that *
203 * this is ridiculously fast because it only requires one AND *
204 * to declare that a pawn can't be caught! *
205 * *
206 * 2.0 initial version preparing for search extension additions. This *
207 * version has a new "next_evasion()" routine that is called when *
208 * the king is in check. It generates sensible (nearly all are *
209 * legal) moves which include capturing the checking piece (if there *
210 * is only one), moving the king (but not along the checking ray), *
211 * and interpositions that block the checking ray (if there is only *
212 * one checking piece. *
213 * *
214 * 2.1 Search is now broken down into three cleanly-defined phases: *
215 * (1) basic full-width search [Search()]; (2) extended tactical *
216 * search [extend()] which includes winning/even captures and then *
217 * passed pawn pushes to the 6th or 7th rank (if the pawn pushes *
218 * are safe); (3) normal quiescence search [Quiesce()] which only *
219 * includes captures that appear to gain material. *
220 * *
221 * 2.2 King safety code re-written and cleaned up. Crafty was giving *
222 * multiple penalties which was causing the king safety score to be *
223 * extremely large (and unstable.) Now, if it finds something wrong *
224 * with king safety, it only penalizes a weakness once. *
225 * *
226 * 2.3 King safety code modified further, penalties were significant *
227 * enough to cause search anomolies. Modified rook scoring to avoid *
228 * having the rook trapped in the corner when the king is forced to *
229 * move rather than castle, and to keep the rook in a position to be *
230 * able to reach open files in one move, which avoids getting them *
231 * into awkward positions where they become almost worthless. *
232 * *
233 * 2.4 King safety code completely rewritten. It now analyzes "defects" *
234 * in the king safety field and counts them as appropriate. These *
235 * defects are then summed up and used as an index into a vector of *
236 * of values that turns them into a score in a non-linear fashion. *
237 * Increasing defects quickly "ramp up" the score to about 1/3+ of *
238 * a pawn, then additional faults slowly increase the penalty. *
239 * *
240 * 2.5 First check extensions added. In the extension search (stage *
241 * between full-width and captures-only, up to two checking moves *
242 * can be included, if there are checks in the full-width part of *
243 * the search. If only one check occurs in the full-width, then *
244 * only one check will be included in the extension phase of the *
245 * selective search. *
246 * *
247 * 2.6 Evaluation modifications attempting to cure Crafty's frantic *
248 * effort to develop all its pieces without giving a lot of regard *
249 * to the resulting position until after the pieces are out. *
250 * *
251 * 2.7 New evaluation code to handle the "outside passed pawn" concept. *
252 * Crafty now understands that a passed pawn on the side away from *
253 * the rest of the pawns is a winning advantage due to decoying the *
254 * king away from the pawns to prevent the passer from promoting. *
255 * The advantage increases as material is removed from the board. *
256 * *
257 * 3.0 The 3.* series of versions will primarily be performance en- *
258 * hancements. The first version (3.0) has a highly modified *
259 * version of MakeMove() that tries to do no unnecessary work. It *
260 * is about 25% faster than old version of MakeMove() which makes *
261 * Crafty roughly 10% faster. Also calls to Mask() have been *
262 * replaced by constants (which are replaced by calls to Mask() on *
263 * the Crays for speed) to eliminate function calls. *
264 * *
265 * 3.1 Significantly modified king safety again, to better detect and *
266 * react to king-side attacks. Crafty now uses the recursive null- *
267 * move search to depth-2 instead of depth-1, which results in *
268 * slightly improved speed. *
269 * *
270 * 3.2 Null-move restored to depth-1. Depth-2 proved unsafe as Crafty *
271 * was overlooking tactical moves, particularly against itself, *
272 * which lost several "won" games. *
273 * *
274 * 3.3 Additional king-safety work. Crafty now uses the king-safety *
275 * evaluation routines to compare king safety for both sides. If *
276 * one side is "in distress" pieces are attracted to that king in *
277 * "big hurry" to either attack or defend. *
278 * *
279 * 3.4 "Threat extensions" added. Simply, this is a null-move search *
280 * used to determine if a move is good only because it is a horizon *
281 * effect type move. We do a null move search after a move fails *
282 * high anywhere in the tree. The window is normally lowered by 1.5 *
283 * pawns, the idea being that if the fail-high move happens in a *
284 * position that fails "really low" with a null move, then this move *
285 * might be a horizon move. To test this, re-search this move with *
286 * the depth increased by one. *
287 * *
288 * 3.5 50-move rule implemented. A count of moves since the last pawn *
289 * move or capture is kept as part of the position[] structure. It *
290 * is updated by MakeMove(). When this number reaches 100 (which *
291 * in plies is 50 moves) Repeat() will return the draw indication *
292 * immediately, just as though the position was a repetition draw. *
293 * *
294 * 3.6 Search extensions cleaned up to avoid excessive extensions which *
295 * produced some wild variations, but which was also slowing things *
296 * down excessively. *
297 * *
298 * 3.7 Endgame strategy added. Two specifics: KBN vs K has a piece/sq *
299 * table that will drive the losing king to the correct corner. For *
300 * positions with no pawns, scoring is altered to drive the losing *
301 * king to the edge and corner for mating purposes. *
302 * *
303 * 3.8 Hashing strategy modified. Crafty now stores search value or *
304 * bound, *and* positional evaluation in the transposition table. *
305 * This avoids about 10-15% of the "long" evaluations during the *
306 * middlegame, and avoids >75% of them in endgames. *
307 * *
308 * 4.0 Evaluation units changed to "millipawns" where a pawn is now *
309 * 1000 rather than the prior 100 units. This provides more *
310 * "resolution" in the evaluation and will let Crafty have large *
311 * positional bonuses for significant things, without having the *
312 * small positional advantages add up and cause problems. V3.8 *
313 * exhibited a propensity to "sac the exchange" frequently because *
314 * of this. It is hoped that this is a thing of the past now. *
315 * Also, the "one legal reply to check" algorithm is now being used. *
316 * In short, if one side has only one legal reply to a checking move *
317 * then the other side is free to check again on the next ply. this *
318 * only applies in the "extension" search, and allows some checks *
319 * that extend() would normally not follow. *
320 * *
321 * 4.1 Extension search modified. It now "tracks" the basic iteration *
322 * search depth up to some user-set limit (default=6). For shallow *
323 * depths, this speeds things up, while at deeper depths it lets the *
324 * program analyze forcing moves somewhat deeper. *
325 * *
326 * 4.2 Extension search modified. Fixed a problem where successive *
327 * passed-pawn pushes were not extended correctly by extend() code. *
328 * Threat-extension margin was wrong after changing the value of a *
329 * pawn to 1000, it is now back to 1.5 pawns. *
330 * *
331 * 4.3 Hash scoring "repaired." As the piece/square tables changed, the *
332 * transposition table (positional evaluation component) along with *
333 * the pawn and king-safety hash tables prevented the changes from *
334 * affecting the score, since the hashed scores were based on the *
335 * old piece/square table values. Now, when any piece/square table *
336 * is modified, the affected hash tables are cleared of evaluation *
337 * information. *
338 * *
339 * 4.4 Piece/square tables simplified, king tropism scoring moved to *
340 * Evaluate() where it is computed dynamically now as it should be. *
341 * *
342 * 4.5 Book move selection algorithm replaced. Crafty now counts the *
343 * number of times each book move was played as the book file is *
344 * created. Since these moves come (typically) from GM games, the *
345 * more frequently a move appears, the more likely it is to lead to *
346 * a sound position. Crafty then enumerates all possible book moves *
347 * for the current position, computes a probability distribution for *
348 * each move so that Crafty will select a move proportional to the *
349 * number of times it was played in GM games (for example, if e4 was *
350 * played 55% of the time, then Crafty will play e4 55% of the time) *
351 * although the special case of moves played too infrequently is *
352 * handled by letting the operator set a minimum threshold (say 5) *
353 * Crafty won't play moves that are not popular (or are outright *
354 * blunders as the case may be.) Pushing a passed pawn to the 7th *
355 * rank in the basic search [Search() module] now extends the search *
356 * by two plies unless we have extended this ply already (usually a *
357 * check evasion) or unless we have extended the whole line to more *
358 * than twice the nominal iteration depth. *
359 * *
360 * 5.0 Selective search extensions removed. With the extensions now in *
361 * the basic full-width search, these became more a waste of time *
362 * than anything useful, and removing them simplifies things quite *
363 * a bit. *
364 * *
365 * 5.1 Pondering logic now has a "puzzling" feature that is used when *
366 * the search has no move to ponder. It does a short search to find *
367 * a move and then ponders that move, permanently eliminating the *
368 * "idle" time when it has nothing to ponder. *
369 * *
370 * 5.2 Evaluation terms scaled down to prevent positional scores from *
371 * reaching the point that sacrificing material to avoid simple *
372 * positional difficulties begins to look attractive. *
373 * *
374 * 5.3 Performance improvement produced by avoiding calls to MakeMove() *
375 * when the attack information is not needed. Since the first test *
376 * done in Quiesce() is to see if the material score is so bad that *
377 * a normal evaluation and/or further search is futile, this test *
378 * has been moved to inside the loop *before* Quiesce() is *
379 * recursively called, avoiding the MakeMove() work only to *
380 * discover that the resulting position won't be searched further. *
381 * *
382 * 5.4 New SEE() function that now understands indirect attacks through *
383 * the primary attacking piece(s). This corrects a lot of sloppy *
384 * move ordering as well as make the "futility" cutoffs added in *
385 * in version 5.3 much more reliable. *
386 * *
387 * 5.5 Checks are now back in the quiescence search. Crafty now stores *
388 * a negative "draft" in the transposition table rather than forcing *
389 * any depth < 0 to be zero. The null-move search now searches the *
390 * null-move to depth-1 (R=1) rather than depth-2 (R=2) which seemed *
391 * to cause some tactical oversights in the search. *
392 * *
393 * 5.6 Improved move ordering by using the old "killer move" idea. An *
394 * additional advantage is that the killers can be tried before *
395 * generating any moves (after the captures.) Quiescence now only *
396 * includes "safe" checks (using SEE() to determine if it is a safe *
397 * checking move. *
398 * *
399 * 5.7 King safety now "hates" a pawn at b3/g3 (white) or b6/g6 (black) *
400 * to try and avoid the resulting mate threats. *
401 * *
402 * 5.8 EvaluateOutsidePassedPawns() fixed to correctly evaluate those *
403 * positions where both sides have outside passed pawns. Before *
404 * this fix, it only evaluated positions where one side had a passed *
405 * pawn, which overlooked those won/lost positions where both sides *
406 * have passed pawns but one is "distant" or "outside" the other. *
407 * *
408 * 5.9 Removed "futility" forward pruning. Exhaustive testing has *
409 * proved that this causes significant tactical oversights. *
410 * *
411 * 5.10 Added code to handle king and pawn vs king, which understands *
412 * the cases where the pawn can't outrun the king, but has to be *
413 * assisted along by the king. *
414 * *
415 * 5.11 Two king-safety changes. (1) The program's king safety score is *
416 * now "doubled" to make it much less likely that it will try to win *
417 * a pawn but destroy it's king-side. (2) The attack threshold has *
418 * been lowered which is used to key the program that it is now *
419 * necessary to move pieces to defend the king-side, in an effort to *
420 * protect a king-side that is deemed somewhat unsafe. *
421 * *
422 * 5.12 Improved null-move code by computing the Knuth/Moore node type *
423 * and then only trying null-moves at type 2 nodes. This has *
424 * resulted in a 2x speedup in test positions. *
425 * *
426 * 5.13 Optimization to avoid doing a call to MakeMove() if it can be *
427 * avoided by noting that the move is not good enough to bring the *
428 * score up to an acceptable level. *
429 * *
430 * 5.14 Artificially isolated pawns recognized now, so that Crafty won't *
431 * push a pawn so far it can't be defended. Also, the bonus for a *
432 * outside passed pawn was nearly doubled. *
433 * *
434 * 5.15 Passed pawns supported by a king, or connected passed pawns now *
435 * get a large bonus as they advance. Minor fix to the ICC resume *
436 * feature to try to avoid losing games on time. *
437 * *
438 * 6.0 Converted to rotated bitboards to make attack generation *much* *
439 * faster. MakeMove() now can look up the attack bit vectors *
440 * rather than computing them which is significantly faster. *
441 * *
442 * 6.1 Added a "hung piece" term to Evaluate() which penalizes the side *
443 * to move if a piece is attacked by a lesser piece, or a piece is *
444 * attacked and not defended at all. Additionally, a new scoring *
445 * term was added to detect a weak back rank (where the king does *
446 * not attack an empty square on the 2nd rank, and there are no *
447 * horizontally sliding pieces [rook or queen] on the first rank to *
448 * guard against back-rank mates. *
449 * *
450 * 6.2 Modified the "futility" cutoff to (a) emulate the way the program *
451 * normally searches, but avoiding MakeMove() calls when possible, *
452 * and (2) not searching a move near the horizon if the material *
453 * score is hopeless. *
454 * *
455 * 6.3 Null-move code moved from NextMove() directly into Search(). *
456 * this results is a "cleaner" implementation, as well as fixing an *
457 * error in the node type, caused by Search() thinking that after *
458 * the first move tried fails to cause a cutoff, that suddenly this *
459 * node is a type=3 node (Knuth and Moore). This bug would then *
460 * introduce null-moves into later nodes that are a waste of time. *
461 * *
462 * 6.4 Pawn scoring modified. Passed pawns were scored low enough that *
463 * Crafty would let the opponent create one in the endgame (as long *
464 * as it wasn't an "outside" passed pawn). This required adjusting *
465 * isolated pawns as well. All "weak" pawns (pawns on open files *
466 * that aren't defended by a pawn) are not penalized so much if *
467 * there aren't any rooks/queens to attack on the file. *
468 * *
469 * 7.0 Removed the to.attack and from.attack bitboards. These are now *
470 * computed as needed, using the rotated bitboards. Hung piece *
471 * stuff removed due to lack of any verified benefit. *
472 * *
473 * 7.1 Modified next.c and nextc.c so that they check "mvv_lva_ordering" *
474 * to determine which capture ordering strategy to use. Note that *
475 * setting this to "1" (default at present) disables the forward *
476 * pruning in quiescence search that wants to cull losing captures. *
477 * *
478 * 7.2 Major clean-up of MakeMove() using macros to make it easier to *
479 * read and understand. Ditto for other modules as well. Fixed a *
480 * bug in Evaluate() where bishop scoring failed in endgame *
481 * situations, and discouraged king centralization. *
482 * *
483 * 7.3 Evaluate() is no longer called if material is too far outside the *
484 * current alpha/beta window. The time-consuming part of Evaluate() *
485 * is no longer done if the major scoring contributors in Evaluate() *
486 * haven't pulled the score within the alpha/beta window, and the *
487 * remainder of Evaluate() can't possible accomplish this either. *
488 * Gross error in EvaluatePawns() fixed, which would "forget" all *
489 * of the pawn scoring done up to the point where doubled white *
490 * pawns were found. Error was xx=+ rather than xx+=, which had *
491 * an extremely harmful effect on pawn structure evaluation. *
492 * *
493 * 7.4 Performance improvements produced by elimination of bit-fields. *
494 * This was accomplished by hand-coding the necessary ANDs, ORs, and *
495 * SHIFTs necessary to accomplish the same thing, only faster. *
496 * *
497 * 7.5 Repetition code modified. It could store at replist[-1] which *
498 * clobbered the long long word just in front of this array. *
499 * *
500 * 7.6 Null move search now searches with R=2, unless within 3 plies *
501 * of the quiescence search, then it searches nulls with R=1. *
502 * *
503 * 8.0 Re-vamp of evaluation, bringing scores back down so that Crafty *
504 * will stop sacrificing the exchange, or a piece for two pawns just *
505 * it thinks it has lots of positional compensation. The next few *
506 * versions are going to be tuning or coding modifications to eval. *
507 * *
508 * 8.1 Futility() re-written to be more efficient, as well as to stop *
509 * tossing moves out based on the +/- 2 pawn window, which was too *
510 * speculative. It still saves roughly 20% in speed over the same *
511 * searches without futility, but seems to have *no* harmful effects *
512 * in tests run to date. *
513 * *
514 * 8.2 Futility() removed once and for all. Since MakeMove() is so *
515 * fast after the new attack generation algorithm, this was actually *
516 * slower than not using it. *
517 * *
518 * 8.3 EvaluatePawns() weak pawn analysis bug fixed. Other minor *
519 * performance enhancements and cleanup. *
520 * *
521 * 8.4 Dynamic "king tropism" evaluation term now used, which varies *
522 * based on how exposed the target king is. The more exposed, the *
523 * larger the bonus for placing pieces near the king. New "analyze" *
524 * feature that complements the "annotate" feature that Crafty has *
525 * had for a while. Annotate is used to play over moves that are *
526 * either in the current game history, or have been read in using *
527 * the "read <filename>" command. Analyze, on the other hand, will *
528 * immediately begin searching the current position. Each time the *
529 * operator enters a move, it will make that move on the board, and *
530 * then search the resulting position for the other side. In effect *
531 * this gives a running commentary on a "game in progress". These *
532 * moves can be pumped into Crafty in many ways so that "on the fly" *
533 * analysis of a game-in-progress is possible. *
534 * *
535 * 8.5 More cleanup. Pawn promotions were searched twice, thanks to the *
536 * killer moves, although often they resulted in no search overhead *
537 * due to transposition table hits the second time around. Other *
538 * minor fixes, including one serious "undefined variable" in *
539 * Evaluate() that caused grief in endings. *
540 * *
541 * 8.6 New book file structure. It is no longer necessary to enter the *
542 * "number of records" as Crafty now uses a new compressed hashing *
543 * technique so that the book has no empty space in it, and the size *
544 * is computed "on the fly" producing a smaller book without the *
545 * user having to compute the size. Tweaks to Evaluate() to cure *
546 * minor irritating habits. *
547 * *
548 * 8.7 Repaired optimization made in null-move search, that forgot to *
549 * clear "EnPassant_Target". A double pawn push, followed by a null *
550 * left the side on move "very confused" and would let it play an *
551 * illegal enpassant capture in the tree. Sort.<n> files are now *
552 * removed after book.bin is created. Also, minor change to book *
553 * format makes it incompatible with older book versions, but also *
554 * allows book lines to be as long as desired, and the book size to *
555 * reach any reasonable size. Dynamic king tropism replaced by a *
556 * dynamic computation, but with a static king tropism score, rather *
557 * than a score based on king exposure. There was simply too much *
558 * interaction, although this may prove workable later. *
559 * *
560 * 8.8 Tweaks to passed pawn scoring. Scores were too low, making *
561 * Crafty "ignore" them too much. *
562 * *
563 * 8.9 Internal iterative deepening is now used in those rare positions *
564 * where a PV node has no hash move to search. This does a shallow *
565 * search to depth-2 to find a good move for ordering. *
566 * *
567 * 8.10 Internal interative deepening modified to handle cases where lots *
568 * of tactics make the deepening search fail high or low, and *
569 * occasionally end up with no move to try. This produced a "bad *
570 * move from hash table" error. *
571 * *
572 * 8.11 Minor bug in internal iterative deepening fixed. Also, macros *
573 * for accessing the "position" data structure are now used to make *
574 * things a little more readable. *
575 * *
576 * 8.12 Fixed minor bugs in quiescence checks, which let Crafty include *
577 * more checks than intended (default quiescence_checks=2, but the *
578 * comparison was <= before including a check, which made it include *
579 * three. Additionally, a hashed check was *always* tried, even if *
580 * quiescence_checks had already been satisfied. Pawn scoring also *
581 * had a bug, in that there was a "crack" between opening and middle *
582 * game, where Crafty would conclude that it was in an endgame, and *
583 * adjust the pawn advance scores accordingly, sometimes causing an *
584 * odd a4/a5/etc move "out of the blue." Minor bug in next_capture *
585 * was pruning even exchanges very early in quiescence search. That *
586 * has now been removed, so only losing exchanges are pruned. *
587 * *
588 * 8.13 NextCapture() now *always* tries checking moves if the move at *
589 * the previous ply was a null-move. This avoids letting the null *
590 * move hide some serious mating threats. A minor bug where Crafty *
591 * could draw by repetition after announcing a mate. This was a *
592 * result of finding a mate score in hash table, and, after the *
593 * search iteration completed, the mate score would terminate the *
594 * search completely. Now, the search won't terminate until it *
595 * finds a mate shorter than the previous search did. Minor eval *
596 * tweaks and bugfixes as well. *
597 * *
598 * 8.14 Checks after null moves discontinued. Worked in some cases, but, *
599 * in general made the tree larger for nothing. Eval tweaks to stop *
600 * sacs that resulted in connected passed pawns, often at the *
601 * expense of a minor piece for a pawn or two, which usually lost. *
602 * Mobility coeffecient increased for all pieces. Asymmetric king *
603 * safety discontinued. King safety for both sides is now equally *
604 * important. King safety is now also proportional to the number of *
605 * pieces the other side has, so that a disrupted king-side will *
606 * encourage trading pieces to reduce attacking chances. *
607 * *
608 * 8.15 Weak pawn scoring modified further. The changes are designed to *
609 * cause Crafty to keep pawns "mobile" where they can advance, *
610 * rather than letting them become blocked or locked. *
611 * *
612 * 8.16 Still more weak pawn modifications. In addition, there is no *
613 * "rook on half-open file" any longer. If there are only enemy *
614 * pawns on the file, and the most advanced one is weak, then the *
615 * file is treated as though it were open. Technical error in the *
616 * EvaluateDevelopment() code that caused screwey evaluations is *
617 * fixed, making Crafty more likely to castle. :) Book() now *
618 * verifies that the current position is in book, before trying any *
619 * moves to see if the resulting positions are in book. This avoids *
620 * something like e4 e5 Bb5 a6 Nf3 from causing Crafty to play Nc6 *
621 * which takes it back into book, rather than axb5 winning a piece. *
622 * This will occasionally backfire and prevent Crafty from trans- *
623 * posing back into book, but seems safer at present. *
624 * *
625 * 8.17 Piece values changed somewhat, to avoid Crafty's propensity to *
626 * make unfavorable trades. An example: Crafty is faced with the *
627 * loss of a pawn. Instead, it trades the queen for a rook and *
628 * bishop, which used to be the same as losing a pawn. This is not *
629 * so good, and often would result in a slow loss. This version *
630 * also implements several "user-supplied" patches to make Crafty *
631 * compile cleanly on various machines. In addition, you no longer *
632 * have to continually modify types.h for different configurations. *
633 * the Makefile now supplies a -D<target> to the compiler. You need *
634 * to edit Makefile and set "target" to the appropriate value from *
635 * the list provided. Then, when getting a new version, save your *
636 * Makefile, extract the new source, copy in your makefile and you *
637 * will be ready, except for those rare occasions where I add a new *
638 * source module. Other changes are performance tweaks. One is a *
639 * simple trick to order captures while avoiding SEE() if possible. *
640 * If the captured piece is more valuable than the capturing piece, *
641 * we can simply use the difference (pessimistic value) rather than *
642 * calling SEE() since this pessimistic value is still > 0. Other *
643 * tweaks to the various Next_*() routines to avoid a little un- *
644 * necessary work. *
645 * *
646 * 8.18 Book move selection algorithm changed. Note that this is highly *
647 * speculative, but when best book play is selected, Crafty will *
648 * use the books.bin file as always. If there is no move in books, *
649 * Crafty reverts to book.bin, but now finds all known book moves *
650 * and puts them into the root move list. It then does a fairly *
651 * short search, only considering these moves, and it will play the *
652 * best one so long as the evaluation is acceptable. If not, it *
653 * simply returns as though there was no book move, and executes a *
654 * search as it normally would. The book hashing algorithm was also *
655 * modified so that the 64-bit hash key is slightly different from *
656 * the real hash key. In effect, the upper 16 bits are only set as *
657 * a result of the side-not-to-move's pieces. This means that for a *
658 * given position, all the book moves will be in the same "cluster" *
659 * which makes the book dramatically faster, since one seek and read *
660 * produces all the possible book moves (plus some others too, since *
661 * the upper 16 bits are not unique enough.) A significant speed *
662 * improvement is noticable, particularly with a 60mb opening book. *
663 * Crafty now understands (if that's the right word) that endings *
664 * with bishops of opposite colors are to be avoided. When such an *
665 * ending is encountered, the total score is simply divided by two *
666 * to make the ending look more drawish. *
667 * *
668 * 8.19 Book selection algorithm further modified, so that the result of *
669 * each game in the GM database is known. Now Crafty will not play *
670 * a move from book, if all games were lost by the side on move, *
671 * hopefully avoiding many blunders. Crafty now understands how to *
672 * attack if both players castle on opposite sides, by encouraging *
673 * pawn advances against the kings. Other minor modifications to *
674 * the eval values. *
675 * *
676 * 8.20 PVS search finally implemented fully. Problems several months *
677 * ago prevented doing the PVS search along the PV itself. This is *
678 * therefore quite a bit faster, now that it's fully implemented and *
679 * working properly. Elapsed time code modified so that Crafty now *
680 * uses gettimeofday() to get fractions of a second elapsed time. *
681 * Slight modification time allocation algorithm to avoid using too *
682 * much time early in the game. *
683 * *
684 * 8.21 Courtesy of Mark Bromley, Crafty may run significantly faster on *
685 * your machine. There are some options in the Makefile that will *
686 * eliminate many of the large attack computation long longs, which *
687 * helps prevent cache thrashing. On some machines this will be *
688 * slower, on others 20% (or maybe more) faster. You'll have to *
689 * try -DCOMPACT_ATTACKS, and if that's faster, then it's time to *
690 * try -DUSE_SPLIT_SHIFTS which may help even more. Finally, if you *
691 * are running on a supersparc processor, you can use the fastattack *
692 * assembly module fastattack.s and get another big boost. (Attack *
693 * function is largest compute user in Crafty at present.) Serious *
694 * search problem fixed. It turns out that Crafty uses the hash *
695 * table to pass PV moves from one iteration to the next, but for *
696 * moves at the root of the tree the hash table has no effect, so a *
697 * special case was added to RootMoveList to check the list of moves *
698 * and if one matches the PV move, move it to the front of the list. *
699 * This turned out to be critical because after completing a search, *
700 * (say to 9 plies) Crafty makes its move, then chops the first two *
701 * moves off of the PV and then passes that to iterate to start a *
702 * search. This search starts at lastdepth-1 (8 in this case) since *
703 * the n-2 search was already done. The "bug" showed up however, in *
704 * that RootMoveList() was not checking for the PV move correctly, *
705 * which meant the root moves were ordered by static eval and static *
706 * exchange evaluation. Normally not a serious problem, just that *
707 * move ordering is not so good. However, suppose that the opponent *
708 * takes a real long time to make a move (say 30 seconds) so that *
709 * Crafty completes a 10 ply search. It then starts the next search *
710 * at depth=9, but with the wrong move first. If the target time is *
711 * not large enough to let it resolve this wrong move and get to the *
712 * other moves on the list, Crafty is "confused" into playing this *
713 * move knowing absolutely nothing about it. The result is that it *
714 * can play a blunder easily. The circumstances leading to this are *
715 * not common, but in a 60 move game, once is enough. PV was pretty *
716 * well mis-handled in carrying moves from one search to another *
717 * (not from one iteration to another, but from one complete search *
718 * to another) and has been fixed. A cute glitch concerning storing *
719 * PV from one iteration to another was also fixed, where the score *
720 * stored was confusing the following search. *
721 * *
722 * 8.22 EPD support (courtesy of Steven Edwards [thanks]) is now standard *
723 * in Crafty. For porting, I'll provide a small test run which can *
724 * be used to validate Crafty once it's been compiled. *
725 * *
726 * 8.23 Cleanup/speedup in hashing. ProbeTransRef() and StoreTransRef() *
727 * now carefully cast the boolean operations to the most efficient *
728 * size to avoid 64bit operations when only the right 32 bits are *
729 * significant. Repeat() code completely re-written to maintain two *
730 * repetition lists, one for each side. Quiesce() now handles the *
731 * repetition check a little different, being careful to not call it *
732 * when it's unimportant, but calling it when repetitions are *
733 * possible. *
734 * *
735 * 8.24 Tweaks for king tropism to encourage pieces to collect near the *
736 * king, or to encourage driving them away when being attacked. A *
737 * modification to Evaluate() to address the problem where Crafty *
738 * is forced to play Kf1 or Kf8, blocking the rook in and getting *
739 * into tactical difficulties as a result. Book problem fixed where *
740 * Bookup was attempting to group moves with a common ancestor *
741 * position together. Unfortunately, captures were separated from *
742 * this group, meaning capture moves in the book could never be *
743 * played. If a capture was the only move in book, it sort of *
744 * worked because Crafty would drop out of book (not finding the *
745 * capture) and then the search would "save" it. However, if there *
746 * was a non-capture alternative, it would be forced to play it, *
747 * making it play gambits, and, often, bad ones. Tablebase support *
748 * is now in. The tablebase files can be downloaded from the ftp *
749 * machine at chess.onenet.net, pub/chess/TB. Currently, Steven *
750 * Edwards has all interesting 4 piece endings done. To make this *
751 * work, compile with -DTABLEBASES, and create a TB directory where *
752 * Crafty is run, and locate the tablebase files in that directory. *
753 * If you are running under UNIX, TB can be a symbolic or hard link *
754 * to a directory anywhere you want. *
755 * *
756 * 8.25 Minor repair on draw by repetition. Modified how books.bin was *
757 * being used. Now, a move in books.bin has its flags merged with *
758 * the corresponding move from book.bin, but if the move does not *
759 * exist in book.bin, it is still kept as a book move. Repetitions *
760 * are now counted as a draw if they occur two times, period. The *
761 * last approach was causing problems due to hashing, since the hash *
762 * approach used in Crafty is fairly efficient and frequently will *
763 * carry scores across several searches. This resulted in Crafty *
764 * stumbling into a draw by repetition without knowing. The con- *
765 * figuration switch HAS-64BITS has been cleaned up and should be *
766 * set for any 64bit architecture now, not just for Cray machines. *
767 * *
768 * 8.26 New search extension added, the well-known "one legal response to *
769 * check" idea. If there's only one legal move when in check, we *
770 * extend two plies rather than one, since this is a very forcing *
771 * move. Also, when one side has less than a rook, and the other *
772 * has passed pawns, pushing these pawns to the 6th or 7th rank *
773 * will extend the search one ply, where in normal positions, we *
774 * only extend when a pawn reaches the 7th rank. *
775 * *
776 * 9.0 Minor constraint added to most extensions: we no longer extend *
777 * if the side on move is either significantly ahead or behind, *
778 * depending on the extension. For example, getting out of check *
779 * won't extend if the side on move is a rook behind, since it's *
780 * already lost anyway. We don't extend on passed pawn pushes if *
781 * the side on move is ahead a rook, since he's already winning. *
782 * minor adjustments for efficiency as well. The next few versions *
783 * in this series will have module names in these comments *
784 * indicating which modules have been "cleaned" up. This is an *
785 * effort at optimizing, although it is currently directed at a line *
786 * by line analysis within modules, rather than major changes that *
787 * effect more global ideas. This type of optimization will come at *
788 * a later point in time. *
789 * *
790 * 9.1 NextMove(), NextCapture() and NextEvasion() were re-structured *
791 * to eliminate unnecessary testing and speed them up significantly. *
792 * EvaluateTrades() was completely removed, since Crafty already has *
793 * positional scores that encourage/discourage trading based on the *
794 * status of the game. EvaluateTempo() was evaluated to be a *
795 * failure and was removed completely. *
796 * *
797 * 9.2 Quiesce()) and Search() were modified to be more efficient. In *
798 * addition, the null-move search was relaxed so that it always does *
799 * a search to depth-R, even if close to the end of the tree. *
800 * *
801 * 9.3 Check() is no longer used to make sure a position is legal after *
802 * MakeMove() called, but before Search() is called recursively. We *
803 * now use the same approach as Cray Blitz, we make a move and then *
804 * capture the king at the next ply to prove the position is not a *
805 * valid move. If the side-on-move is already in check, we use *
806 * NextEvasion() which only generates legal moves anyway, so this *
807 * basically eliminates 1/2 of the calls to Check(), a big win. *
808 * This resulted in modifications to Search(), Quiesce(), and *
809 * QuiesceFull(). Connected passed pawns on 6th-7th no longer *
810 * trigger search extensions. Solved some problems like Win at *
811 * Chess #2, but overall was a loser. *
812 * *
813 * 9.4 Lookup now checks the transposition table entry and then informs *
814 * Search() when it appears that a null move is useless. This is *
815 * found when the draft is too low to use the position, but it is at *
816 * least as deep as a null-move search would go, and the position *
817 * did not cause a fail-high when it was stored. King-safety was *
818 * modified again. The issue here is which king should attract the *
819 * pieces, and for several months the answer has been the king that *
820 * is most exposed attracts *all* pieces. This has been changed to *
821 * always attract one side's pieces to the other king. Crafty's *
822 * asymmetric king-safety was making it overly-defensive, even when *
823 * the opponent's king was more exposed. This should cure that and *
824 * result in more aggressive play. *
825 * *
826 * 9.5 "Vestigial code" (left over from who-knows-when) removed from *
827 * Evaluate(). This code used an undefined variable when there was *
828 * no bishop or knight left on the board, and could add in a penalty *
829 * on random occasions. Quiescence checks removed completely to see *
830 * how this works, since checks extend the normal search significant *
831 * amounts in any case. QuiesceFull() removed and merged into *
832 * Quiesce() which is faster and smaller. First impression: faster, *
833 * simpler, better. The benefit of no quiescence checks is that the *
834 * exhaustive search goes deeper to find positional gains, rather *
835 * than following checks excessively. No noticable loss in tactical *
836 * strength (so far). *
837 * *
838 * 9.6 legal move test re-inserted in Search() since null-moves could *
839 * make it overlook the fact that a move was illegal. New assembly *
840 * code for X86 improves performance about 1/3, very similarly to *
841 * the results obtained with the sparc-20 assembly code. This was *
842 * contributed by Eugene Nalimov and is a welcome addition. *
843 * *
844 * 9.7 Optimizations continuing. Minor bug in pawn evaluation repaired. *
845 * Crafty looked at most advanced white pawn, but least-advanced *
846 * black pawn on a file when doing its weak pawn evaluation. The *
847 * history heuristic was slightly broken, in that it was supposed to *
848 * be incrementing the history count by depth*depth, but this was *
849 * somehow changed to 7*depth, which was not as good. Assembly *
850 * language interface fixed to cleanly make Crafty on all target *
851 * architectures. *
852 * *
853 * 9.8 The first change was to borrow a time-allocation idea from Cray *
854 * Blitz. Essentially, when Crafty notices it has used the normal *
855 * time allotment, rather than exiting the search immediately, it *
856 * will wait until it selects the next move at the root of the tree. *
857 * The intent of this is that if it has started searching a move *
858 * that is going to be better than the best found so far, this will *
859 * take more time, while a worse move will fail low quickly. Crafty *
860 * simply spends more time to give this move a chance to fail high *
861 * or else quickly fail low. A fairly serious bug, that's been *
862 * around for a long time, has finally been found/fixed. In simple *
863 * terms, if the "noise" level was set too high, it could make *
864 * Crafty actually play a bad move. The more likely effect was to *
865 * see "bad move hashed" messages and the first few lines of output *
866 * from the search often looked funny. The bug was "noise" was used *
867 * as a limit, until that many nodes had been searched, no output *
868 * would be produced. Unfortunately, on a fail-high condition, the *
869 * same code that produced the "++ Nh5" message also placed the *
870 * fail-high move in the PV. Failing to do this meant that the *
871 * search could fail high, but not play the move it found. Most *
872 * often this happened in very fast games, or near the end of long *
873 * zero-increment games. It now always saves this move as it should *
874 * regardless of whether it prints the message or not. *
875 * *
876 * 9.9 Interface to Xboard changed from -ics to -xboard, so that -ics *
877 * can be used with the custom interface. Additional code to *
878 * communicate with custom interface added. Search() extensions are *
879 * restricted so that there can not be more than one extension at a *
880 * node, rather than the two or (on occasion) more of the last *
881 * version. *
882 * *
883 * 9.10 Converted to Ken Thompson's "Belle" hash table algorithm. Simply *
884 * put, each side has two tables, one that has entries replaced on a *
885 * depth-priority only, the other is an "always replace" table, but *
886 * is twice as big. This allows "deep" entries to be kept along *
887 * with entries close to search point. Basically, when the depth- *
888 * priority table gets a position stored in it, the displaced *
889 * position is moved to the always-replace table. If the position *
890 * can not replace the depth-priority entry, it always overwrites *
891 * the other always-replace entry. However, a position is never put *
892 * in both tables at the same time. *
893 * *
894 * 9.11 Bug in Search() that could result in the "draft" being recorded *
895 * incorrectly in the hash table. Caused by passing depth, which *
896 * could be one or two plies more than it should be due to the last *
897 * move extending the search. Repeat() completely removed from *
898 * Quiesce() since only capture moves are included, and it's *
899 * impossible to repeat a position once a capture has been made. *
900 * *
901 * 9.12 optimizations: history.c, other minor modifications. *
902 * *
903 * 9.13 EvaluatePawns() modified significantly to simplify and be more *
904 * accurate as well. Pawns on open files are now not directly *
905 * penalized if they are weak, rather the penalty is added when the *
906 * rooks are evaluated. Pawn hashing modified to add more info to *
907 * the data that is hashed. King safety scores toned down almost *
908 * 50% although it is still asymmetric. *
909 * *
910 * 9.14 EvaluatePawns() modified further so that it now does the same *
911 * computations for king safety as the old EvaluateKingSafety*() *
912 * modules did, only it produces four values, two for each king, *
913 * for each side of the board (king or queen-side). This is now *
914 * hashed with the rest of the pawn scoring, resulting in less *
915 * hashing and computation, and more hits for king-safety too. King *
916 * safety modified further. Asymmetric scoring was accidentally *
917 * disabled several versions ago, this is now enabled again. *
918 * *
919 * 9.15 Evaluate() now attempts to recognize the case where a knight is *
920 * trapped on one of the four corner squares, much like a bishop *
921 * trapped at a2/a7/h2/h7. If a knight is on a corner square, and *
922 * neither of the two potential flight squares are safe (checked by *
923 * SEE()) then a large penalty is given. This was done to avoid *
924 * positions where Crafty would give up a piece to fork the king and *
925 * rook at (say) c7, and pick up the rook at a8 and think it was an *
926 * exchange ahead, when often the knight was trapped and it was *
927 * two pieces for a rook and pawn (or worse.) Two timing bugs fixed *
928 * in this version: (1) nodes_per_second was getting clobbered at *
929 * the end of iterate, which would then corrupt the value stored in *
930 * nodes_between_time_checks and occasionally make Crafty not check *
931 * the time very often and use more time than intended; (2) the *
932 * "don't stop searching after time is out, until the current move *
933 * at the root of the tree has been searched" also would let Crafty *
934 * use time unnecessarily. *
935 * *
936 * 9.16 Significant changes to the way MakeMove() operates. Rather than *
937 * copying the large position[ply] structure around, the piece *
938 * location bitmaps and the array of which piece is on which square *
939 * are now simple global variables. This means that there is now an *
940 * UnmakeMove() function that must be used to restore these after a *
941 * a move has been made. The benefit is that we avoid copying 10 *
942 * bitmaps for piece locations when typically only one is changed, *
943 * Ditto for the which piece is on which square array which is 64 *
944 * bytes long. The result is much less memory traffic, with the *
945 * probability that the bitmaps now stay in cache all the time. The *
946 * EvaluatePawns() code now has an exponential-type penalty for *
947 * isolated pawns, but it penalizes the difference between white and *
948 * black isolated pawns in this manner. King evaluation now *
949 * evaluates cases where the king moves toward one of the rooks and *
950 * traps it in either corner. *
951 * *
952 * 9.17 Xboard compatibility version! Now supports, so far as I know, *
953 * the complete xboard interface, including hint, show thinking, *
954 * taking back moves, "move now" and so forth. Additionally, Crafty *
955 * now works with standard xboard. Notice that this means that a *
956 * ^C (interrupt) will no long terminate Crafty, because xboard uses *
957 * this to implement the "move now" facility. This should also *
958 * work with winboard and allow pondering, since there is now a *
959 * special windows version of CheckInput() that knows how to check *
960 * Win95 or WinNT pipes when talking with winboard. *
961 * *
962 * 9.18 Xboard compatibility update. "force" (gnu) mode was broken, so *
963 * that reading in a PGN file (via xboard) would break. Now, Crafty *
964 * can track the game perfectly as xboard reads the moves in. King *
965 * safety modified to discourage g3/g6 type moves without the bishop *
966 * to defend the weak squares. Significant other changes to the *
967 * Evaluate() procedure and its derivatives. Very nasty trans/ref *
968 * bug fixed. Been there since transposition tables added. When *
969 * storing a mate score, it has to be adjusted since it's backed up *
970 * as "mate in n plies from root" but when storing, it must be saved *
971 * as "mate in n plies from current position". Trivial, really, but *
972 * I overlooked one important fact: mate scores can also be upper *
973 * or lower search bounds, and I was correcting them in the same way *
974 * which is an error. The effect was that Crafty would often find a *
975 * mate in 2, fail high on a move that should not fail high, and end *
976 * up making a move that would mate in 3. In particularly bad cases *
977 * this would make the search oscillate back and forth and draw a *
978 * won position. The fix was to only adjust the score if it's a *
979 * score, not if it's a bound. The "age" field of the trans/ref *
980 * table was expanded to 3 bits. Iterate now increments a counter *
981 * modulo 8, and this counter is stored in the 3 ID bits of the *
982 * trans/ref table. If they are == the transposition_id counter, *
983 * we know that this is a position stored during the current search. *
984 * If not, it's an "old" position. This avoids the necessity of *
985 * stepping through each entry in the trans/ref table (at the begin- *
986 * ning of a search) to set the age bit. Much faster in blitz games *
987 * as stepping through the trans/ref table, entry by entry, would *
988 * blow out cache. This idea was borrowed from Cray Blitz, which *
989 * used this same technique for many years. *
990 * *
991 * 9.19 New evaluation code for passed pawns. Crafty now gives a large *
992 * bonus for two or more connected passed pawns, once they reach the *
993 * sixth rank, when the opponent has less than a queen remaining. *
994 * this will probably be tuned as experience produces the special *
995 * cases that "break" it. Such things as the king too far away or *
996 * the amount of enemy material left might be used to further im- *
997 * prove the evaluation. *
998 * *
999 * 9.20 Bug in SetBoard() fixed. Validity checks for castling status and *
1000 * en passant status was broken for castle status. It was checking *
1001 * the wrong rook to match castling status, and would therefore not *
1002 * accept some valid positions, including #8 in Win At Chess suite. *
1003 * Minor repetition bug fixed, where Crafty would recognize that a *
1004 * three-fold repetition had occurred, but would not claim it when *
1005 * playing on a chess server. Crafty now does not immediately re- *
1006 * search the first move when it fails low. Rather, it behaves like *
1007 * Cray Blitz, and searches all moves. If all fail low, Crafty will *
1008 * then relax (lower) alpha and search the complete list again. *
1009 * This is a simple gamble that there is another move that will *
1010 * "save the day" so that we avoid the overhead of finding out just *
1011 * how bad the first move is, only to have more overhead when a good *
1012 * move fails high. Minor repetition bug fixed. When running test *
1013 * suites of problems, SetBoard() neglected to put the starting *
1014 * position in the repetition list, which would occasionally waste *
1015 * time. One notable case was Win At Chess #8, where Crafty would *
1016 * find Nf7+ Kg8 Nh6+ Kh8 (repeating the original position) followed *
1017 * by Rf7 (the correct move, but 4 tempi behind.) Display() bug *
1018 * fixed. Crafty now displays the current board position, rather *
1019 * than the position that has been modified by a search in progress. *
1020 * Castling evaluation modified including a bug in the black side *
1021 * that would tend to make Crafty not castle queen-side as black if *
1022 * the king-side was shredded. Minor bug in Book(). If the book was *
1023 * turned off (which is done automatically when using the test com- *
1024 * mand since several of the Win At Chess positions are from games *
1025 * in Crafty's large opening book) Book() would still try to read *
1026 * the file and then use the data from the uninitialized buffer. *
1027 * This would, on occasion, cause Crafty to crash in the middle of *
1028 * a test suite run. *
1029 * *
1030 * 9.21 Castling evaluation has been significantly modified to handle the *
1031 * following three cases better: *
1032 * (a) One side can castle at the root of the tree, but can not *
1033 * castle at a tip position. If the move that gave up the right to *
1034 * castle was *not* a castle move, penalize the score. *
1035 * (b) One side can castle short or long at the root, but has al- *
1036 * ready castled by the time the search reaches a tip position. *
1037 * Here the goal is to make sure the player castled to the "better" *
1038 * side by comparing king safety where the king really is, to king *
1039 * safety had the king castled to the other side. If the latter is *
1040 * "safer" then penalize the current position by the "difference" *
1041 * in king safety to encourage that side to delay castling. This is *
1042 * a problem when Crafty can castle kingside *now*, but the kingside *
1043 * has been disrupted somehow. If the search is not deep enough to *
1044 * see clearing out the queenside and castling long, then it will *
1045 * often castle short rather than not castle at all. This fix will *
1046 * make it delay, develop the queenside, and castle to a safer king *
1047 * shelter, unless tactics force it to castle short. *
1048 * (c) One side can castle short or long at the root, but can only *
1049 * castle one way at a tip position, because a rook has been moved. *
1050 * If the remaining castle option is worse than castling to the side *
1051 * where the rook was moved, then we penalize the rook move to keep *
1052 * castling to that side open as an option. *
1053 * *
1054 * 9.22 More castling evaluation changes, to tune how/when Crafty chooses *
1055 * to castle. Bugs in Option() where certain commands could be ex- *
1056 * ecuted while a search was in progress. If these commands did *
1057 * anything to the board position, It would break Crafty badly. *
1058 * All that was needed was to check for an active search before some *
1059 * commands were attempted, and if a search was in progress, return *
1060 * to abort the search then re-try the command. When playing games *
1061 * with computers (primarily a chess-server consideration) Crafty is *
1062 * now defaulting to "book random 0" to use a short search to help *
1063 * avoid some ugly book lines on occasion. In this version, *all* *
1064 * positional scores were divided by 2 to reduce the liklihood that *
1065 * Crafty would sacrifice material and make up the loss with some *
1066 * sort of positional gain that was often only temporary. Note that *
1067 * king safety scores were not reduced while doing this. New book *
1068 * random options: 0=search, 1=most popular move, 2=move that *
1069 * produces best positional value, 3=choose from most frequently *
1070 * played moves, 4=emulate GM frequency of move selection, 5=use *
1071 * sqrt() on frequencies to give more randomness, 6=random. For *
1072 * now, computers get book_random=1, while GM's now get 4 (same as *
1073 * before), everyone else gets 5. Until now, there has been no *
1074 * penalty for doubled/tripled pawns. It now exists. Also, if the *
1075 * king stands on E1/E8, then the king-side king safety term is used *
1076 * to discourage disrupting the king-side pawns before castling. *
1077 * Crafty now has a start-up initialization file (as most Unix *
1078 * programs do). This file is named ".craftyrc" if the macro UNIX *
1079 * is defined, otherwise a "dossy" filename "crafty.rc" is used. *
1080 * Crafty opens this file and executes every command in it as though *
1081 * they were typed by the operator. The last command *must* be *
1082 * "exit" to revert input back to STDIN. *
1083 * *
1084 * 9.23 More evaluation tuning, including the complete removal of the *
1085 * mobility term for rooks/queens. Since rooks already have lots *
1086 * of scoring terms like open files, connected, etc, mobility is *
1087 * redundant at times and often misleading. The queen's mobility *
1088 * is so variable it is nearly like introducing a few random points *
1089 * at various places in the search. Minor Xboard compatibility bug *
1090 * fixed where you could not load a game file, then have Crafty play *
1091 * by clicking the "machine white" or "machine black" options. *
1092 * *
1093 * 9.24 Minor bug in Quiesce() repaired. When several mate-in-1 moves *
1094 * were available at the root, Crafty always took the last one, *
1095 * which was often an under-promotion to a rook rather than to a *
1096 * queen. It looked silly and has been fixed so that it will play *
1097 * the first mate-in-1, not the last. RootMoveList() went to great *
1098 * pains to make sure that promotion to queen occurs before rook. *
1099 * Bug in EvaluateOutsidePassedPawns() would fail to recognize that *
1100 * one side had an outside passer, unless both sides had at least *
1101 * one passer, which failed on most cases seen in real games. *
1102 * Minor "tweak" to move ordering. GenerateMoves() now uses the *
1103 * LSB() function to enumerate white moves, while still using MSB() *
1104 * for black moves. This has the effect of moving pieces toward *
1105 * your opponent before moving them away. A severe oversight *
1106 * regarding the use of "!" (as in wtm=!wtm) was found and corrected *
1107 * to speed things up some. !wtm was replaced by wtm^1 (actually, *
1108 * a macro Flip(wtm) is used to make it more readable) which *
1109 * resulted in significant speedup on the sparc, but a more modest *
1110 * improvement on the pentium. *
1111 * *
1112 * 9.25 Minor bug in Book() fixed where it was possible for Crafty to *
1113 * play a book move that was hardly ever played. Minor change to *
1114 * time utilization to use a little more time "up front". Tuned *
1115 * piece/square tables to improve development some. Saw Crafty lose *
1116 * an occasional game because (for example) the bishop at c1 or c8 *
1117 * had not moved, but the king had already castled, which turned the *
1118 * EvaluateDevelopment() module "off". first[ply] removed, since it *
1119 * was redundant with last[ply-1]. The original intent was to save *
1120 * a subscript math operation, but the compilers are quite good with *
1121 * the "strength-reduction" optimization, making referencing a value *
1122 * by first[ply] or last[ply-1] exactly the same number of cycles. *
1123 * Passed pawn scores increased. The reduction done to reduce all *
1124 * scores seemed to make Crafty less attentive to passed pawns and *
1125 * the threats they incur. Minor bug in Book() fixed, the variable *
1126 * min_percent_played was inoperative due to incorrect test on the *
1127 * book_status[n] value. Pawn rams now scored a little differently, *
1128 * so that pawn rams on Crafty's side of the board are much worse *
1129 * than rams elsewhere. This avoids positional binds where, for ex- *
1130 * ample Crafty would like black with pawns at e6 d5 c6, white with *
1131 * pawns at e5 and c5. Black has a protected passed pawn at d5 for *
1132 * sure, but the cramp makes it easy for white to attack black, and *
1133 * makes it difficult for black to defend because the black pawns *
1134 * block the position badly. King safety tweaked up about 30%, due *
1135 * to using nearly symmetrical scoring, the values had gotten too *
1136 * small and were not overriding minor positional things. *
1137 * *
1138 * 9.26 Minor bug fixes in time allocation. This mainly affects Crafty *
1139 * as it plays on a chess server. The problem is, simply, that the *
1140 * current internal timing resolution is 1/10 of a second, kept in *
1141 * an integer variable. .5 seconds is stored as 5, for example. *
1142 * This became a problem when the target time for a search dropped *
1143 * below .3 seconds, because the "easy move" code would terminate *
1144 * the search after 1/3 of the target time elapsed if there were no *
1145 * fail lows or PV changes. Unfortunately, 2 divided by 3 (.2 secs *
1146 * /3) is "zero" which would let the search quickly exit, possibly *
1147 * without producing a PV with a move for Crafty to play. Crafty *
1148 * would play the first PV move anyway, which was likely the PV move *
1149 * from the last search. This would corrupt the board information, *
1150 * often produce the error "illegal move" when the opponent tried to *
1151 * move, or, on occasion, blow Crafty up. On a chess server, Crafty *
1152 * would simply flag and lose. After this fix, I played several *
1153 * hundred games with a time control of 100 moves in 1 second and *
1154 * there were no failures. Before the fix, this time control could *
1155 * not result in a single completed game. If you don't run Crafty *
1156 * on a chess server, this version is not important, probably. a *
1157 * minor fix for move input, so that moves like e2e4 will always be *
1158 * accepted, where before they would sometimes be flagged as errors. *
1159 * *
1160 * 9.27 This version has an interesting modification to NextCapture(). *
1161 * Quiesce() now passes alpha to NextCapture() and if a capture *
1162 * appears to win material, but doesn't bring the score up to the *
1163 * value of alpha, the capture is ignored. In effect, if we are so *
1164 * far behind that a capture still leaves us below alpha, then there *
1165 * is nothing to gain by searching the capture because our opponent *
1166 * can simply stand pat at the next ply leaving the score very bad. *
1167 * One exception is if the previous ply was in check, we simply look *
1168 * for any safe-looking capture just in case it leads to mate. Bad *
1169 * book bug with book random=1 or 2 fixed (this is set when playing *
1170 * a computer). This bug would cause Crafty to play an illegal move *
1171 * and bust wide open with illegal move errors, bad move hashed, and *
1172 * other things. Book randomness also quite a bit better now. *
1173 * *
1174 * 9.28 Piece/square table added for rooks. Primary purpose is to dis- *
1175 * courage rooks moving to the edge of the board but in front of *
1176 * pawns, where it is easy to trap it. Crafty now understands the *
1177 * concept of blockading a passed pawn to prevent it from advancing. *
1178 * it always understood that advancing one was good, which would *
1179 * tend to encourage blockading, but it would also often ignore the *
1180 * pawn and let it advance a little here, a little there, until it *
1181 * suddenly realized that it was a real problem. The command to set *
1182 * the size of the hash table has been modified. This command is *
1183 * now "hash n", "hash nK" or "hash nM" to set the hash table to one *
1184 * of bytes, Kbytes, or Mbytes. Note that if the size is not an *
1185 * exact multiple of what Crafty needs, it silently reduces the size *
1186 * to an optimum value as close to the suggested size as possible. *
1187 * Trade bonus/penalty is now back in, after having been removed *
1188 * when the new UnmakeMove() code was added. Crafty tries to trade *
1189 * pawns but not pieces when behind, and tries to trade pieces but *
1190 * not pawns when ahead. EvaluateDraws() now understands that rook *
1191 * pawns + the wrong bishop is a draw. Minor adjustment to the *
1192 * quiescence-search pruning introduced in 9.27, to avoid excluding *
1193 * captures that didn't lose material, but looked bad because the *
1194 * positional score was low. Slightly increased the values of the *
1195 * pieces relative to that of a pawn to discourage the tendency to *
1196 * trade a piece for two or three pawns plus some positional plusses *
1197 * that often would slowly vanish. Null-move search modified to try *
1198 * null-moves, even after captures. This seems to hurt some prob- *
1199 * lem positions, but speeds up others significantly. Seems better *
1200 * but needs close watching. EvaluateDraws() call moved to the top *
1201 * of Evaluate() to check for absolute draws first. Quiesce() now *
1202 * always calls Evaluate() which checks for draws before trying the *
1203 * early exit tests to make sure that draws are picked up first. *
1204 * EvaluateDraws() substantially re-written to get rid of lots of *
1205 * unnecessary instructions, and to also detect RP+B of wrong color *
1206 * even if the losing side has a pawn of its own. Crafty would *
1207 * often refuse to capture that last pawn to avoid reaching an end- *
1208 * game it knew was drawn. *
1209 * *
1210 * 9.29 New time.c as contributed by Mike Byrne. Basically makes Crafty *
1211 * use more time up front, which is a method of anticipating that *
1212 * Crafty will predict/ponder pretty well and save time later on *
1213 * anyway. InCheck() is never called in Quiesce() now. As a *
1214 * result, Crafty won't recognize mates in the q-search. This has *
1215 * speeded the code up with no visible penalty, other than it will *
1216 * occasionally find a win of material rather than a mate score, but *
1217 * this has not affected the problem suite results in a measurable *
1218 * way, other than Crafty is now about 10% faster in average type *
1219 * position, and much faster in others. The latest epd code from *
1220 * Steven Edwards is a part of this version, which includes updated *
1221 * tablebase access code. *
1222 * *
1223 * 10.0 New time.c with a "monitoring feature" that has two distinct *
1224 * functions: (1) monitor Crafty's time remaining and if it is too *
1225 * far behind the opponent, force it to speed up, or if it is well *
1226 * ahead on time, slow down some; (2) if opponent starts moving *
1227 * quickly, Crafty will speed up as well to avoid getting too far *
1228 * behind. EvaluateDraws() modified to detect that if one side has *
1229 * insufficient material to win, the score can never favor that side *
1230 * which will make Crafty avoid trading into an ending where it has *
1231 * KNN vs KB for example, where KNN seems to be ahead. *
1232 * *
1233 * 10.1 New book.c. Crafty now counts wins, losses and draws for each *
1234 * possible book move and can use these to play a move that had a *
1235 * high percentage of wins, vs the old approach of playing a move *
1236 * just because it was played a lot in the past. *
1237 * *
1238 * 10.2 Evaluation tuning. Rook on 7th, connected rooks on 7th, etc., *
1239 * are now more valuable. Crafty was mistakenly evaluating this *
1240 * too weakly. Book() changed so that the list of moves is first *
1241 * sorted based on winning percentages, but then, after selecting *
1242 * the sub-set of this group, the list is re-sorted based on the *
1243 * raw total games won so that the most popular opening is still the *
1244 * most likely to be played. *
1245 * *
1246 * 10.3 Timer resolution changed to 1/100th of a second units, with all *
1247 * timing variables conforming to this, so that it is unnecessary *
1248 * to multiply by some constant to convert one type of timing info *
1249 * to the standard resolution. Bug in evaluate.c fixed. Trapped *
1250 * rook (rook at h1, king at g1 for example) code had a bad sub- *
1251 * script that caused erroneous detection of a trapped rook when *
1252 * there was none. *
1253 * *
1254 * 10.4 Quiesce() no longer checks for time exceeded, nor does it do any *
1255 * hashing whatsoever, which makes it significantly faster, while *
1256 * making the trees only marginally bigger. *
1257 * *
1258 * 10.5 Quiesce() now calls GenerateCaptures() to generate capture moves. *
1259 * This new move generator module is significantly faster, which *
1260 * speeds the quiescence search up somewhat. *
1261 * *
1262 * 10.6 CastleStatus is now handled slightly differently. The right two *
1263 * bits still indicate whether or not that side can castle to either *
1264 * side, and 0 -> no castling at all, but now, <0 means that no *
1265 * castling can be done, and that castling rights were lost by *
1266 * making a move that was not castling. This helps in Evaluate() *
1267 * by eliminating a loop to see if one side castled normally or had *
1268 * to give up the right to castle for another (bad) reason. This is *
1269 * simply an efficiency issue, and doesn't affect play or anything *
1270 * at all other than to make the search faster. *
1271 * *
1272 * 10.7 NextMove() now doesn't try history moves forever, rather it will *
1273 * try the five most popular history moves and if it hasn't gotten a *
1274 * cutoff by then, simply tries the rest of the moves without the *
1275 * history testing, which is much faster. *
1276 * *
1277 * 10.8 Book() now "puzzles" differently. In puzzling, it is trying to *
1278 * find a move for the opponent. Since a book move by the opponent *
1279 * will produce an instant move, puzzle now enumerates the set of *
1280 * legal opponent moves, and from this set, removes the set of known *
1281 * book moves and then does a quick search to choose the best. We *
1282 * then ponder this move just in case the opponent drops out of book *
1283 * and uses a normal search to find a move. Crafty now penalizes *
1284 * a pawn that advances, leaving its neighbors behind where both *
1285 * the advancing pawn, and the ones being left behind become weaker. *
1286 * the opening phase of the game has been modified to "stay active" *
1287 * until all minor pieces are developed and Crafty has castled, to *
1288 * keep EvaluateDevelopment() active monitoring development. Minor *
1289 * change to DrawScore() so that when playing a computer, it will *
1290 * return "default_draw_score" under all circumstances rather than *
1291 * adjusting this downward, which makes Crafty accept positional *
1292 * weaknesses rather than repeat a position. *
1293 * *
1294 * 10.9 Evaluate() now handles king safety slightly differently, and *
1295 * increases the penalty for an exposed king quite a bit when there *
1296 * is lots of material present, but scales this increase down as the *
1297 * material comes off. This seems to help when attacking or getting *
1298 * attacked. Since Quiesce() no longer probes the hash table, the *
1299 * idea of storing static evaluations there became worthless and was *
1300 * burning cycles that were wasted. This has been removed. Check *
1301 * extensions relaxed slightly so that if ply is < iteration+10 it *
1302 * will allow the extension. Old limit was 2*iteration. Connected *
1303 * passed pawns on 6th now evaluated differently. They get a 1 pawn *
1304 * bonus, then if material is less than a queen, another 1 pawn *
1305 * bonus, and if not greater than a rook is left, and the king can't *
1306 * reach the queening square of either of the two pawns, 3 more *
1307 * more pawns are added in for the equivalent of + a rook. *
1308 * *
1309 * 10.10 Evaluate() modified. King safety was slightly broken, in that *
1310 * an uncastled king did not get a penalty for open center files. *
1311 * new evaluation term for controlling the "absolute 7th rank", a *
1312 * concept from "My System". *
1313 * *
1314 * 10.11 Lazy evaluation implemented. Now as the Evaluate() code is ex- *
1315 * ecuted, Crafty will "bail out" when it becomes obvious that the *
1316 * remainder of the evaluation can't bring the score back inside the *
1317 * alpha/beta window, saving time. *
1318 * *
1319 * 10.12 More Jakarta time control commands added so operator can set the *
1320 * time accurately if something crashes, and so the operator can set *
1321 * a "cushion" to compensate for operator inattention. "Easy" is *
1322 * more carefully qualified to be a recapture, or else a move that *
1323 * preserves the score, rather than one that appears to win material *
1324 * as was done in the past. King safety tweaked a little so that if *
1325 * one side gives up the right to castle, and could castle to a safe *
1326 * position, the penalty for giving up the right is substantially *
1327 * larger than before. A minor bug also made it more likely for *
1328 * black to give up the right to castle than for white. *
1329 * *
1330 * 10.13 Modifications to Book() so that when using "book random 0" mode *
1331 * (planned for Jakarta) and the search value indicates that we are *
1332 * losing a pawn, we return "out of book" to search *all* the moves, *
1333 * Not just the moves that are "in book." This hopefully avoids *
1334 * some book lines that lose (gambit) material unsoundly. *
1335 * *
1336 * 10.14 Final timing modifications. Puzzling/booking searches now take *
1337 * 1/30th of the normal time, rather than 1/10th. New command *
1338 * "mode=tournament" makes Crafty assess DRAW as "0" and also makes *
1339 * it prompt the operator for time corrections as required by WMCCC *
1340 * rules. *
1341 * *
1342 * 10.15 Evaluate() tuning to reduce development bonuses, which were able *
1343 * to overwhelm other scores and lead to poor positions. *
1344 * *
1345 * 10.16 "Lazy" (early exit) caused some problems in Evaluate() since so *
1346 * many scores are very large. Scaled this back significantly and *
1347 * also EvaluateOutsidePassedPawns() could double the score if one *
1348 * side had passers on both sides. This was fixed. *
1349 * *
1350 * 10.17 Crafty's Book() facility has been significantly modified to be *
1351 * more understandable. book random <n> has the following options: *
1352 * (0) do a search on set of book moves; (1) choose from moves that *
1353 * are played most frequently; (2) choose from moves with best win *
1354 * ratio; (3) choose from moves with best static evaluation; and *
1355 * (4) choose completely randomly. book width <n> can be used to *
1356 * control how large the "set" of moves will be, with the moves in *
1357 * the "set" being the best (according to the criteria chosen) from *
1358 * the known book moves. Minor tweak to Search() so that it extends *
1359 * passed pawn pushes to the 6th or 7th rank if the move is safe, *
1360 * and this is an endgame. *
1361 * *
1362 * 10.18 New annotate command produces a much nicer analysis file and also *
1363 * lets you exert control over what has to happen to trigger a com- *
1364 * ment among other things. AKA Crafty/Jakarta version. *
1365 * *
1366 * 11.1 Fractional depth allows fractional ply increments. The reso- *
1367 * lution is 1/4 of a ply, so all of the older "depth++" lines now *
1368 * read depth+=PLY, where #define PLY 4 is used everywhere. This *
1369 * gives added flexibility in that some things can increment the *
1370 * depth by < 1 ply, so that it takes two such things before the *
1371 * search actually extends one ply deeper. Crafty now has full PGN *
1372 * support. A series of pgn commands (pgn Event 14th WMCCC) allow *
1373 * the PGN tags to be defined, when Crafty reads or annotates a PGN *
1374 * file it reads and parses the headers and will display the info *
1375 * in the annotation (.can) file or in the file you specify when you *
1376 * execute a "savegame <filename>" command. *
1377 * *
1378 * 11.2 Fractional ply increments now implemented. 11.1 added the basic *
1379 * fractional ply extension capabilities, but this version now uses *
1380 * them in Search(). There are several fractional ply extensions *
1381 * being used, all are #defined in types.h to make playing with them *
1382 * somewhat easier. One advantage is that now all extensions are *
1383 * 3/4 of a ply, which means the first time any extension is hit, it *
1384 * has no effect, but the next three extensions will result in an *
1385 * additional ply, followed by another ply where the extension does *
1386 * nothing, followed by ... This allowed me to remove the limit on *
1387 * how deep in the tree the extensions were allowed, and also seems *
1388 * to not extend as much unless there's "something" going on. When *
1389 * the position gets interesting, these kick in. Asymmetric king *
1390 * safety is back in. Crafty's king safety is a little more im- *
1391 * portant than the opponent's now to help avoid getting its king- *
1392 * side shredded to win a pawn. A new term, ROOK_ON_7TH_WITH_PAWN *
1393 * to help Crafty understand how dangerous a rook on the 7th is if *
1394 * it is supported by a pawn. It is difficult to drive off and the *
1395 * pawn provides additional threats as well. *
1396 * *
1397 * 11.3 King safety modifications. One fairly serious bug is that Crafty *
1398 * considered that king safety became unimportant when the total *
1399 * pieces dropped below 16 material points. Note that this was *
1400 * pieces only, not pieces and pawns, which left plenty of material *
1401 * on the board to attack with. As a result, Crafty would often *
1402 * allow its king-side to be weakened because it was either in an *
1403 * endgame, or close to an endgame. *Incorrectly*, it turns out. :) *
1404 * Going back to a very old Crafty idea, king tropism is now tied to *
1405 * how exposed each king is, with pieces being attracted to the most *
1406 * exposed king for attack/defense. *
1407 * *
1408 * 11.4 Tuning on outside passed pawn code. Values were not large enough *
1409 * and didn't emphasize how strong such a pawn is. General passed *
1410 * pawn value increased as well. Minor bug in edit that would let *
1411 * Crafty flag in some wild games was fixed. Basically, edit has no *
1412 * way to know if castling is legal, and has to assume if a rook and *
1413 * king are on the original squares, castling is o.k. For wild2 *
1414 * games in particular, this can fail because castling is illegal *
1415 * (by the rules for wild 2) while it might be that rooks and king *
1416 * are randomly configured to make it look possible. Crafty would *
1417 * then try o-o or o-o-o and flag when the move was rejected as *
1418 * illegal. richard Lloyd suggested a speed-up for the annotate *
1419 * command which I'm using temporarily. Crafty now searches all *
1420 * legal moves in a position, and if the best move matches the game *
1421 * move, the second search of just the move played is not needed. I *
1422 * was searching just the game move first, which was a waste of time *
1423 * in many positions. I'll resume this later, because I want to see *
1424 * these values: (1) score for move actually played; (2) score for *
1425 * the rest of the moves only, not including the move actually *
1426 * played, to see how often a player finds a move that is the *only* *
1427 * good move in a position. *
1428 * *
1429 * 11.5 More fractional ply extension tuning. A few positions could blow *
1430 * up the search and go well beyond 63 plies, the max that Crafty *
1431 * can handle. Now, extensions are limited to no more than one ply *
1432 * of extensions for every ply of search. Note that "in check" is *
1433 * extended on the checking move ply, not on the out of check ply, *
1434 * so that one-reply-to-check still extends further. Minor changes *
1435 * to time.c to further help on long fast games. Another important *
1436 * timing bug repaired. If Crafty started an iteration, and failed *
1437 * high on the first move, it would not terminate the search until *
1438 * this move was resolved and a score returned. This could waste a *
1439 * lot of time in already won positions. Interesting bug in the *
1440 * capture search pruning fixed. At times, a piece would be hung, *
1441 * but the qsearch would refuse to try the capture because it would *
1442 * not bring the score back to above alpha. Unfortunately, taking *
1443 * the piece could let passed pawns race in undisturbed which would *
1444 * affect the score. This pruning is turned off when there are not *
1445 * at least two pieces left on the board. Another bug in the move *
1446 * generator produced pawn promotions twice, once when captures were *
1447 * generated, then again when the rest of the moves are produced. *
1448 * this was also repaired. Small book now will work. The Bookup() *
1449 * code now assumes white *and* black won in the absence of a valid *
1450 * PGN Result tag, so that the small book will work correctly. *
1451 * *
1452 * 11.6 Modifications to time allocation in a further attempt to make *
1453 * Crafty speed up if time gets short, to avoid flagging. It is now *
1454 * *very* difficult to flag this thing. :) Minor evaluation tweaks *
1455 * and a fix to Quiesce() to speed it up again after a couple of bad *
1456 * fixes slowed things down. *
1457 * *
1458 * 11.7 Minor modification to Evaluate(). Rooks behind a passed pawn are *
1459 * good, but two rooks behind the pawn don't help if the pawn is *
1460 * blockaded and can't move, unless the two rooks are not the same *
1461 * color as the pawn. *
1462 * *
1463 * 11.8 First stage of "book learning" implemented. Crafty monitors the *
1464 * search evaluation for the first 10 moves out of book. It then *
1465 * computes a "learn value" if it thinks this set of values shows *
1466 * that the book line played was very good or very bad. This value *
1467 * is added to a "learn count" for each move in the set of book *
1468 * moves it played, with the last move getting the full learn value, *
1469 * and moves closer to the start of the game getting a smaller *
1470 * percentage. (See learn.c for more details). These values are *
1471 * used by Book() to help in selecting/avoiding book lines. Crafty *
1472 * produces a "book.lrn" file that synthesizes this information into *
1473 * a portable format that will be used by other Crafty programs, *
1474 * once the necessary code is added later on. *
1475 * *
1476 * 11.9 An age-old problem caused by null-move searching was eliminated *
1477 * in this version. Often the null-move can cause a move to fail *
1478 * high when it should not, but then the move will fail low on the *
1479 * re-search when beta is relaxed. This would, on occasion, result *
1480 * in Crafty playing a bad move for no reason. Now, if a fail high *
1481 * is followed by a fail-low, the fail high condition is ignored. *
1482 * This can be wrong, but with null-move pruning, it can also be *
1483 * even "more wrong" to accept a fail high move after it fails low *
1484 * due to a null-move failure, than it would be right to accept the *
1485 * fail high/fail low that is caused by trans/ref table anomalies. *
1486 * *
1487 * 11.10 Crafty is now using the Kent, et. al, "razoring" algorithm, which *
1488 * simply eliminates the last ply of full-width searching and goes *
1489 * directly to the capture search if the move before the last full- *
1490 * width ply is uninteresting, and the Material eval is 1.5 pawns *
1491 * below alpha. It's a "modest futility" idea that doesn't give up *
1492 * on the uninteresting move, but only tries captures after the move *
1493 * is played in the tree. Net result is 20-30% average faster times *
1494 * to reach the same depth. Minor mod to book.lrn to include Black, *
1495 * White and Date PGN tags just for reference. Next learning mod is *
1496 * another "book random n" option, n=3. This will use the "learned" *
1497 * score to order book moves, *if* any of them are > 0. What this *
1498 * does is to encourage Crafty to follow opening lines that have *
1499 * been good, even if the learn count hasn't reached the current *
1500 * threshold of 1,000. This makes learning "activate" faster. This *
1501 * has one hole in it, in that once Crafty learns that one move has *
1502 * produced a positive learn value, it will keep playing that move *
1503 * (since no others will yet have a positive value) until it finally *
1504 * loses enough to take the learn value below zero. This will be *
1505 * taken care of in the next version, hopefully. *
1506 * *
1507 * 11.11 New "book random 4" mode that simply takes *all* learning scores *
1508 * for the set of legal book moves, translates them so that the *
1509 * worst value is +1 (by adding -Min(all_scores)+1 to every learn *
1510 * value) and then squaring the result. This encourages Crafty to *
1511 * follow book lines that it has learned to be good, while still *
1512 * letting it try openings that it has not yet tried (learn value *
1513 * =0) and even lets it try (albeit rarely) moves that it has *
1514 * learned to be bad. Minor evaluation tweaking for king placement *
1515 * in endgames to encourage penetration in the center rather than on *
1516 * a wing where the king might get too far from the "action." *
1517 * *
1518 * 11.12 LearnFunction() now keeps positional score, rather than using a *
1519 * constant value for scores < PAWN_VALUE, to improve learning *
1520 * accuracy. Book learn <filename> [clear] command implemented to *
1521 * import learning files from other Crafty programs. *
1522 * *
1523 * 11.13 Endgame threshold lowered to the other side having a queen or *
1524 * less (9) rather than (13) points. Queen+bishop can be very *
1525 * dangerous to the king for example, or two rooks and a bishop. *
1526 * Learning "curve" modified. It was accidentally left in a sort *
1527 * of "geometric" shape, with the last move getting the full learn *
1528 * value, the next one back getting 1/2, the next 1/3, etc. Now *
1529 * it is uniformly distributed from front to back. If there are 20 *
1530 * moves, the last gets the full value, the next gets 19/20, etc.. *
1531 * Also the "percentage played" was hosed and is fixed. *
1532 * *
1533 * 11.14 Minor modification to book learn 4 code so that when you start *
1534 * off with *no* learned data, Book() won't exclude moves from the *
1535 * possible set of opening moves just because one was not played *
1536 * very often. Due to the lack of "ordering" info in this case, it *
1537 * would often discover the second or third move in the list had not *
1538 * been played very often and cull the rest of the list thinking it *
1539 * was ordered by the number of times it was played. This code *
1540 * contains all of Frank's xboard patches so that analyze mode and *
1541 * so forth works cleanly. A new book random option <5> modifies *
1542 * the probability of playing a move by letting the popularity of a *
1543 * move affect the learned-value sorting algorithm somewhat. Minor *
1544 * adjustment in pawn ram asymmetric term to simply count rams and *
1545 * not be too concerned about which half of the board they are on. *
1546 * adjustment to weak pawn code. Also increased bonus for king *
1547 * tropism to attract pieces toward enemy king to improve attacking. *
1548 * code that detects drawn K+RP+wrong bishop had a bug in that on *
1549 * occasion, the defending king might not be able to reach the *
1550 * queening square before the opposing king blocks it out. This *
1551 * would let some positions look like draws when they were not. King *
1552 * safety now uses square(7-distance(piece,king)) as one multiplier *
1553 * to really encourage pieces to get closer to the king. In cases *
1554 * whre one king is exposed, all pieces are attracted to that king *
1555 * to attack or defend. This is turned off during the opening. *
1556 * minor 50-move rule draw change to fix a bug, in that the game is *
1557 * not necessarily a draw after 50 moves by both sides, because one *
1558 * side might be mated by the 50th move by the other side. This *
1559 * occurred in a game Crafty vs Ferret, and now works correctly. *
1560 * *
1561 * 11.15 Modified LearnBook() so that when Crafty terminates, or resigns, *
1562 * or sees a mate, it will force LearnBook() to execute the learning *
1563 * analysis even if 10 moves have not been made sine leaving the *
1564 * book. Crafty now trusts large positive evals less when learning *
1565 * about an opening, since such evals are often the result of the *
1566 * opponent's blunder, rather than a really good opening line. *
1567 * second learning stage implemented. Crafty maintains a permanent *
1568 * hash file that it uses to store positions where the search value *
1569 * (at the root of the tree) suddenly drop, and then it "seeds" the *
1570 * real transposition table with these values at the start of each *
1571 * of each search so that information is available earlier the next *
1572 * time this game is played. Position.bin has the raw binary data *
1573 * this uses, while position.lrn has the "importable" data. New *
1574 * import <filename> [clear] command imports all learning data now, *
1575 * eliminating the old book learn command. LearnFunction() modified *
1576 * to handle "trusted" values (negative scores, because we are sure *
1577 * that Crafty won't make an outright blunder very often) and *
1578 * "untrusted" values (positive values often caused by the opponent *
1579 * hanging a piece. Trusted values are scaled up if the opponent is *
1580 * weaker than Crafty since a weaker opponent forcing a negative *
1581 * eval means the position must really be bad, and are scaled down *
1582 * somewhat if the opponent is stronger than Crafty (from the rating *
1583 * information from ICC or the operator using the rating command.) *
1584 * Untrusted values are scaled down harshly, unless the opponent is *
1585 * much stronger than Crafty, since it is unlikely such an opponent *
1586 * would really blunder, while weaker opponents drastically scale *
1587 * untrusted value (which is positive, remember) down. minor depth *
1588 * problem fixed in learning code. The depth used in LearnFunction *
1589 * was not the depth for the search that produced the "learn value" *
1590 * the LearnBook() chooses, it was the depth for the search last *
1591 * done. Now, in addition to the 10 last search values, I store the *
1592 * depth for each as well. When a particular search value is used *
1593 * to "learn", the corresponding (correct) depth is also now used. *
1594 * These learn values are now limited to +6000/-6000 because in one *
1595 * book line, Crafty discovered it was getting mated in 2 moves at *
1596 * the end of the book line which was 30 moves deep. If you try to *
1597 * distribute a "mate score" as the learned value, it will instantly *
1598 * make every move for the last 26 moves look too bad to play. This *
1599 * is not desirable, rather the last few moves should be unplayable, *
1600 * but other moves further back should be o.k. Another bug that let *
1601 * Crafty overlook the above mate also fixed. The search value was *
1602 * not correct if Crafty got mated, which would avoid learning in *
1603 * that case. This has been fixed, although it was obviously a rare *
1604 * problem anyway. Minor draw bug fixed, where Crafty would offer *
1605 * a draw when time was way low, caused by the resolution change a *
1606 * few months back, and also it would offer a draw after the *
1607 * opponent moved, even if he made a blunder. It now only offers a *
1608 * draw after moving to make sure it's reasonable. Crafty now won't *
1609 * resign if there is a deep mate, such as a mate in 10+, because we *
1610 * want to be sure that the opponent can demonstrate making progress *
1611 * before we toss in the towel. LearnBook() now learns on all games *
1612 * played. The old algorithm had a serious problem in that negative *
1613 * scores were trusted fully, positive scores were treated with low *
1614 * confidence, and scores near zero were ignored totally. The net *
1615 * result was that learning values became more and more negative as *
1616 * games were played. Now equal positions are also factored in to *
1617 * the learning equation to help pull some of these negative values *
1618 * back up. Book() now excludes moves that have not been played *
1619 * many times (if there is at least one move that has) for book *
1620 * random = 2, 3 and 4. This stops some of the silly moves. *
1621 * position learning is turned off after 15 moves have passed since *
1622 * leaving book, to avoid learning things that won't be useful at a *
1623 * later time. Hashing changed slightly to include "permanent" *
1624 * entries so that the learned stuff can be copied into the hash *
1625 * table with some confidence that it will stay there long enough to *
1626 * be used. *
1627 * *
1628 * 11.16 King tropism toned down a little to not be quite so intent on *
1629 * closeness to the kings, so that other positional ideas don't get *
1630 * "lost" in the eval. Back to normal piece values (1,3,3,5,9) for *
1631 * a while. Optimizations in Quiesce() speeded things up about 2%. *
1632 * Pawns pushed toward the king are not so valuable any more so that *
1633 * Crafty won't prefer to hold on to them rather than trading to *
1634 * open a file(s) on the enemy king. BookLearn() call was moved in *
1635 * Resign() so that it first learns, then resigns, so that it won't *
1636 * get zapped by a SIGTERM right in the middle of learning when *
1637 * xboard realizes the game is over. Edit/setboard logic modified *
1638 * so that it is now possible to back up, and move forward in a game *
1639 * that was set up via these commands. *
1640 * *
1641 * 11.17 EvaluatePawns() modified to eliminate "loose pawn" penalty which *
1642 * was not particularly effective and produced pawn scores that were *
1643 * sometimes misleading. Several optimizations dealing with cache *
1644 * efficiency, primarily changing int's to signed char's so that *
1645 * multiple values fit into a cache line together, to eliminate some *
1646 * cache thrashing. PopCnt() no longer used to recognize that we *
1647 * have reached an endgame database, there's now a counter for the *
1648 * total number of pieces on the board, as it's much faster to inc *
1649 * and dec that value rather than count 1 bits. Tweaks to MakeMove *
1650 * and UnmakeMove to make things a couple of percent faster, but a *
1651 * whole lot cleaner. Ditto for SEE and Quiesce. More speed, and *
1652 * cleaner code. Outside passed pawn scored scaled down except when *
1653 * the opponent has no pieces at all. "Lazy eval" cleaned up. We *
1654 * now have two early exits, one before king safety and one after *
1655 * king safety. There are two saved values so we have an idea of *
1656 * how large the positional scores have gotten to make this work. *
1657 * Bug in passed pawn code was evaluating black passed pawns as less *
1658 * valuable than white. Fixed and passed pawn scores increased *
1659 * slightly. Isolated pawn scoring modified so the penalty is pro- *
1660 * portional to the number of isolani each side has, rather than the *
1661 * old approach of penalizing the "excess" isolani one side has over *
1662 * the other side. Seems to be more accurate, but we'll see. Fixed *
1663 * a rather gross bug in ValidateMove() related to the way castling *
1664 * status not only indicates whether castling is legal or not, but *
1665 * if it's not, whether that side castled or move the king/rooks. *
1666 * this let ValidateMove() fail to correctly detect that a castling *
1667 * move from the hash table might be invalid, which could wreck the *
1668 * search easily. This was an oversight from the new status code. *
1669 * Serious book bug fixed. Bookup() was not counting wins and *
1670 * losses correctly, a bug introduced to make small.pgn work. Minor *
1671 * bug in the "trapped bishop" (a2/h2/a7/h7) code fixed. Minor bug *
1672 * in SEE() also fixed (early exit that was not safe in rare cases.) *
1673 * *
1674 * 11.18 EvaluatePawns() modified to recognize that if there are two white *
1675 * pawns "rammed" by black pawns at (say) c4/c5 and e4/e5, then any *
1676 * pawns on the d-file are also effectively rammed as well since *
1677 * there is no hope for advancing it. Auto232 automatic play code *
1678 * seems to be working, finally. The problem was Crafty delayed *
1679 * echoing the move back to auto232, if the predicted move was the *
1680 * move played by the opponent. Auto232 gave Crafty 3 seconds and *
1681 * then said "too late, you must be hung." Outpost knight scoring *
1682 * modified to produce scores between 0 and .2 pawns. A knight was *
1683 * getting too valuable, which caused some confusion in the scoring. *
1684 * *
1685 * 11.19 Slight reduction in the value of passed pawns, as they were *
1686 * getting pretty large. Cleaned up annotate.c to get rid of code *
1687 * that didn't work out. Annotate now gives the PV for the move *
1688 * actually played as well as the move Crafty suggests is best. *
1689 * Crafty now has a reasonable "trade" bonus that kicks in when it *
1690 * has 20 points of material (or less) and is ahead or behind at *
1691 * least 2 pawns. This trade bonus ranges from 0 to 1000 (one pawn) *
1692 * and encourages the side that is winning to trade, while the side *
1693 * that is losing is encouraged to avoid trades. More minor tweaks *
1694 * for auto232 including trying a delay of 100ms before sending *
1695 * a move. New annotate command gives the option to get more than *
1696 * one suggested best move displayed, as well as fixes a few bugs *
1697 * in the older code. Fix to bishop + wrong rook pawn code to also *
1698 * recognize the RP + no pieces is just as bad if the king can reach *
1699 * the queening square first. *
1700 * *
1701 * 11.20 Cleanup to annotate command. It now won't predict that one side *
1702 * will follow a book line that only resulted in losses. Also a *
1703 * couple of glitches in annotate where it was possible for a move *
1704 * to take an exhorbitant amount of time if the best move was a *
1705 * book move, but there were no other possible book moves. The *
1706 * trade bonus now includes trade pawns if behind, but not if ahead *
1707 * as well as now considering being ahead or behind only one pawn *
1708 * rather than the two pawns used previously in 11.19. *
1709 * *
1710 * 11.21 Additional bug fix in annotate command that would fail if there *
1711 * was only one legal move to search. Passed pawn values now have *
1712 * an added evaluation component based on material on the board, so *
1713 * that they become more valuable as material is traded. *
1714 * *
1715 * 11.22 Test command modified. Test <filename> [N] (where N is optional *
1716 * and defaults to 99) will terminate a test position after N con- *
1717 * secutive iterations have had the correct solution. Bug in *
1718 * Quiesce() fixed, which would incorrectly prune (or fail to prune) *
1719 * some captures, due to using "Material" which is computed with *
1720 * respect to white-to-move. This was fixed many versions ago, but *
1721 * the fix was somehow lost. Fix to EvaluateDraws that mistakenly *
1722 * declared some endings drawn when there were rookpawns on both *
1723 * sides of the board, and the king could get in front of one. Minor *
1724 * fix to Repeat() that was checking one too many entries. No *
1725 * harmful effect other than one extra iteration in the loop that *
1726 * would make "purify/purity" fail as well as slow things down 1% or *
1727 * so. *
1728 * *
1729 * 11.23 logpath=, bookpath= and tbpath= command line options added to *
1730 * direct logs, books and tb files to the indicated path. These *
1731 * only work as command line options, and can't be used in normal *
1732 * places since the files are already opened and in use. A bug in *
1733 * Evaluate() would call EvaluatePawns() when there were no pawns, *
1734 * breaking things on many systems. *
1735 * *
1736 * 12.0 Rewrite of Input/Output routines. Crafty no longer relies on the *
1737 * C library buffered I/O routine scanf() for input. This made it *
1738 * basically impossible to determine when to read data from the key- *
1739 * board, which made xboard/winboard difficult to interface with. *
1740 * Now Crafty does its own I/O using read(), which is actually much *
1741 * cleaner and easier. Minor bug where a fail high in very short *
1742 * time controls might not get played... *
1743 * *
1744 * 12.1 Clean-up of Main(). The code had gotten so obtuse with the *
1745 * pondering call, plus handling Option() plus move input, that it *
1746 * was nearly impossible to follow. It is now *much* cleaner and *
1747 * easier to understand/follow. *
1748 * *
1749 * 12.2 Continued cleanup of I/O, particularly the way main() is *
1750 * structured, to make it more understandable. Rewritten time.c *
1751 * to make it more readable and understandable, not to mention *
1752 * easier to modify. Fixed a timing problem where Crafty could be *
1753 * pondering, and the predicted move is made followed immediately by *
1754 * "force", caused when the opponent makes a move and loses on time, *
1755 * or makes a move and resigns. This would leave the engine state *
1756 * somewhat confused, and would result in the "new" command not *
1757 * reinitializing things at all, which would hang Crafty on xboard *
1758 * or winboard. *
1759 * *
1760 * 12.3 Modified piece values somewhat to increase their worth relative *
1761 * to a pawn, to try to stop the tendency to sac a piece for 3 pawns *
1762 * and get into trouble for doing so. Minor fixes in NewGame() that *
1763 * caused odd problems, such as learning positions after 1. e4. The *
1764 * position.lrn/.bin files were growing faster than they should. *
1765 * Other minor tweaks to fix a few broken commands in Option(). *
1766 * Slight reduction in trade bonus to match slightly less valuable *
1767 * pawns. *
1768 * *
1769 * 12.4 Added ABSearch() macro, which makes Search() much easier to read *
1770 * by doing the test to call Search() or Quiesce() in the macro *
1771 * where it is hidden from sight. Bugs in the way the log files *
1772 * were closed and then used caused crashed with log=off. *
1773 * *
1774 * 12.5 Development bonus for central pawns added to combat the h4/a3 *
1775 * sort of openings that would get Crafty into trouble. It now will *
1776 * try to seize the center if the opponent dallies around. *
1777 * *
1778 * 12.6 Bug in EvaluateDraws() that would erroneously decide that a KNP *
1779 * vs K was drawn if the pawn was a rook pawn and the king could get *
1780 * in front of it, which was wrong. Another minor bug would use *
1781 * EvaluateMate() when only a simple exchange ahead, which would *
1782 * result in sometimes giving up a pawn to reach such a position. *
1783 * Minor bug in SetBoard() would incorrectly reset many important *
1784 * game state variables if the initial position was set to anything *
1785 * other than the normal starting position, such as wild 7. This *
1786 * would make learning add odd PV's to the .lrn file. Development *
1787 * bonus modified to penalize moving the queen before minor pieces, *
1788 * and not moving minor pieces at all. It is now possible to build *
1789 * a "wild 7" book, by first typing "wild 7", and then typing the *
1790 * normal book create command. Crafty will remember to reset to the *
1791 * "wild 7" position at the start of each book line. Note that it *
1792 * is not possible to have both wild 7 book lines *and* regular book *
1793 * lines in the same book. *
1794 * *
1795 * 12.7 Failsoft added, so that scores can now be returned outside the *
1796 * alpha/beta window. Minor null-move threat detection added where *
1797 * a mate in 1 score, returned by a null-move search, causes a one *
1798 * ply search extension, since a mate in one is a serious threat. *
1799 * razoring is now disabled if there is *any* sort of extension in *
1800 * the search preceeding the point where razoring would be applied, *
1801 * to avoid razoring taking away one ply from a search that was ex- *
1802 * tended (for good reasons) earlier. Fail-soft discarded, due to *
1803 * no advantages at all, and a slight slowdown in speed. Rewrite of *
1804 * pawn hashing, plus a rewrite of the weak pawn scoring code to *
1805 * make it significantly more accurate, while going a little slower *
1806 * (but since hashing hits 99% of the time, the slower speed is not *
1807 * noticable at all.) Evaluation tweaking as well. *
1808 * *
1809 * 12.8 Continued work on weak pawn analysis, as well as a few minor *
1810 * changes to clean the code up. *
1811 * *
1812 * 13.0 Preparation for the Paris WMCCC version starts here. First new *
1813 * thing is the blocked pawn evaluation code. This recognizes when *
1814 * a pawn is immobolized and when a pawn has lever potential, but *
1815 * is disabled if playing a computer opponent. Passed pawn scoring *
1816 * modified to eliminate duplicate bonuses that were added in *
1817 * EvaluatePawns as well as EvaluatePassedPawns. Trade bonus code *
1818 * rewritten to reflect trades made based on the material when the *
1819 * search begins. This means that some things have to be cleared in *
1820 * the hash table after a capture is really made on the board, but *
1821 * prevents the eval from looking so odd near the end of a game. *
1822 * minor bug with book random 0 fixed. If there was only one book *
1823 * move, the search could blow up. *
1824 * *
1825 * 13.1 All positional scores reduced by 1/4, in an attempt to balance *
1826 * things a little better. Also more modifications to the weak and *
1827 * blocked pawn code. Added evaluation code to help with KRP vs KR, *
1828 * so that the pawn won't be advanced too far before the king comes *
1829 * to its aid. Ditto for defending, it knows that once the king is *
1830 * in front of the pawn, it is a draw. *
1831 * *
1832 * 13.2 Blocked pawn scoring changed slightly to not check too far to see *
1833 * if a pawn can advance. Also pawns on center squares are weighted *
1834 * more heavily to encourage keeping them there, or trying to get *
1835 * rid of them if the opponent has some there. Discovered that *
1836 * somehow, the two lines of code that add in bonuses for passed *
1837 * pawns were deleted as I cleaned up and moved code around. These *
1838 * were reinserted (missing from 13.0 on). *
1839 * *
1840 * 13.3 Modified tablebase code to support 5 piece endings. There is now *
1841 * a configuration option (see Makefile) to specify 3, 4 or 5 piece *
1842 * endgame databases. More evaluation tuning. *
1843 * *
1844 * 13.4 Modified null-move search. If there is more than a rook left for *
1845 * the side on move, null is always tried, as before. If there is *
1846 * a rook or less left, the null move is only tried within 5 plies *
1847 * of the leaf positions, so that as the search progresses deeper, *
1848 * null-move errors are at least moved away from the root. Many *
1849 * evaluation changes, particularly to king safety and evaluating *
1850 * castling to one side while the other side is safer. Also it now *
1851 * handles pre-castled positions better. *
1852 * *
1853 * 13.5 "From-to" display patch from Jason added. This shows the from *
1854 * and to squares on a small diagram, oriented to whether Crafty is *
1855 * playing black or white. The intent is to minimize operator *
1856 * errors when playing black and the board coordinates are reversed. *
1857 * More eval changes. *
1858 * *
1859 * 13.6 Weak pawns on open files now add value to the opponent's rooks *
1860 * since they are the pieces that will primarily use an open file to *
1861 * attack a weak pawn. *
1862 * *
1863 * 13.7 Minor eval tweaks, plus fixes for the CR/LF file reading problems *
1864 * in windows NT. *
1865 * *
1866 * 13.8 Adjustments to book.c, primarily preventing Crafty from playing *
1867 * lines that had very few games in the file, because those are *
1868 * often quite weak players. Minor fix to InputMoves() so that a *
1869 * move like bxc3 can *never* be interpreted as a bishop move. A *
1870 * bishop move must use an uppercase B, as in Bxc3. Bug in the *
1871 * king safety for white only was not checking for open opponent *
1872 * files on the king correctly. *
1873 * *
1874 * 13.9 Minor adjustment to time allocation to allow "operator time" to *
1875 * affect time per move. This is set by "operator <n>" where <n> is *
1876 * time in seconds per move that should be "reserved" to allow the *
1877 * operator some typing/bookkeeping time. New command "book *
1878 * trigger <n>" added so that in tournament mode, when choosing a *
1879 * book line, Crafty will revert to book random 0 if the least *
1880 * popular move was played fewer times than <n>. This is an attempt *
1881 * to avoid trusting narrow book lines too much while still allowing *
1882 * adequate randomness. If the least frequently played move in the *
1883 * set of book moves was played fewer times than this, then a search *
1884 * over all the book moves is done. If the best one doesn't look *
1885 * so hot, Crafty drops out of book and searches *all* legal moves *
1886 * instead. *
1887 * *
1888 * 13.10 Minor adjustments. This is the gold Paris version that is going *
1889 * with Jason. Any changes made during the event will be included *
1890 * in the next version. *
1891 * *
1892 * 14.0 Major eval modification to return to centipawn evaluation, rather *
1893 * then millipawns. This reduces the resolution, but makes it a lot *
1894 * easier to understand evaluation changes. Significant eval mods *
1895 * regarding king safety and large positional bonuses, where the ad- *
1896 * vantage is not pretty solid. Note that old book learning will *
1897 * not work now, since the evals are wrong. Old position learning *
1898 * must be deleted completely. See the read.me file for details on *
1899 * what must be done about book learning results. New egtb=n option *
1900 * to replace the older -DTABLEBASES=n Makefile option, so that the *
1901 * tablebases can be enabled or disabled without recompiling. *
1902 * *
1903 * 14.1 Glitch in EvaluateDevelopment() was producing some grossly large *
1904 * positional scores. Also there were problems with where the *
1905 * PreEvaluate() procedure were called, so that it could be called *
1906 * *after* doing RootMoveslist(), but before starting a search. This*
1907 * caused minor problems with hashing scores. One case was that it *
1908 * was possible for a "test suite" to produce slightly different *
1909 * scores than the same position run in normal mode. This has been *
1910 * corrected. St=n command now supports fractional times to .01 *
1911 * second resolution. *
1912 * *
1913 * 14.2 MATE reduced to 32768, which makes all scores now fit into 16 *
1914 * bits. Added code to EvaluatePawns() to detect the Stonewall *
1915 * pawn formation and not like it as black. Also it detects a *
1916 * reversed Stonewall formation (for black) and doesn't like it as *
1917 * white. EvaluateOutsidePassedPawns() removed. Functionality is *
1918 * incorporated in EvaluatePawns() and is hashed, which speeds the *
1919 * evaluation up a bit. King safety is now fully symmetric and is *
1920 * folded into individual piece scoring to encourage pieces to *
1921 * attack an unsafe king. *
1922 * *
1923 * 14.3 Minor adjustments to the king safety code for detecting attacks *
1924 * initiated by pushing kingside pawns. Flip/flop commands added to *
1925 * mirror the board either horizontally or vertically to check for *
1926 * symmetry bugs in the evaluation. Other eval tuning changes. *
1927 * *
1928 * 14.4 Queen value increased to stop trading queen for two rooks. Book *
1929 * learning slightly modified to react quicker. Also scores are now *
1930 * stored in the book file as floats to get rid of an annoying trun- *
1931 * cation problem that was dragging scores toward zero. The book *
1932 * file now has a "version" so that old book versions won't cause *
1933 * problems due to incorrect formats. Null-move mated threat ex- *
1934 * tension was modified. If null-move search fails high, I fail *
1935 * high as always, if it fails low, and it says I get mated in N *
1936 * moves, I extend all moves at this ply, since something is going *
1937 * on. I also carry this threat extension into the hash table since *
1938 * a hash entry can say "don't do null move, it will fail low." I *
1939 * now have a flag that says not only will null-move fail low, it *
1940 * fails to "mated in N" so this ply needs extending even without a *
1941 * null-move search to tell it so. Book learning greatly modified *
1942 * in the way it "distributes" the learned values, in an effort to *
1943 * make learning happen faster. I now construct a sort of "tree" *
1944 * so I know how many book alternatives Crafty had at each move it *
1945 * at each book move it played. I then assign the whole learn value *
1946 * to all moves below the last book move where there was a choice, *
1947 * and also assign the whole learn value to the move where there *
1948 * was a choice. I then divide the learn value by the number of *
1949 * choices and assign this to each book move (working backward once *
1950 * again) until the next point where there were choices. This makes *
1951 * sure that if there is a choice, and it is bad, it won't be played *
1952 * again, even if this choice was at move 2, and the remainder of *
1953 * the book line was completely forced. All in an effort to learn *
1954 * more quickly. *
1955 * *
1956 * 14.5 annotate bug fixed where if there was only one legal move, the *
1957 * annotation would stop with no warning. Bookup() now produces a *
1958 * more useful error message, giving the exact line number in the *
1959 * input file where the error occurred, to make fixing them easier. *
1960 * If you are playing without a book.bin, 14.4 would crash in the *
1961 * book learning code. This is now caught and avoided. Bookup() *
1962 * now knows how to skip analysis in PGN files, so you can use such *
1963 * files to create your opening book, without having problems. It *
1964 * understands that nesting () {} characters "hides" the stuff in- *
1965 * side them, as well as accepting non-standard PGN comments that *
1966 * are inside []. Annotate() now will annotate a PGN file with *
1967 * multiple games, although it will use the same options for all of *
1968 * the games. PGN headers are preserved in the .can file. Annotate *
1969 * now will recognize the first move in a comment (move) or {move} *
1970 * and will search that move and give analysis for it in addition to *
1971 * the normal output. *
1972 * *
1973 * 14.6 Minor change to book random 4 (use learned value.) if all the *
1974 * learned values are 0, then use the book random 3 option instead. *
1975 * Bug in 50-move counter fixed. Learn() could cause this to be set *
1976 * to a value that didn't really reflect the 50-move status, and *
1977 * cause games to be drawn when they should not be. Modified the *
1978 * "Mercilous" attack code to recognize a new variation he worked *
1979 * out that sacrifices a N, R and B for a mating attack. No more. *
1980 * *
1981 * 14.7 "Verbose" command removed and replaced by a new "display" command *
1982 * that sets display options. Use "help display" for more info on *
1983 * how this works. The "mercilous" attack scoring is only turned on *
1984 * when playing "mercilous". But there is a new "special" list that *
1985 * you can add players too if you want, and this special scoring is *
1986 * turned on for them as well. *
1987 * *
1988 * 14.8 New scoring term to penalize unbalanced trades. IE if Crafty has *
1989 * to lose a pawn, it would often trade a knight for two pawns in- *
1990 * stead, which is actually worse. This new term prevents this sort *
1991 * of trades. *
1992 * *
1993 * 14.9 "Mercilous" attack code modified to handle a new wrinkle he (and *
1994 * one other player) found. *
1995 * *
1996 * 14.10 New "bench" command runs a test and gives a benchmark comparison *
1997 * for Crafty and compares this to a P6/200 base machine. Minor bug *
1998 * disabled the "dynamic draw score" and fixed it at zero, even if *
1999 * the opponent was much weaker (rating) or behind on time. Also *
2000 * draw_score was not reset to 0 at start of each new game, possibly *
2001 * leaving it at +.20 after playing a higher-rated opponent. *
2002 * *
2003 * 14.11 Release to make mercilous attack detection code the default, to *
2004 * prevent the rash of mercilous attacks on the chess servers. *
2005 * *
2006 * 14.12 Modified tuning of evaluation. Scores were reduced in the past, *
2007 * to discourage the piece for two pawns sort of trades, but since *
2008 * this was basically solved in 14.8, scores are going "back up". *
2009 * Particularly passed pawn scores. Crafty now accepts draw offers *
2010 * if the last search result was <= the current result returned by *
2011 * DrawScore(). It also honors draw requests via xboard when *
2012 * against a human opponent as well, and will flag the game as over. *
2013 * Minor modification to annotate.c to display move numbers in the *
2014 * PV's to match the PV output format used everywhere else in *
2015 * Crafty. A new type of learning, based on results, has been added *
2016 * and is optional (learn=7 now enables every type of learning.) *
2017 * this type of learning uses the win/lose game result to flag an *
2018 * opening that leads to a lost game as "never" play again. The *
2019 * book move selection logic has been modified. There are four com- *
2020 * ponents used in choosing book moves: frequency of play; win/lose *
2021 * ratio; static evaluation; and learned score. There are four *
2022 * weights that can be modified with the bookw command, that control *
2023 * how these 4 values are used to choose book moves. Each weight is *
2024 * a floating point value between 0 and 1, and controls how much the *
2025 * corresponding term factors in to move selection. *
2026 * *
2027 * 14.13 Fixed a book parsing bug that now requires a [Site "xxx"] tag in *
2028 * any book file between lines for the "minplay" option of book *
2029 * create to work properly. *
2030 * *
2031 * 15.0 This is the first version to support a parallel search using *
2032 * multiple processors on a shared-memory machinel. This version *
2033 * uses the "PVS" algorithm (Principal Variation Search) that is an *
2034 * early form of "Young Brothers Wait". This is not the final *
2035 * search algorithm that will be used, but it is relatively easy to *
2036 * implement, so that the massive data structure changes can be de- *
2037 * bugged before getting too fancy. The major performance problem *
2038 * with this approach is that all processors work together at a node *
2039 * and when one finishes, it has to wait until all others finish *
2040 * before it can start doing anything more. This adds up to a *
2041 * significant amount of time and really prevents good speedups on *
2042 * multiprocessor machines. This restriction will be eliminanted in *
2043 * future versions, but it makes debugging much simpler for the *
2044 * first version. After much agonizing, I finally chose to write my *
2045 * own "spinlock" macros to avoid using the pthread_mutex_lock stuff *
2046 * that is terribly inefficient due to its trying to be cute and *
2047 * yield the processor rather than spinning, when the lock is al- *
2048 * ready set. i'd rather spin than context-switch. *
2049 * *
2050 * 15.1 This version actually unleashes the full design of the parallel *
2051 * search, which lets threads split away from the "pack" when *
2052 * they become idle, and they may then jump in and help another *
2053 * busy thread. This eliminates the significant delays that *
2054 * occur near the end of a search at a given ply. Now as those pro- *
2055 * cessors drop out of the search at that ply, they are reused at *
2056 * other locations in the tree without any significant delays. *
2057 * *
2058 * 15.2 WinNT support added. Also fixed a small bug in Interrupt() that *
2059 * could let it exit with "busy" set so that it would ignore all *
2060 * input from that point forward, hanging the game up. Added a new *
2061 * "draw accept" and "draw decline" option to enable/disable Crafty *
2062 * accepting draw offers if it is even or behind. Turned on by *
2063 * an IM/GM opponent automatically. Thread pools now being used to *
2064 * avoid the overhead of creating/destroying threads at a high rate *
2065 * rate of speed. It is now quite easy to keep N processors busy. *
2066 * *
2067 * 15.3 CPU time accounting modified to correctly measure the actual time *
2068 * spent in a parallel search, as well as to modify the way Crafty *
2069 * handles time management in an SMP environment. A couple of bugs *
2070 * fixed in book.c, affecting which moves were played. Also veri- *
2071 * fied that this version will play any ! move in books.bin, even if *
2072 * it was not played in the games used to build the main book.bin *
2073 * file. *
2074 * *
2075 * 15.4 This version will terminate threads once the root position is in *
2076 * a database, to avoid burning cpu cycles that are not useful. A *
2077 * flag "done" is part of each thread block now. When a thread goes *
2078 * to select another move to search, and there are no more left, it *
2079 * sets "done" in the parent task thread block so that no other pro- *
2080 * cessors will attempt to "join the party" at that block since no *
2081 * work remains to be done. Book selection logic modified so that *
2082 * frequency data is "squared" to improve probabilities. Also, the *
2083 * frequency data is used to cull moves, in that if a move was not *
2084 * played 1/10th of the number of times that the "most popular" move *
2085 * was played, then that move is eliminated from consideration. *
2086 * *
2087 * 15.5 Changes to "volatile" variables to enhance compiler optimization *
2088 * in places where it is safe. Added a function ThreadStop() that *
2089 * works better at stopping threads when a fail high condition *
2090 * occurs at any nodes. It always stopped all sibling threads at *
2091 * the node in question, but failed to stop threads that might be *
2092 * working somewhere below the fail-high node. ThreadStop() will *
2093 * recursively call itself to stop all of those threads. Significant *
2094 * increase in king centralization (endgame) scoring to encourage *
2095 * the king to come out and fight rather than stay back and get *
2096 * squeezed to death. Minor change to queen/king tropism to only *
2097 * conside the file distance, not ranks also. Bug in interrupt.c *
2098 * fixed. This bug would, on very rare occasion, let Crafty read in *
2099 * a move, but another thread could read on top of this and lose the *
2100 * move. Xboard would then watch the game end with a <flag>. *
2101 * *
2102 * 15.6 Ugly repetition draw bug (SMP only) fixed. I carefully copied *
2103 * the repetition list from parent to child, but also copied the *
2104 * repetition list pointer... which remained pointing at the parent *
2105 * repetition list. Which failed, of course. *
2106 * *
2107 * 15.7 Problem in passing PV's back up the search fixed. The old bug of *
2108 * a fail high/fail low was not completely handled, so that if the *
2109 * *last* move on a search failed high, then low, the PV could be *
2110 * broken or wrong, causing Crafty to make the wrong move, or else *
2111 * break something when the bogus PV was used. Piece/square tables *
2112 * now only have the _w version initialized in data.c, to eliminate *
2113 * the second copy which often caused errors. Initialize() now will *
2114 * copy the _w tables to the _b tables (reflected of course.) *
2115 * *
2116 * 15.8 trade bonus modified to not kick in until one side is two pawns *
2117 * ahead or behind, so that trading toward a draw is not so common. *
2118 * Fixed a whisper bug that would cause Crafty to whisper nonsense *
2119 * if it left book, then got back in book. It also now whispers the *
2120 * book move it played, rather than the move it would play if the *
2121 * opponent played the expected book move, which was confusing. *
2122 * *
2123 * 15.9 Bug in positions with one legal move would abort the search after *
2124 * a 4 ply search, as it should, but it was possible that the result *
2125 * from the aborted search could be "kept" which would often make *
2126 * Crafty just "sit and wait" and flag on a chess server. *
2127 * *
2128 * 15.10 Fixed "draw" command to reject draw offers if opponent has < ten *
2129 * seconds left and no increment is being used. Fixed glitch in *
2130 * LearnResult() that would crash Crafty if no book was being used, *
2131 * and it decides to resign. Modified trade bonus code to eliminate *
2132 * a hashing inconsistency. Minor glitch in "show thinking" would *
2133 * show bad value if score was mate. Added Tim Mann's new xboard/ *
2134 * winboard "result" command and modified the output from Crafty to *
2135 * tell xboard when a game is over, using the new result format that *
2136 * Tim now expects. Note that this is xboard 3.6.9, and earlier *
2137 * versions will *not* work correctly (ok on servers, but not when *
2138 * you play yourself) as the game won't end correctly due to the *
2139 * change in game-end message format between the engine and xboard. *
2140 * *
2141 * 15.11 Modified SMP code to not start a parallel search at a node until *
2142 * "N" (N=2 at present) moves have been search. N was 1, and when *
2143 * move ordering breaks down the size of the tree gets larger. This *
2144 * controls that much better. Fixed an ugly learning bug. If the *
2145 * last move actually in the game history was legal for the other *
2146 * side, after playing it for the correct side, it could be played *
2147 * a second time, which would break things after learning was done. *
2148 * An example was Rxd4 for white, where black can respond with Rxd4. *
2149 * Changes for the new 3.6.10 xboard/winboard are also included as *
2150 * well as a fix to get book moves displayed in analysis window as *
2151 * it used to be done. *
2152 * *
2153 * 15.12 "The" SMP repetition bug was finally found and fixed. CopyToSMP *
2154 * was setting the thread-specific rephead_* variable *wrong* which *
2155 * broke so many things it was not funny. Evaluation tuning in this *
2156 * version as well to try to "center" values in a range of -X to +X *
2157 * rather than 0 to 2X. Trade bonus had a bug in the pawn part that *
2158 * not only encouraged trading pawns when it should be doing the *
2159 * opposite, but the way it was written actually made it look bad to *
2160 * win a pawn. More minor xboard/winboard compatibility bugs fixed *
2161 * so that games end when they should. DrawScore() had a quirk that *
2162 * caused some problems, in that it didn't know what to do with non- *
2163 * zero draw scores, and could return a value with the wrong sign at *
2164 * times. It is now passed a flag, "Crafty_is_white" to fix this. *
2165 * Modification so that Crafty can handle the "FEN" PGN tag and set *
2166 * the board to the correct position when it is found. Xboard *
2167 * options "hard" and "easy" now enable and disable pondering. *
2168 * *
2169 * 15.13 Modification to "bad trade" code to avoid any sort of unbalanced *
2170 * trades, like knight/bishop for 2-3 pawns, or two pieces for a *
2171 * rook and pawn. More new xboard/winboard fixes for Illegal move *
2172 * messages and other engine interface changes made recently. Minor *
2173 * change to null move search, to always search with the alpha/beta *
2174 * window of (beta-1,beta) rather than (alpha,beta), which is very *
2175 * slightly more efficient. *
2176 * *
2177 * 15.14 Rewrite of ReadPGN() to correctly handle nesting of various sorts *
2178 * of comments. This will now correctly parse wall.pgn, except for *
2179 * promotion moves with no promotion piece specified. The book *
2180 * create code also now correctly reports when you run out of disk *
2181 * space and this should work under any system to let you know when *
2182 * you run out of space. *
2183 * *
2184 * 15.15 Major modifications to Book() and Bookup(). Bookup() now needs *
2185 * 1/2 the temp space to build a book that it used to need (even *
2186 * less under windows). Also, a book position is now 16 bytes in- *
2187 * stead of 20 (or 24 under windows) further reducing the space *
2188 * requirements. The "win/lose/draw" counts are no longer absolute, *
2189 * rather they are relative so they can be stored in one byte. A new *
2190 * method for setting "!" moves in books.bin is included in this *
2191 * version. For any move in the input file used to make books.bin, *
2192 * you can add a {play nn%} string, which says to play this move nn% *
2193 * of the time, regardless of how frequently it was played in the *
2194 * big book file. For example, e4 {play 50%} says to play e4 50% of *
2195 * the time. Note two things here: (1) If the percentages for all *
2196 * of white's first moves add up to a number > 100, then the *
2197 * percentage played is taken as is, but all will be treated as if *
2198 * they sum to 100 (ie if there are three first moves, each with a *
2199 * percentage of 50%, they will behave as though they are all 33% *
2200 * moves). (2) For any moves not marked with a % (assuming at least *
2201 * one move *is* marked with a percent) then such moves will use the *
2202 * remaining percentage left over applied to them equally. Note that *
2203 * using the % *and* the ! flags together slightly changes things, *
2204 * because normally only the set of ! moves will be considered, and *
2205 * within that set, any with % specified will have that percent used *
2206 * as expected. But if you have some moves with !, then a percent *
2207 * on any of the *other* moves won't do a thing, because only the ! *
2208 * moves will be included in the set to choose from. *
2209 * *
2210 * 15.16 Bug in the king tropism code, particularly for white pieces that *
2211 * want to be close to the black king, fixed in this version. New *
2212 * History() function that handles all history/killer cases, rather *
2213 * than the old 2-function approach. Ugly Repeat() bug fixed in *
2214 * CopyToChild(). This was not copying the complete replist due to *
2215 * a ply>>2 rather than ply>>1 counter. *
2216 * *
2217 * 15.17 Adjustments to "aggressiveness" to slightly tone it down. Minor *
2218 * fix to avoid the odd case of whispering one move and playing an- *
2219 * other, caused by a fail-high/fail-low overwriting the pv[1] stuff *
2220 * and then Iterate() printing that rather than pv[0] which is the *
2221 * correct one. New LegalMove() function that strengthens the test *
2222 * for legality at the root, so that it is impossible to ponder a *
2223 * move that looks legal, but isn't. Modifications to king safety *
2224 * to better handle half-open files around the king as well as open *
2225 * files. EGTB "swindler" added. If the position is drawn at the *
2226 * root of the tree, then all losing moves are excluded from the *
2227 * move list and the remainder are searched normally with the EGTB *
2228 * databases disabled, in an effort to give the opponent a chance to *
2229 * go wrong and lose. Fixed "mode tournament" and "book random 0" *
2230 * so that they will work correctly with xboard/winboard, and can *
2231 * even be used to play bullet games on a server if desired. Minor *
2232 * fix to attempt to work around a non-standard I/O problem on the *
2233 * Macintosh platform dealing with '\r' as a record terminator *
2234 * rather than the industry/POSIX-standard \n terminator character. *
2235 * *
2236 * 15.18 Fix to the "material balance" evaluation term so that it will not *
2237 * like two pieces for a rook (plus pawn) nor will it like trading a *
2238 * piece for multiple pawns. A rather gross bug in the repetition *
2239 * code (dealing with 50 move rule) could overwrite random places in *
2240 * memory when the 50 move rule approached, because the arrays were *
2241 * not long enough to hold 50 moves, plus allow the search to go *
2242 * beyond the 50-move rule (which is legal and optional) and then *
2243 * output moves (which uses ply=65 data structures). This let the *
2244 * repetition (50-move-rule part) overwrite things by storing well *
2245 * beyond the end of the repetition list for either side. Minor fix *
2246 * to EGTB "swindle" code. It now only tries the searches if it is *
2247 * the side with swindling chances. Ie it is pointless to try for *
2248 * a swindle in KRP vs KR if you don't have the P. :) Some very *
2249 * substantial changes to evaluate.c to get things back into some *
2250 * form of synch with each other. *
2251 * *
2252 * 15.19 More evaluation changes. Slight change to the Lock() facility *
2253 * as it is used to lock the hash table. Modifications to the book *
2254 * selection logic so that any move in books.bin that is not in the *
2255 * regular book.bin file still can be played, and will be played if *
2256 * it has a {play xxx%} or ! option. New option added to the book *
2257 * create command to allow the creation of a better book. This *
2258 * option lets you specify a percentage that says "exclude a book *
2259 * move it if didn't win xx% as many games as it lost. IE, if the *
2260 * book move has 100 losses, and you use 50% for the new option, the *
2261 * move will only be included if there are at least 50 wins. This *
2262 * allows culling lines that only lost, for example. New bad trade *
2263 * scoring that is simpler. If one side has one extra minor piece *
2264 * and major pieces are equal, the other side has traded a minor for *
2265 * pawns and made a mistake. If major pieces are not matched, and *
2266 * one side has two or more extra minors, we have seen either a rook *
2267 * for two minor pieces (bad) or a queen for three minor pieces (bad *
2268 * also). Horrible bug in initializing min_thread_depth, which is *
2269 * supposed to control thrashing. The SMP search won't split the *
2270 * tree within "min_thread_depth" of the leaf positions. Due to a *
2271 * gross bug, however, this was initialized to "2", and would have *
2272 * been the right value except that a ply in Crafty is 4. The *
2273 * mtmin command that adjusts this correctly multiplied it by 4, *
2274 * but in data.c, it was left at "2" which lets the search split way *
2275 * too deeply and can cause thrashing. It now correctly defaults to *
2276 * 120 (2*PLY) as planned. Crafty now *only* supports *
2277 * winboard/xboard 4.0 or higher, by sending the string "move xxx" *
2278 * to indicate its move. This was done to eliminate older xboard *
2279 * versions that had some incompatibilities with Crafty that were *
2280 * causing lots of questions/problems. Xboard 4.0 works perfectly *
2281 * and is the only recommended GUI now. *
2282 * *
2283 * 15.20 New evaluation term to ensure that pawns are put on squares of *
2284 * the opposite color as the bishop in endings where one side only *
2285 * has a single bishop. Another new evaluation term to favor *
2286 * bishops over knights in endings with pawns on both sides of the *
2287 * board. Search extensions now constrained so that when doing an *
2288 * N-ply search, the first 2N plies can extend normally, but beyond *
2289 * that the extensions are reduced by one-half. This eliminates a *
2290 * few tree explosions that wasted lots of time but didn't produce *
2291 * any useful results. This version solves 299/300 of the Win at *
2292 * Chess positions on a single-cpu pentium pro 200mhz machine now. *
2293 * New evaluation term to reward "pawn duos" (two pawns side by side *
2294 * which gives them the most flexibility in advancing. A change to *
2295 * the bishops of opposite color to not just consider B vs B drawish *
2296 * when the B's are on opposite colors, but to also consider other *
2297 * positons like RB vs RB drawish with opposite B's. *
2298 * *
2299 * 16.0 Hash functions renamed to ProbeTransRef() and StoreTransRef(). *
2300 * The store functions (2) were combined to eliminate some duplicate *
2301 * code and shrink the cache footprint a bit. Adjustment to "losing *
2302 * the right to castle" so that the penalty is much less if this is *
2303 * done when trading queens, since a king in the center becomes less *
2304 * of a problem there. Several eval tweaks. Support for Eugene *
2305 * Nalimov's new endgame databases that reduce the size by 50%. *
2306 * Added a new cache=xxx command to set the tablebase cache (more *
2307 * memory means less I/O of course). The "egtb" command now has two *
2308 * uses. If you enter egtb=0, you can disable tablebases for *
2309 * testing. Otherwise, you just add "egtb" to your command line or *
2310 * .craftyrc file and Crafty automatically recognizes the files that *
2311 * are present and sets up to probe them properly. Added an eval *
2312 * term to catch a closed position with pawns at e4/d3/c4 and then *
2313 * avoiding the temptation to castle into an attack. Most of the *
2314 * evaluation discontinuities have been removed, using the two new *
2315 * macros ScaleToMaterial() and InverseScaleToMaterial(). Scale() *
2316 * is used to reduce scores as material is removed from the board, *
2317 * while InverseScale() is used to increase the score as material *
2318 * is removed. This removed a few ugly effects of things happening *
2319 * right around the EG_MAT threshold. *
2320 * *
2321 * 16.1 Bug in EGTBProbe() which used the wrong variable to access the *
2322 * enpassant target square was fixed. The cache=x command now *
2323 * checks for a failed malloc() and reverts to the default cache *
2324 * size to avoid crashes. Major eval tuning changes. Cache bug *
2325 * would do an extra malloc() and if it is done after the "egtb" *
2326 * command it would crash. Analyze mode now turns off the "swindle" *
2327 * mode. *
2328 * *
2329 * 16.2 More evaluation changes, specifically to bring king safety down *
2330 * to reasonable levels. Support for the DGT electronic chess board *
2331 * is now included (but only works in text mode, not in conjunction *
2332 * with xboard/winboard yet. Fix to StoreTransRef() that corrected *
2333 * a problem with moving an entry from tablea to tableb, but to the *
2334 * wrong address 50% of the time (thanks to J. Wesley Cleveland). *
2335 * *
2336 * 16.3 Performance tweaks plus a few evaluation changes. An oversight *
2337 * would let Crafty play a move like exd5 when cxd5 was playable. *
2338 * IE it didn't follow the general rule "capture toward the center." *
2339 * this has been fixed. King safety ramped up just a bit. *
2340 * *
2341 * 16.4 Search extension fixed. One-reply was being triggered when there *
2342 * was only one capture to look at as well, which was wrong. Minor *
2343 * fix to king safety in Evaluate(). Adjustments to preeval to fix *
2344 * some "space" problems caused by not wanting to advance pawns at *
2345 * all, plus some piece/square pawn values that were too large near *
2346 * the opponent's king position. New swindle on*off command allows *
2347 * the user to disable "swindle mode" so that Crafty will report *
2348 * tablebase draws as draws. Swindle mode is now disabled auto- *
2349 * matically in analysis or annotate modes. DrawScore() now returns *
2350 * a draw score that is not nearly so negative when playing humans. *
2351 * The score was a bit large (-.66 and -.33) so that this could tend *
2352 * to force Crafty into losing rather than drawn positions at times. *
2353 * EGTB probe code now monitors how the probes are affecting the nps *
2354 * and modifies the probe depth to control this. IE it adjusts the *
2355 * max depth of probes to attempt to keep the NPS at around 50% or *
2356 * thereabouts of the nominal NPS rate. Fixed a nasty bug in the *
2357 * EGTB 'throttle' code. It was possible that the EGTB_mindepth *
2358 * could get set to something more than 4 plies, then the next *
2359 * search starts off already in a tablebase ending, but with this *
2360 * probe limit, it wouldn't probe yet Iterate() would terminate the *
2361 * search after a couple of plies. And the move chosen could draw. *
2362 * New code submitted by George Barrett, which adds a new command *
2363 * "html on". Using this will cause the annotate command to produce *
2364 * a game.html file (rather than game.can) which includes nice board *
2365 * displays (bitmapped images) everywhere Crafty suggests a *
2366 * different move. You will need to download the bitmaps directory *
2367 * files to make this work. Note that html on enables this or you *
2368 * will get normal annotation output in the .can file. Final *
2369 * hashing changes made. Now crafty has only two hash tables, the *
2370 * 'depth preferred' and 'always store' tables, but not one for each *
2371 * side. *
2372 * *
2373 * 16.5 Minor glitch in internal iterative deepening code (in search.c) *
2374 * could sometimes produce an invalid move. Crafty now probes the *
2375 * hash table to find the best move which works in all cases. *
2376 * Interesting tablebase bug fixed. By probing at ply=2, the *
2377 * search could overlook a repetition/50 move draw, and turn a won *
2378 * position into a draw. Crafty now only probes at ply > 2, to *
2379 * let the Repeat() function have a chance. Added code by Dan *
2380 * Corbitt to add environment variables for the tablebases, books, *
2381 * logfiles and the .craftyrc file paths. The environment variables *
2382 * CRAFTY_TB_PATH, CRAFTY_BOOK_PATH, CRAFTY_LOG_PATH and *
2383 * CRAFTY_RC_PATH should point to where these files are located and *
2384 * offer an alternative to specifying them on the command line. *
2385 * Final version of the EGTB code is included in this version. This *
2386 * allows Crafty to use either compressed (using Andrew Kadatch's *
2387 * compressor, _not_ zip or gzip) or non-compressed tablebases. It *
2388 * will use non-compressed files when available, and will also use *
2389 * compressed files that are available so long as there is no non- *
2390 * compressed version of the same file. It is allowable to mix and *
2391 * match as you see fit, but with all of the files compressed, the *
2392 * savings is tremendous, roughly a factor of 5 in space reduction. *
2393 * *
2394 * 16.6 Major rewrite of king-safety pawn shelter code to emphasize open *
2395 * files (and half-open files) moreso than just pawns that have been *
2396 * moved. Dynamic EGTB probe depth removed. This caused far too *
2397 * many search inconsistencies. A fairly serious SMP bug that could *
2398 * produce a few hash glitches was found. Rewrite of the 'king- *
2399 * tropism' code completed. Now the pieces that are 'crowding' the *
2400 * king get a bigger bonus if there are more of them. Ie it is more *
2401 * than twice as good if we have two pieces close to the king, while *
2402 * before this was purely 'linear'. Minor fix to book.c to cure an *
2403 * annotate command bug that would produce odd output in multi-game *
2404 * PGN files. *
2405 * *
2406 * 16.7 Minor bug in 'book create' command would produce wrong line num- *
2407 * bers if you used two book create commands without restarting *
2408 * Crafty between uses. Replaced "ls" command with a !cmd shell *
2409 * escape to allow _any_ command to be executed by a shell. Change *
2410 * to bishop scoring to avoid a bonus for a bishop pair _and_ a good *
2411 * bishop sitting at g2/g7/etc to fill a pawn hole. If the bishop *
2412 * fills that hole, the bishop pair score is reduced by 1/2 to avoid *
2413 * scores getting too large. Another ugly SMP bug fixed. It was *
2414 * for the CopyFromSMP() function to fail because Search() put the *
2415 * _wrong_ value into tree->value. The "don't castle into an unsafe *
2416 * king position" code was scaled up a bit as it wasn't quite up to *
2417 * detecting all cases of this problem. The parallel search has *
2418 * been modified so that it can now split the tree at the root, as *
2419 * well as at deeper nodes. This has improved the parallel search *
2420 * efficiency noticably while also making the code a bit more *
2421 * complex. This uses an an adaptive algorithm that pays close *
2422 * attention to the node count for each root move. If one (or more) *
2423 * moves below the best move have high node counts (indicating that *
2424 * these moves might become new 'best' moves) then these moves are *
2425 * flagged as "don't search in parallel" so that all such moves are *
2426 * searched one by one, using all processors so that a new best move *
2427 * if found faster. Positional scores were scaled back 50% and the *
2428 * king safety code was again modified to incorporate pawn storms, *
2429 * which was intentionally ignored in the last major revision. Many *
2430 * other scoring terms have been modified as well to attempt to *
2431 * bring the scores back closer to something reasonable. *
2432 * *
2433 * 16.8 Bug in evaluate.c (improper editing) broke the scoring for white *
2434 * rooks on open files (among other things.) New twist on null- *
2435 * move search... Crafty now uses R=3 near the root of the tree, *
2436 * and R=2 near the top. It also uses null-move so long as there is *
2437 * a single piece on the board, but when material drops to a rook or *
2438 * less, null move is turned off and only used in the last 7 plies *
2439 * to push the zugzwang errors far enough off that they can be *
2440 * avoided, hopefully. *
2441 * *
2442 * 16.9 Tuning to king safety. King in center of board was way too high *
2443 * which made the bonus for castling way too big. More fine-tuning *
2444 * on the new 'tropism' code (that tries to coordinate piece attacks *
2445 * on the king). It understands closeness and (now) open files for *
2446 * the rooks/queens. Modified blocked center pawn code so that an *
2447 * 'outpost' in front of an unmoved D/E pawn is made even stronger *
2448 * since it restrains that pawn and cramps the opponent. *
2449 * *
2450 * 16.10 All scores are back to 16.6 values except for king safety, as *
2451 * these values played well. King safety is quite a bit different *
2452 * and now has two fine-tuning paramaters that can be set in the *
2453 * crafty.rc file (try help ksafety for more details, or see the new *
2454 * crafty.doc for more details. Suffice it to say that you can now *
2455 * tune it to be aggressive or passive as you wish. *
2456 * *
2457 * 16.11 Adjustment to king safety asymmetry to make Crafty a bit more *
2458 * cautious about starting a king-side attack. New "ksafe tropism" *
2459 * command allows the tropism scores (pulling pieces toward opponent *
2460 * king) to be adjusted up or down (up is more aggressive). *
2461 * *
2462 * 16.12 evaluation adjustment options changed. The new command to modify *
2463 * this stuff is "evaluation option value". For example, to change *
2464 * the asymmetry scoring for king safety, you now use "evaluation *
2465 * asymmetry 120". See "help evaluation" for more details. There *
2466 * is a new "bscale" option to adjust the scores for 'blocked' type *
2467 * positions, and I added a new "blockers_list" so that players that *
2468 * continually try to lock things up to get easy draws can be better *
2469 * handled automatically. The command is "list B +name". There are *
2470 * other adjustable evaluation scaling parameters now (again, use *
2471 * "help evaluation" to see the options.) *
2472 * *
2473 * 16.13 Bug in Evaluate() fixed. King safety could produce impossibly *
2474 * large scores due to negative subscript values. Minor change to *
2475 * root.c to allow partial tablebase sets while avoiding the ugly *
2476 * potential draw problem. This was supplied by Tim Hoooebeek and *
2477 * seems to work ok for those wanting to have files like kpk with- *
2478 * out the corresponding promotion files. *
2479 * *
2480 * 16.14 Bug in Evaluate() fixed. King safety could produce impossibly *
2481 * large scores due to a subscript two (2) larger than expected for *
2482 * max values. A couple of other minor tweaks to rook on 7th as *
2483 * well. Setboard now validates enpassant target square to be sure *
2484 * that an enpassant capture is physically possible, and that the *
2485 * target square is on the right rank with pawns in the right place. *
2486 * *
2487 * 16.15 Bug in EGTBProbe() usage fixed. It was possible to call this *
2488 * function before tablebases were initialized, or when there were *
2489 * more than 3 pieces on one side, which would break a subscript. *
2490 * *
2491 * 16.16 Changes to the way EvaluatePassedPawn() works. It now does a *
2492 * reasonable job of penalizing blockaded passed pawns. Also a bug *
2493 * in king scoring used a variable set from the previous call to the *
2494 * Evaluate() procedure, which could produce bizarre effects. A few *
2495 * minor eval glitches that caused asymmetric scores unintentionally *
2496 * were removed. *
2497 * *
2498 * 16.17 Minor "hole" in SMP code fixed. It was possible that a move *
2499 * displayed as the best in Output() would not get played. *
2500 * Very subtle timing issue dealing with the search timing out and *
2501 * forgetting to copy the best move back to the right data area. *
2502 * Minor fixes to the modified -USE_ATTACK_FUNCTIONS option that *
2503 * was broken when the And()/Or()/ShiftX() macros were replaced by *
2504 * their direct bitwise operator replacements. *
2505 * *
2506 * 16.18 Adjustments to king tropism scoring terms (these attract pieces *
2507 * toward the opponent king in a coordinated way). The scoring term *
2508 * that kept the queen from going to the opposite side of the board *
2509 * was not working well which would also cause attacking problems. *
2510 * Razoring code has been disabled, as it neither helps or hurts on *
2511 * tactical tests, and it creates a few hashing problems that are *
2512 * annoying. Bug in StoreTransRefPV() that would store the PV into *
2513 * the hash table, but possibly in the wrong table entry, which *
2514 * could stuff a bad move in a hash entry, or overwrite a key entry *
2515 * that could have been useful later. Book random 0 was slightly *
2516 * wrong as it could not ignore book moves if the search said that *
2517 * the score was bad. Also the search would not time-out properly *
2518 * on a forced move, it would use the entire time alotted which was *
2519 * a big waste of time when there was only one legal move to make. *
2520 * A very interesting bug was found in storing mate bounds in the *
2521 * hash table, one I had not heard of before. Another change to *
2522 * Iterate() to make it avoid exiting as soon as a mate is found, so *
2523 * that it can find the shortest mate possible. *
2524 * *
2525 * 16.19 Savepos now pads each rank to 8 characters so that programs that *
2526 * don't handle abbreviated FEN will be able to parse Crafty's FEN *
2527 * output without problems. Threads are no longer started and *
2528 * stopped before after searches that seem to not need multiple *
2529 * threads (such as when the starting position is in the databases *
2530 * or whatever) because in fast games, it can start and stop them *
2531 * after each search, due to puzzling for a ponder move, and this is *
2532 * simply to inefficient to deal with, and burning the extra cpus is *
2533 * only bad if the machine is used for other purposes. And when the *
2534 * machine is not dedicated to chess only, the SMP search is very *
2535 * poor anyway. New lockless hashing (written by Tim Mann) added *
2536 * to improve SMP performance. New eval term that handles various *
2537 * types of candidate passed pawns, most commonly the result of a *
2538 * position where one side has an offside majority that later turns *
2539 * into an outside passed pawn. New EGTBPV() procedure added. This *
2540 * code will print the entire PV of a tablebase mating line. If it *
2541 * given an option of ! (command is "egtb !") it will add a ! to any *
2542 * move where there is only one optimal choice. Crafty will now *
2543 * automatically display the EGTB PV if you give it a setboard FEN *
2544 * command, or if you just give it a raw FEN string (the setboard *
2545 * command is now optional except in test suites). This version now *
2546 * supports the 6 piece database files. To include this support, *
2547 * you need to -DEGTB6 when compiling everything. The majority code *
2548 * has been temporarily removed so that this version can be released *
2549 * to get the 6 piece ending stuff out. *
2550 * *
2551 * 17.0 Connected passed pawn scoring modified so that connected passers *
2552 * don't get any sort of bonus, except for those cases where the *
2553 * opponent has a rook or more. This will avoid liking positions *
2554 * where Crafty has two connected passers on the d/e files, and the *
2555 * opponent has passers on the b/g files. The split passers win if *
2556 * all pieces are traded, while the connected passers are better *
2557 * when pieces are present. A new scoring term evaluates the *
2558 * "split" passers similar to outside passers, this at the request *
2559 * (make that demand) of GM Roman Dzindzichashvili. Book() now finds *
2560 * the most popular move as the move to ponder. This eliminated all *
2561 * 'puzzling' searches which result in clearing the hash tables two *
2562 * times for every book move, which can slow it down when a large *
2563 * hash table is used. New book option for playing against computer *
2564 * opponents was written for this version. Crafty now supports two *
2565 * "books.bin" type files, books.bin and bookc.bin (the bookc create *
2566 * command can be used to make bookc.bin). Bookc will only be used *
2567 * when Crafty is playing a computer. This is supplied by xboard or *
2568 * winboard when playing on a server, or can be included int the *
2569 * crafty.rc/.craftyrc file when playing directly. Bookc.bin will *
2570 * be used when playing a computer only, and should be used to avoid *
2571 * unsound lines that are fine against humans, but not against other *
2572 * computers. If you don't use a bookc.bin, it will use the normal *
2573 * books.bin as always. If you use both, it will only use bookc.bin *
2574 * in games that have been started and then given the 'computer' *
2575 * command. Minor adjustment to EGTB probe code so that it will *
2576 * always probe TBs at ply=2 (if the right number of pieces are on *
2577 * the board) but won't probe beyond ply=2 unless the move at the *
2578 * previous ply was a capture/promotion and the total pieces drops *
2579 * into the proper range for TB probes. This makes the 6 piece *
2580 * files far more efficient as before it would continuously probe *
2581 * after reaching 6 piece endings, even if it didn't have the right *
2582 * file. now after the capture that takes us to a 6 piece ending *
2583 * we probe one time... and if there is no hit we don't probe at *
2584 * the next node (or any successors) unless there is another capture *
2585 * or promotion that might take us to a database we have. The book *
2586 * (binary) format has once again been modified, meaning that to use *
2587 * 16.20 and beyond the book.bin/books.bin files must be re-built *
2588 * from the raw PGN input. This new format includes an entry for *
2589 * the CAP project score, so that deep searches can be used to guide *
2590 * opening book lines. A new weight (bookw CAP) controls how much *
2591 * this affects book move ordering/selection. A new import command *
2592 * will take the raw CAPS data and merge it into the book.bin after *
2593 * the file has been built. Serious bug in SetBoard() would leave *
2594 * old EP status set in test suites. This has been fixed. Outpost *
2595 * knight code was modified so that a knight in a hole is good, a *
2596 * knight in a hole supported by a pawn is better, supported by two *
2597 * pawns is still better, and if the opponent has no knights or a *
2598 * bishop that can attack this knight it is even better. The out- *
2599 * post bonus for a bishop was removed. A pretty serious parallel *
2600 * search bug surfaced. In non-parallel searches, Crafty _always_ *
2601 * completed the current ply=1 move after the time limit is reached, *
2602 * just to be sure that this move isn't going to become a new best *
2603 * move. However, when parallel searching, this was broken, and at *
2604 * the moment time runs out, the search would be stopped if the *
2605 * parallel split was done at the root of the tree, which means that *
2606 * where the search would normally find a new best move, it would *
2607 * not. This has been fixed. New "store <val>" command can be used *
2608 * to make "position learning" remember the current position and the *
2609 * score (val) you supply. This is useful in analyze mode to move *
2610 * into the game, then let Crafty know that the current position is *
2611 * either lost or won (with a specific score). *
2612 * *
2613 * 17.1 Book structure fixed, since compilers can't quite agree on how *
2614 * structures ought to be aligned, for reasons not clear to me. A *
2615 * serious eval bug that could produce gross scores when one side *
2616 * had two queens was fixed. *
2617 * *
2618 * 17.2 Isolated pawn scoring tweaked a bit, plus a couple of bugs in the *
2619 * way EvaluateDevelopment() was called were fixed. *
2620 * *
2621 * 17.3 Passed pawn scores increased somewhat to improve endgame play. *
2622 * *
2623 * 17.4 Minor bug with "black" command (extra line from unknown origin) *
2624 * would make "black" command fail to do anything. Minor tweaks to *
2625 * passed pawn scoring again... And a slight performance improve- *
2626 * ment in how EvaluateKingSafety() is called. Code for "bk" *
2627 * from xboard was somehow lost. It now provides a book hint. *
2628 * *
2629 * 17.5 Rewrite of outside passed pawn/pawn majority code. It is now *
2630 * much faster by using pre-computed bitmaps to recognize the right *
2631 * patterns. *
2632 * *
2633 * 17.6 Minor fix in interrupt.c, which screwed up handling some commands *
2634 * while pondering. Minor fix to score for weak back rank. Score *
2635 * was in units of 'defects' but should have been in units of *
2636 * "centipawns". Minor bug in "drawn.c" could mis-classify some *
2637 * positions as drawn when they were not. *
2638 * *
2639 * 17.7 Repair to DrawScore() logic to stop the occasional backward sign *
2640 * that could create some funny-looking scores (-20 and +20 for *
2641 * example). Minor fix to majority code to recognize the advantage *
2642 * of having a majority when the opponent has no passers or majority *
2643 * even if the candidate in the majority is not an 'outside' passer *
2644 * candidate. Minor change to passed pawns so that a protected *
2645 * passed pawn is not considered a winning advantage if the *
2646 * opponent has two or more passed pawns. But in input_status *
2647 * would cause an infinite loop if you reset a game to a position *
2648 * that was in book, after searching a position that was not in *
2649 * the book. Bug in position learning fixed also. This was caused *
2650 * by the new hashing scheme Tim Mann introduced to avoid locking *
2651 * the hash table. I completed the changes he suggested, but forgot *
2652 * about how it might affect the position learning since it is also *
2653 * hash-based. Needless to say, I broke it quite nicely, thank you. *
2654 * *
2655 * 17.8 This is the version used in the first ICC computer chess *
2656 * tournament. Crafty won with a score of 7.0/8.0 which included *
2657 * only 2 draws and no losses. Changes are minimal except for a few *
2658 * non-engine syntax changes to eliminate warnings and fix a bad bug *
2659 * in 'bench.c' that would crash if there was no books.bin file. *
2660 * *
2661 * 17.9 LearnPosition() called with wrong arguments from main() which *
2662 * effectively disabled position learning. This was broken in 17.7 *
2663 * but is now fixed. *
2664 * *
2665 * 17.10 Minor change to "threat" extension now only extends if the null- *
2666 * move search returns "mated in 1" and not "mated in N". This *
2667 * tends to shrink the trees a bit with no noticable effect in *
2668 * tactical strength. EvaluatePawns() was not doing a reasonable *
2669 * job of recognizing blocked pawns and candidate passers. It did *
2670 * not do well in recognizing that the pawn supporting a candidate *
2671 * could not advance far enough to help make a real passed pawn. *
2672 * Minor change to Repeat() to not count two-fold repeats as draws *
2673 * in the first two plies, which prevents some odd-looking repeats *
2674 * at the expense of a little inefficiency. Ugly repetition bug *
2675 * fixed. Rephead was off by one for whatever side Crafty was *
2676 * playing which would screw up repetition detection in some cases. *
2677 * Minor bug in main() that would report stalemate on some mates *
2678 * when the ponder score was forgotten. *
2679 * *
2680 * 17.11 Fail high/low logic changed to move the ++ output into Iterate() *
2681 * where the -- output was already located. (This was done for *
2682 * consistecy only, it was not a problem. New function to detect *
2683 * draws RepetitionCheckBook() was added to count two-fold repeats *
2684 * as draws while in book. This lets Crafty search to see if it *
2685 * wants tht draw or not, rather than just repeating blindly. Minor *
2686 * bug in "go"/"move" command fixed. The command did not work if *
2687 * the engine was pondering. Minor change to Evaluate() that makes *
2688 * BAD_TRADE code more acurate. Minor change to pawn majority code *
2689 * to fix two bugs. White pawns on g2/h2 with black pawn on h7 was *
2690 * not seen as a majority (outside candidate passer) but moving the *
2691 * black pawn to g7 made it work fine. Also if both sides had an *
2692 * equal number of pawns (black pawn at a7/b7, white pawns at b2/c2 *
2693 * the code would not notice black had an outside passer candidate *
2694 * since pawns were 'equal' in number. *
2695 * *
2696 * 17.12 Bookup() will now create a book with all sorts of games in it, so *
2697 * long as the various games have the FEN string to properly set the *
2698 * initial chess board position. *
2699 * *
2700 * 17.13 Endgame evaluation problem fixed. King scoring now dynamically *
2701 * chooses the right piece/square table depending on which side of *
2702 * the board has pawns, rather than using root pre-processing which *
2703 * could make some gross errors. Glitch with majorities would make *
2704 * an "inside majority candidate" offset a real outside passed pawn *
2705 * even if the candidate would not be outside. A suggestion by *
2706 * Blass Uri (CCC) was added. This adds .01 to tablebase scores if *
2707 * the side on move is ahead in material, and -.01 if the side on *
2708 * move is behind in material (only for drawn positions.) the *
2709 * intent is to favor positions where you are ahead in material *
2710 * rather than even in material, which gives 'swindle mode' a chance *
2711 * to work. Bug in EvaluateDraws() would mis-categorize some B+RP *
2712 * (wrong bishop) as drawn, even if the losing king could not make *
2713 * it to the corner square in time. *
2714 * *
2715 * 17.14 Another endgame evaluation problem fixed. The outside passed *
2716 * pawn code worked well, up until the point the pawn had to be *
2717 * given up to decoy the other side's king away from the remainder *
2718 * of the pawns. Crafty now understands the king being closer to *
2719 * the pawns than the enemy king, and therefore transitions from *
2720 * outside passer to won king-pawn ending much cleaner. New command *
2721 * "selective" as requested by S. Lim, which allows the user to *
2722 * set the min/max null move R values (default=2/3). They can be *
2723 * set to 0 which disables null-move totally, or they can be set *
2724 * larger than the default for testing. Minor changes to init.c *
2725 * sent by Eugene Nalimov to handle 64 bit pointer declarations for *
2726 * win64 executable compilation. NetBSD changes included along with *
2727 * a new Makefile that requires no editing to use for any known *
2728 * configuration ("make help" will explain how to use it). This was *
2729 * submitted by Johnny Lam. Serious changes to the outside passed *
2730 * pawn code. The evaluator now understands that outside passers *
2731 * on _both_ sides of the board is basically winning. Same goes for *
2732 * candidate passers. *
2733 * *
2734 * 18.0 Bug in EvaluateDraws() could incorrectly decide that if one side *
2735 * had only rook pawns in a king/pawn ending, the ending was a draw. *
2736 * Even if the other side had pawns all over the board. Passed pawn *
2737 * scores increased a bit. Minor change to "bad trade" code to turn *
2738 * off in endings. S list removed. The trojan horse check is now *
2739 * automatically enabled when the key position is recognized at the *
2740 * root of the tree. It is disabled once the key position is no *
2741 * longer seen at the root. Bug in Bookup() would break if a FEN *
2742 * string was included in a game used for input. SetBoard() was *
2743 * setting castling status incorrectly. Internal iterative *
2744 * deepening bug could (on very rare occasions) cause Crafty to try *
2745 * to search an illegal move that would bomb the search. This *
2746 * version fully supports the new xboard protocol version 2. One *
2747 * other major change is that the eval is now consistently displayed *
2748 * as +=good for white, -=good for black. In the log file. In the *
2749 * console output window. And when whispering/kibitzing on a chess *
2750 * server. This should eliminate _all_ confusion about the values *
2751 * that are displayed as there are now no exceptions to the above *
2752 * policy of any kind. Book() was changed so that if it notices *
2753 * that the opponent has a "stonewall pattern" set up (IE Crafty *
2754 * is black, has a pawn at e7 or e6, and the opponent has pawns at *
2755 * d4/f4) then it won't play a castle move from book. It will do a *
2756 * normal search instead and let the evaluation guide it on whether *
2757 * to castle or not (generally it won't unless it is forced). *
2758 * *
2759 * 18.1 Easy move code broken, so that no move ever appeared to be "easy" *
2760 * even if it was the only possible recapture move to make. A minor *
2761 * problem in analysis mode dealing with pawn promotions was fixed. *
2762 * It was possible for a move like h8=Q to be rejected even though *
2763 * it was perfectly legal. *
2764 * *
2765 * 18.2 Minor bug in analyze mode would break the "h" command when black *
2766 * was on move, and show one less move for either side that had *
2767 * actually been played in the game. Another bug also reversed the *
2768 * sign of a score whispered in analysis mode. Recapture extension *
2769 * is disabled by default. To turn it on, it is necessary to use *
2770 * -DRECAPTURE when compiling search.c and option.c. LearnBook() *
2771 * has been modified to 'speed up' learning. See the comments in *
2772 * that module to see how it was changed. LearnResult() has been *
2773 * removed. LearnBook() is now used to do the same thing, except *
2774 * that a good (or bad) score is used. *
2775 * *
2776 * 18.3 Minor bug in "avoid_null_move" test used R=2 for the test rather *
2777 * than testing R=2/3 as the real null-move search uses. The kibitz *
2778 * for "Hello from Crafty Vx.xx" has been moved so that it works *
2779 * with the new xboard/winboard 4.2.2 versions. Book learning was *
2780 * badly broken in the previous version and has been fixed/tested. *
2781 * *
2782 * 18.4 Recapture extension was left in SearchParallel() by mistake. *
2783 * This has now been protected by a #ifdef just like it was in *
2784 * Search(). Bug in Repeat() was causing problems in SMP versions. *
2785 * The entire repetition list code was modified to clean this up. *
2786 * The problem was most noticable on things like fine #70. Bug in *
2787 * LearnImportBook() confused the learn value sign, due to the other *
2788 * changes to make +=white all the time. Opposite bishop scoring *
2789 * has been beefed up a bit to avoid these drawish endings. *
2790 * *
2791 * 18.5 Minor change to RootMove() to use Quiesce() rather than the more *
2792 * complicated way it was ordering with Evaluate()/EnPrise(). This *
2793 * is no faster, but it is simpler and eliminated the need for the *
2794 * EnPrise() function totally, making the code a bit smaller. Bug *
2795 * in EvaluateDraws() would let it think that the bishop+wrong rook *
2796 * pawn endings were winnable if both kings were very close to the *
2797 * queening square, even with the wrong bishop. *
2798 * *
2799 * 18.6 "New" no longer produces a new log.nnn/game.nnn file if no moves *
2800 * have actually been played. Minor change to rook scoring gives a *
2801 * penalty when a rook has no horizontal (rank) mobility, to avoid *
2802 * moves like Ra2 protecting the pawn on b2, etc. Glitch in the *
2803 * code that initializes is_outside[][] and is_outside_c[][] could *
2804 * cause missed outside pawn cases to happen. This has been there *
2805 * a long time. *
2806 * *
2807 * 18.7 BOOK_CLUSTER_SIZE increased to 2000 to handle making really large *
2808 * books. A book made without this change could produce clusters *
2809 * that would cause memory overwrites. *
2810 * *
2811 * 18.8 Recapture extension turned back on for a while. Changes to the *
2812 * evaluation code, particularly EvaluatePawns() to make it more *
2813 * efficient and accurate. IE it was possible for an isolated pawn *
2814 * to be penalized for being isolated, weak, and blocked, which made *
2815 * little sense. *
2816 * *
2817 * 18.9 Book() modified to increase the responsiveness of book learning. *
2818 * The new code, plus the default weights for the book parameters *
2819 * now make Crafty learn very aggressively and repeat good opening *
2820 * lines and avoid bad ones. *
2821 * *
2822 * 18.10 Minor bug in book.c would let Crafty play lines that were very *
2823 * rarely played even though there were others that had been played *
2824 * far more times and were more reliable. King safety scores ramped *
2825 * up a bit and made more "responsive". *
2826 * *
2827 * 18.11 Minor bug in EvaluateDevelopment() found by Bruce Moreland. The *
2828 * pawn ram code is now disabled when playing a computer, although *
2829 * the normal 'blocked pawn' code is always active. Bug in the code *
2830 * that penalizes a rook with no horizontal mobility was fixed. If *
2831 * the first rook scored had horizontal mobility, the second rook *
2832 * appeared to have this mobility as well, which was wrong. Pawn *
2833 * hash statistics were wrong on longer searches due to an int *
2834 * overflow on a multiply and divide calculation. This has been *
2835 * re-ordered to avoid the overflow. For unknown reasons, epd *
2836 * support was disabled. It is now enabled as it should be. Some *
2837 * strange adjustements to root_alpha/root_beta were removed from *
2838 * searchr.c. They were probably left-over from some sort of test. *
2839 * *
2840 * 18.12 Bug in EvaluateDraws() fixed to not call KBB vs KN a draw if the *
2841 * correct tablebase is not available. Bishop pair scores now vary *
2842 * depending on how many pawns are left on the board. A pair is not *
2843 * worth a lot if there are 7-8 pawns left as most diagonals will be *
2844 * blocked by pawns. Test() modified so that it will now run using *
2845 * an EPD test suite with am/bm and id tags. The old testfile for- *
2846 * mat will continue to work for a while, but Test() now notices the *
2847 * EPD format and processes it correctly. A new way of handling the *
2848 * search extensions is in place. With the old approach, one ply *
2849 * could not extend more than one full ply. With the new approach, *
2850 * borrowed from Deep Blue, two consecutive plies can not extend *
2851 * more than two plies total. It averages out to be the same, of *
2852 * course, but the effect is a bit different. Now it is possible *
2853 * for a check and recapture to be applied at the same ply, where *
2854 * they could not before (since a check was already a full one-ply *
2855 * extension). Whether this is better or not is not clear yet, but *
2856 * it is worth careful analysis. EvaluateDraws() has been replaced *
2857 * by EvaluateWinner(). This function returns an indicator that *
2858 * specifices whether white, black, both or neither can win in the *
2859 * present position. *
2860 * *
2861 * 18.13 Deep Blue extension limit removed and restored to one ply of *
2862 * extension per ply of search. Pruning in q-search fixed so that *
2863 * a capture will be considered if it takes the total material on *
2864 * the board down to a bishop or less for the opponent, as that can *
2865 * greatly influence the evaluation with the EvaluateWinner() code. *
2866 * As the 50 move rule draws near, the hash table scores are marked *
2867 * as invalid every 5 moves so that hashing can't hide potential *
2868 * 50-move-rule draws. Lazy evaluation code modified to be more *
2869 * conservative, since in endgames the positional score can be a *
2870 * large change. EvaluatePassedPawnRaces() fixed so that if one *
2871 * side has two pawns that are far enough apart, it will recognize *
2872 * that even though the king is "in the square" of either, it can't *
2873 * always stay in the square of one if it has to capture the other. *
2874 * Pawn hash signature restored to 64 bits after testing proved that *
2875 * 32 was producing an unacceptable number of collisions. Search *
2876 * node counter is now 64 bits as well to avoid overflows. Bug in *
2877 * the outside passed pawn code fixed (bad mask). *
2878 * *
2879 * 18.14 Minor bug in ResignOrDraw() code caused Crafty to not offer draws *
2880 * although it would accept them when appropriate. Rook vs Minor *
2881 * is now evaluated as "neither side can win" an oversight in the *
2882 * EvaluateWinner() code. Minor bug in ResignOrDraw() would fail to *
2883 * offer draws due to the +0.01/-0.01 draw scores returned by the *
2884 * EGTB probe code. *
2885 * *
2886 * 18.15 Change in endgame draw recognition to handle the case where one *
2887 * side appears to be in a lost ending but is stalemated. The code *
2888 * now evaluates such positions as "DrawScore()" instead. The code *
2889 * to accept/decline draws has been modified. When a draw offer is *
2890 * received, a global variable "draw_offer_pending" is set to 1. *
2891 * When the search for a move for Crafty terminates, Crafty then *
2892 * uses this value to decide whether to accept or decline the draw. *
2893 * This means that the accept/decline won't happen until _after_ the *
2894 * search has a chance to see if something good is happening that *
2895 * should cause the draw to be declined, closing a timing hole that *
2896 * used to exist that let a few "suspects" get away with draws that *
2897 * should not have happened (ie Crafty has - scores for a long time, *
2898 * the opponent suddenly fails low and sees he is losing and offers *
2899 * a draw quickly. Crafty would accept before doing a search and *
2900 * noticing that it was suddenly winning.) minor evaluation change *
2901 * to notice that K+B+right RP vs K+B is not necessarily won if the *
2902 * weaker side has a bishop of the right color. *
2903 * *
2904 * 19.0 Significant change to the search extension limits. First, the *
2905 * limit of no more than 1 ply of extensions per ply has been tossed *
2906 * out. Now, any number of extensions are allowed in the first N *
2907 * plies, where N=iteration_depth of the current iteration. After *
2908 * the first N plies, extensions are reduced by 50% for the next N *
2909 * plies. They are then reduced by another 50% for the next N plies *
2910 * and then completely disabled after that. IE for a 12 ply search, *
2911 * all extensions (even > one ply) are allowed for the first 12 *
2912 * plies, then the extensions are reduced by 1/2 for the next 12 *
2913 * plies, then by 1/4 for the next 12 plies, then turned off from *
2914 * that point forward. Minor tweak (suggested by GCP) to reduce the *
2915 * time limit by 1/4 for ponder=off games was done in time.c. Fix *
2916 * to EvaluateWinner() to correctly realize that KR[BN] vs KRR is a *
2917 * draw for the KRR side if it doesn't have at least a pawn left. *
2918 * Minor bug in RejectBookMove() would reject all moves if the op- *
2919 * ponent had a stonewall-type pawn set-up. It was supposed to only *
2920 * reject castling into the attack. Minor change to code in the *
2921 * EvaluateMaterial() function to lower the penalty for sacrificing *
2922 * the exchange. it was considered just as bad as trading a rook *
2923 * for two pawns which was wrong. Change to hashing code so that we *
2924 * can now determine that a hash entry came from the EGTB so that *
2925 * PVs are displayed with <EGTB> when appropriate, not <EGTB> if it *
2926 * originally came from the EGTB but later <HT> when it was picked *
2927 * up from the hash table instead. Minor changes to search/searchmp *
2928 * to make them identical in "look" where possible, for consistency *
2929 * in source reading if nothing else. If the first argument on the *
2930 * command-line is "xboard" or if the environment variable *
2931 * "CRAFTY_XBOARD" is set, Crafty sends a "feature done=0" command *
2932 * to tell xboard it has not yet initialized things. Significant *
2933 * changes to EvaluateWinner() to recognize new cases of draws such *
2934 * as Q+minor+nopawns vs Q+pawns as unwinnable by the Q+minor side. *
2935 * Other cases were fixed/improved as well. *
2936 * *
2937 * 19.1 Changes to the outside passed pawn and outside candidate pawn *
2938 * code to more correctly recognize when one side has a simple end- *
2939 * game position that is easy to win. Futility pruning and razoring *
2940 * (Jeremiah Penery) was added. To endable it, you will need to add *
2941 * -DFUTILITY to the Makefile options, otherwise it is disabled by *
2942 * default. EvaluateWinner() had a bug dealing with KR vs KN or *
2943 * KRR vs KRN(B) that has been fixed. *
2944 * *
2945 * 19.2 CCT-5 version 01/20/03. *
2946 * Changes to the LimitExtensions() macro. The extensions are now *
2947 * a bit more aggressive, but after 2*iteration_depth, then they *
2948 * taper off smoothly so that by the time the depth reaches *
2949 * 4*iteration_depth, the extensions are cut to zero. Fixed bug in *
2950 * EvaluatePawns() that missed candidate passed pawns so that the *
2951 * new endgame stuff didn't work completely. Change to hash.c to *
2952 * combine the two hash tables into one so that the two probed *
2953 * entries are adjacent in memory to be more cache friendly. A bug *
2954 * in moving a replaced entry from depth-preferred to always-store *
2955 * caused the moved entry to go to the wrong address which would *
2956 * make it impossible to match later. New hash table layout is more *
2957 * cache-friendly by putting one entry from depth-preferred table *
2958 * with two entries from always-store, so that they often end up in *
2959 * the same cache-line. *
2960 * *
2961 * 19.3 Change to EvaluateMaterial to realize that a rook for five pawns *
2962 * is also likely a "bad trade." Adaptive hash table size code was *
2963 * added so that the hash size is set automatically based on the *
2964 * estimated NPS and time per move values for a specific "level" *
2965 * command setting. Repeat() rewritten. The old code had an *
2966 * unexplained bug that would overlook repetitions in a parallel *
2967 * search in rare cases. The old cold was complex enough that it *
2968 * was time to rewrite it and simplify it significantly. *
2969 * *
2970 * 19.4 Initial depth "seed" value changed to iteration_depth + 1/2 ply, *
2971 * so that fractional extensions kick in earlier rather than deeper *
2972 * in the search. This performs _much_ better in tactical tests *
2973 * such as WAC and similar suites. Minor book fix for a bug that *
2974 * could cause a crash with book=off in xboard/winboard. *
2975 * *
2976 * 19.5 Default draw score set to 1, because endgame table draws can be *
2977 * 0, -.01 or +.01, which translates to -1, 0 or 1 in real scores *
2978 * inside Crafty. +1 means a draw where white has extra material *
2979 * and that would break accepting draws with such a score. A few *
2980 * NUMA-related changes. One global variable was made thread- *
2981 * private to avoid cache thrashing. Split blocks are now allocated *
2982 * by each individual processor to make them local to the specific *
2983 * processor so that access is much faster. CopyToSMP() now tries *
2984 * to allocate a block for a thread based on the thread's ID so that *
2985 * the split block will be in that thread's local memory. A few *
2986 * other NUMA-related changes to help scaling on NUMA machines. *
2987 * *
2988 * 19.6 New egtb.cpp module that cuts decompression indices memory by 50% *
2989 * with no harmful side-effects. Fixes to NUMA code to make SMP and *
2990 * non-SMP windows compiles go cleanly. *
2991 * *
2992 * 19.7 Changes to draw code so that Crafty will first claim a draw and *
2993 * then play the move, to avoid any confusion in whether the draw *
2994 * was made according to FIDE rules or not. Minor bug in evaluate() *
2995 * dealing with candidate passed pawns fixed. A few additions to *
2996 * support my AMD Opteron inline assembly for MSB(), LSB() *
2997 * and PopCnt() procedures. *
2998 * *
2999 * 19.8 Changes to lock.h to (a) eliminate NT/alpha, since Microsoft no *
3000 * longer supports the alpha, which makes lock.h much more readable. *
3001 * CLONE is no longer an option either, further simplyfying the .h *
3002 * files. New mode option "match" which sets an aggressive learning *
3003 * mode, which is now the default. The old learning mode can be set *
3004 * by using the command "mode normal". Memory leak in new windows *
3005 * NUMA code fixed by Eugene Nalimov. AMD fix to make the history *
3006 * counts thread-local rather than global (to avoid excessive cache *
3007 * invalidate traffic). *
3008 * *
3009 * 19.9 Two new pieces of code submitted by Alexander Wagner. The first *
3010 * adds speech to Crafty for unix users. /opt/chess/sounds needs to *
3011 * exist and the common/sounds.tar.gz file needs to be untarred in *
3012 * directory. "Speech on*off" controls it. A new annotatet command *
3013 * outputs the annotated file in LaTeX format for those that prefer *
3014 * that platform. Lots of source reformatting to make indenting and *
3015 * other things more consistent, using the unix "indent" utility. *
3016 * Singular extension (simplistic approach) has been added and needs *
3017 * -DSINGULAR to activate it. Once it has been compiled in, you can *
3018 * turn it on/off by setting the singular extension depth using the *
3019 * ext command. Default is on if you compile it in. Ext/sing=0 *
3020 * disable it. Changes to non-COMPACT_ATTACKS code to shrink the *
3021 * array sizes. This was done primarily for the Opteron where the *
3022 * COMPACT_ATTACKS stuff was a bit slower than the direct look-up *
3023 * approach. This change reduced the table sizes by 75%. A small *
3024 * change to Evaluate() to better handle the 50-move draw problem. *
3025 * What used to happen was when the counter hit 100 (100 plies since *
3026 * last capture or pawn push) the score just dumped to DrawScore() *
3027 * instantly. It was possible that by the time the draw was seen, *
3028 * it was too late to do anything to avoid it without wrecking the *
3029 * position. what happens now is that once the 50-move counter *
3030 * reaches 80 plies (40 moves by both sides with no pawn push or *
3031 * capture) the score starts dropping toward DrawScore() no matter *
3032 * which side is winning. Dave Slate called this a "weariness *
3033 * factor" in that after playing 40 moves with no progress, the *
3034 * evaluation shows that the program is getting "weary". The idea *
3035 * is that the score starts to slip over the last 10 moves by each *
3036 * side to that if either can do something to reset the counter, *
3037 * they will do it sooner rather than later. *
3038 * *
3039 * 19.10 A fix to the EvaluateWinner() code to recognize that while KRB vs *
3040 * KR can not normally be won by the KRB side, we require that the *
3041 * KR side not be trapped on the edge of the board, where it can be *
3042 * mated. FUTILITY code put back in. 19.9 will be the SE version *
3043 * for those wanting to play with it. New "learn" command option to *
3044 * allow the user to set the position learning parameters that are *
3045 * used to trigger position learning and disable position learning *
3046 * after the game is already lost. The command syntax is as follows *
3047 * "learn trigger cutoff" and are expressed as fractions of a pawn *
3048 * with a decimel point. The default is learn .33 -2.0 which says *
3049 * to do position learning when the score drops 1/3 of a pawn, but *
3050 * turn it off after the score reaches -2.00 as the game is already *
3051 * lost and learning won't help at this point. This is the CCT-6 *
3052 * version exactly as played in the CCT-6 tournament. *
3053 * *
3054 * 19.11 A fix to the Annotate() code that could, in certain cases, fail *
3055 * to display N moves when asked. This happened when there were *
3056 * fewer than N moves total, and on occasion it would not display *
3057 * all the moves that were possible, omitting the last one. Fix to *
3058 * egtb.cpp to correctly set 16 bit index mode for a few of the *
3059 * recent 6-piece tables. *
3060 * *
3061 * 19.12 Fix to allocating split blocks that did not let all blocks get *
3062 * used, which would produce slow-downs on large parallel boxes *
3063 * (cpus > 8-16). Change to fail-high/fail-low window adjustment. *
3064 * I now use the old Cray Blitz approach ("Using time wisely - *
3065 * revisited", JICCA) where a fail-high (or low) now adjusts the *
3066 * root alpha or beta bound by 1 pawn on the first fail, another two *
3067 * pawns on the second failure, and finally relaxes the bound to *
3068 * +/- infinity on the third fail for the same move. This speeds up *
3069 * searching many fail-high/fail-low conditions, although it will *
3070 * occasionally cause the search to take a bit longer. *
3071 * *
3072 * 19.13 Fix to evaluating split passed pawns. Code is cleaner and is not *
3073 * applied if the opposing side has any pieces at all since a piece *
3074 * and the king can stop both. New egtb.cpp that opens the tables *
3075 * approximately 20-25% faster is included in this version (code by *
3076 * Eugene Nalimov of course). *
3077 * *
3078 * 19.14 New "eval" command (eval list and eval help to start) allow a *
3079 * user to modify all internal evaluation values via commands that *
3080 * may be entered directly or via the .craftyrc/crafty.rc init file. *
3081 * This was mainly done for the automated evaluation tuning project *
3082 * I am working on with Anthony Cozzie, but it will be useful for *
3083 * merging Mike Byrne's "personality" stuff as well. New command *
3084 * "personality load/save <filename>" which saves eval and search *
3085 * parameters to create new personalities that can be loaded at any *
3086 * time. "Crafty.cpf" is the "default" personality file that is *
3087 * used at start-up if it exists. Evaluation tuning changes based *
3088 * on some results from the new annealing code, although all of the *
3089 * annealed values are not yet fully understood nor utilized yet. *
3090 * LearnBook() is now used to learn good and bad game results. IE *
3091 * if Crafty wins with a particular opening, it will remember it as *
3092 * good and try it again, in addition to the previous method that *
3093 * would remember bad openings and avoid them. It also now handles *
3094 * draws as well which can make slightly bad openings appear better. *
3095 * Minor change to SMP code to eliminate the possibility of a shared *
3096 * variable getting overwritten unintentionally. Several changes to *
3097 * evaluation weights and evaluation code as testing for the WCCC *
3098 * continues. New "help" command uses a file "crafty.hlp" which now *
3099 * contains all the help information. This makes the help info *
3100 * easier to maintain and gets rid of a bunch of printf()s in the *
3101 * Option() source (option.c). Rewrite of the "list" code. Crafty *
3102 * now supports six lists, AK (auto-kibitz), B (blocker), C (comp), *
3103 * GM, IM and SP (special player). The SP list has two extra items *
3104 * that can be specified to go with a player's name, namely a book *
3105 * filename (to replace the normal books.bin, but not book.bin) and *
3106 * a personality file that will be loaded each time this particular *
3107 * named opponent plays. The format is available in the new help *
3108 * facility. Bug fix for outside passed pawn code that would cause *
3109 * an outside passer to appear to be a winning advantage even if the *
3110 * opponent has a protected passer, which easily negates the outside *
3111 * passer's threat. *
3112 * *
3113 * 19.15 Fix to outside passed pawn code that requires pawns on both sides *
3114 * of the board for the side with an "outside passer" or "outside *
3115 * candidate" to avoid some bizarre evaluations. Sel 0/0 now works *
3116 * without crashing Crafty. This would fail in previous versions as *
3117 * the hash signature would be modified but not restored. Slightly *
3118 * more conservative limit on using null-move search to head off a *
3119 * few notable zugzwang problems was added. Fix to time control *
3120 * code to remove a hole that could cause a divide-by-zero at a time *
3121 * control boundary. Stonewall detection removed completely as it *
3122 * appears to be no longer needed. Rook scoring changed to better *
3123 * evaluate "open files" by measuring mobility on them. Complete *
3124 * removal of Phase() (phase.c) and references to the opening, *
3125 * middlegame and endgame phases as they were no longer referenced *
3126 * anywhere in the code. *
3127 * *
3128 * 19.16 Fix to "Trojan code" to eliminate the time limit exclusion since *
3129 * many users still have old and slow hardware, and the time limit *
3130 * was not set correctly when PreEvaluate() was called anyway. The *
3131 * code to display fail-high/fail-low information was cleaned up so *
3132 * that the +1 or +3 now makes sense from the black side where the *
3133 * score is really going down (good for black) rather than showing *
3134 * a +3 fail high (when Crafty is black) and the score is really *
3135 * going to drop (get better for black). Now the fail-high-fail-low *
3136 * +/- sign is also relative to +=good for white like the scores *
3137 * have been for years. Adjustments to pawn evaluation terms to *
3138 * improve the scoring balance. "New" now terminates parallel *
3139 * threads (they will be re-started when needed) so that we don't *
3140 * burn CPU time when not actually playing a game. *
3141 * *
3142 * 19.17 Changes to pawn evaluation to limit positional scores that could *
3143 * get a bit out of sane boundaries in some positions. *
3144 * *
3145 * 19.18 ProbeTransRef() no longer adjusts alpha/beta bounds if the entry *
3146 * is not good enough to terminate the search here. This has helped *
3147 * speed things up (reduced size of tree) over many test positions *
3148 * so either it was buggy or not worthwhile. Regardless, it is now *
3149 * 'gone'. Connected passed pawns now scored as a simple pair of *
3150 * pawns that are better as they are advanced, the old connected *
3151 * passed pawns on the 6th rank special code has been removed. *
3152 * *
3153 * 19.19 Repeat3x() had a bug that would cause it to miss a draw claim on *
3154 * the 50th move, often making a strange (losing) move that would *
3155 * not lose if the draw is was claimed, but which would cause a loss *
3156 * if the draw was not claimed because the piece might be instantly *
3157 * captured if the opponent can play a move. *
3158 * *
3159 * 19.20 Bug in the EvaluateMaterial() (bad trade) code that would not *
3160 * penalize a single piece vs 3 pawns properly. Now the penalty is *
3161 * added in unless the side with the piece has nothing else to go *
3162 * with it at all (no pawns or other pieces). Pawn scoring changed, *
3163 * doubled pawns were scored too badly because the penalties were *
3164 * added twice (as expected) but they were set as if they were just *
3165 * added once. Eval command also had a bug in displaying the pawn *
3166 * evaluation parameters. Move input changed to accept pawn *
3167 * promotions of the form a8Q (this is needed as ChessBase violates *
3168 * the PGN/SAN standard that mandates a8=Q as the proper syntax for *
3169 * pawn promotions.) annoying glitch in epdglue.c that would *
3170 * produce the wrong score for positions with exactly one legal move *
3171 * was fixed. New InvalidPosition() function verifies that FEN *
3172 * setup positions are reasonable, without extra pawns or too many *
3173 * pieces total, etc. Passed pawn to 7th search extension removed, *
3174 * mate threat extension tuned down to 1/2 ply. Bug in SetBoard() *
3175 * fixed. This bug made it impossible to import many epd records *
3176 * due to incorrectly handling the wtm flag. This was introduced in *
3177 * the recent changes to disallow certain types of illegal positions *
3178 * that were impossible (more than 9 queens of one color, etc.) new *
3179 * eval term for space added. This simply counts the number of *
3180 * squares on each rank attacked by pawns, and then multiplies by a *
3181 * constant that scales the attacks so that attacking ranks on the *
3182 * opponent's side of the board is more valuable than attacking *
3183 * squares on our side of the board and vice-versa. Significant *
3184 * coding changes for the unix parallel search. POSIX threads are *
3185 * gone, due to too many differences between vendor's implementation *
3186 * details. Crafty now uses SYSV shared memory to share the search *
3187 * data (this is exactly the same parallel search approach always *
3188 * used, but with a completely different implementation) and fork() *
3189 * to spawn processes for each CPU. It simply became too much work *
3190 * to figure out what each vendor was doing about CPU time, how *
3191 * threads were scheduled, plus debug thread library implementations *
3192 * that were often buggy. There are no performance benefits to this *
3193 * approach other than falling back to features found in all Unix *
3194 * implementations. New NUMA changes to make sure that the local *
3195 * thread "blocks" are actually allocated on the NUMA node where *
3196 * the process actually runs, rather than on a remote node that *
3197 * will cause extra memory latency for often-used memory data. Bug *
3198 * in EvaluatePawns() caused the outside passer / outside *
3199 * candidate bonus to be triggered when the opponent has a simple *
3200 * protected passed pawn. Since the decoy value is nil with a *
3201 * protected passer (we can't take the supporing pawn or the passer *
3202 * will run) the outside candidate or passer doesn't help. Bug in *
3203 * king safety caused pieces to be attracted to the opponent's king, *
3204 * even in simple endgames, inflating/deflating the score for a *
3205 * feature that was pointless. (2005 WCCC final version). *
3206 * *
3207 * 20.0 First in a new series. First change is to produce an endian- *
3208 * independent opening book. The format has not changed so that old *
3209 * book.bin/books.bin files will work fine, but they may now be *
3210 * freely between big-endian and little-endian architectures. This *
3211 * makes the binary format compatible between a PC and a Sun or HP *
3212 * box, for example, so that just one book.bin file is needed. *
3213 * *
3214 * 20.1 First step toward a complete redesign of the evaluation code in *
3215 * Evaluate() (evaluate.c). This first set of changes are mainly *
3216 * restructuring related, an attempt to collect the various bits of *
3217 * evaluation code that are related to a common theme (i.e. All *
3218 * bishop scoring, all passed pawn scoring, etc) are not contained *
3219 * in one routine, with a sensible name. This makes it much easier *
3220 * to find evaluation code and modify it, without having bits and *
3221 * pieces scattered all over the place. Perhaps the most signifi- *
3222 * cant is that the current evaluation has dropped the asymmetric *
3223 * king safety, and later the asymmetric blocked pawn code will go *
3224 * as well. To do this, I did have to make some changes in terms *
3225 * of the "tropism" code. The basic idea is that white's "tropism" *
3226 * bonus in incremented for each white piece that attacks the black *
3227 * king, but it is also decrement for each black piece that attacks *
3228 * the black king, so that a defender offsets an attacker. This has *
3229 * certainly changed the "personality" of how it plays. It is now *
3230 * far more aggressive, and further changes planned for the future *
3231 * will hopefully improve on this change. It is playing quite a bit *
3232 * better, but whether this aggressiveness is "over the top" remains *
3233 * to be seen. Fix to "won kp ending" logic. If one king is closer *
3234 * to the opponent's "average pawn square" than the other, by at *
3235 * least 2 moves, then that side is credited as having a won k+p *
3236 * ending. New code for time allocation testing added. A new *
3237 * "timebook <factor> <moves>" command that says use "factor" extra *
3238 * time (factor is expressed as a percent, 100 means use 100% extra *
3239 * time) tapered off for "moves" out of book. For example, *
3240 * "timebook 100 10" says use 100% extra time on first non-book move *
3241 * followed by 90% extra on the next move, 80% on the next, until *
3242 * after 10 moves we are back to the normal time average. *
3243 * *
3244 * 20.2 Significant evaluation changes to try to limit positional scores *
3245 * so that new tuning can be accomplished. In particular, the king *
3246 * safety code has been greatly simplified, now having two separate *
3247 * components, one for pawn structure, one for piece tropism. A new *
3248 * SearchControl() procedure now handles all the search extensions *
3249 * in one centralized place, shared by normal and parallel search *
3250 * code. The plan is that eventually this piece of code will also *
3251 * be able to recommend search reductions as well as extensions to *
3252 * speed the tree traversal process significantly with a form of *
3253 * of forward pruning that is commonly called "search reductions". *
3254 * *
3255 * 20.3 Search reduction code added. Part of this dates back to 1997 *
3256 * when Bruce Moreland and I played with the idea of reducing the *
3257 * depth on the last part of the move list when it seemed to become *
3258 * fairly certain that no fail-high was going to happen. That was a *
3259 * big search speed improvement, but also risky. Recently, several *
3260 * started to do this again, except they added one fairly useful *
3261 * constraint, that the "history value" for a specific move has to *
3262 * be below some threshold before a reduction can happen. The idea *
3263 * is that we don't want to reduce the depth of moves that have *
3264 * failed high in the past, because they might fail high again if *
3265 * they are not reduced too much. Tord Romstad suggested an *
3266 * additional improvement, namely that if a reduced move does fail *
3267 * high, re-search with the proper (non-reduced) depth to verify *
3268 * that it will fail high there as well. All of this is included *
3269 * in version 20.3, but the values (reduction amount, history *
3270 * threshold, min depth to do a reduction) need serious testing and *
3271 * tuning. The current values are simply "legal" but hardly could *
3272 * be considered optimal without substantial testing. New code to *
3273 * "age" history counters added. After each iteration, this code *
3274 * divides each counter by 2, to scale the values back, so that *
3275 * moves that are no longer causing fail highs will have a history *
3276 * value that won't prevent reduction pruning. The "minimum depth" *
3277 * value indicates how much search to leave after doing a reduction *
3278 * in the tree. A value of 1 ply guarantees that after a reduction *
3279 * is done, there will always be one full-width ply of search done *
3280 * after such reductions to avoid gross tactical oversights. Tuning *
3281 * to extensions to reduce the tree size. The recapture extension *
3282 * has been completely removed, while the check extension has been *
3283 * left at 1.0 as in the past. The mate threat and one-legal-reply *
3284 * extensions are now both set to .75 after extensive testing. This *
3285 * is the CCT8 version of Crafty. *
3286 * *
3287 * 20.4 History counters changed. There is now one large history[8192] *
3288 * array to simplify indexing. More importantly, these values are *
3289 * now limited to a max value of 32000. During the update process, *
3290 * if any value reaches that limit, all values are divided by 2 to *
3291 * prevent deep searches from producing very large history values *
3292 * which would essentially disable late move reductions based on the *
3293 * big history values. The reduce/history=n command now uses values *
3294 * 0 <= n <= 100. A value of 100 will cause all non-tactical moves *
3295 * to be reduced (most aggressive) while a value of 0 will result in *
3296 * no moves being reduced (most conservative). The value, loosely *
3297 * interpreted, means "reduce if a move fails high < n% of the time *
3298 * when at least one move fails high in a search." the default is *
3299 * currently 50%, but further testing is needed. *
3300 * *
3301 * 20.5 Old "mask" code removed and replaced by constants, since this is *
3302 * never intended to run on a Cray specifically any longer. Change *
3303 * to "won king and pawn ending" to make it more accurate, this code *
3304 * is used when there are nothing but pawns left, all on one side of *
3305 * board, and one king is closer to a capturable pawn than the other *
3306 * king is. This is intended to help in outside passed pawn games *
3307 * where one side has to eventually give up the outside passer to *
3308 * decoy the opposing king away from the rest of the pawns. New *
3309 * king safety now factors in king pawn shelter and opponent piece *
3310 * tropism into one score, but the score is now an arithmetic *
3311 * value that goes up more quickly as both indices increase, to do a *
3312 * more accurate evaluation of safety and attacking chances. Change *
3313 * to bishop mobility, which now goes in units of 2 rather than 1, *
3314 * to increase the value of mobility somewhat. Also mobility is now *
3315 * 'centered' in that it is computed as (squares - 6) * 2, to keep *
3316 * the bishop value from going way over its normal range with these *
3317 * new and somewhat larger numbers. *
3318 * *
3319 * 20.6 New eval code to look for bishops that are blocked in the forward *
3320 * direction by friendly pawns. That basically turns a bishop into *
3321 * a "tall pawn" since movement in the critical direction is not *
3322 * possible. *
3323 * *
3324 * 20.7 Manually tuned kinf_safety[][] array values. Modified the new *
3325 * bishop code to only consider the "long diagonal" if the bishop *
3326 * is in either 9-square corner on its own side of the board, so *
3327 * that the short diagonal being open won't offset the long *
3328 * diagonal that is blocked. Bishop-pair bonus is now adjusted by *
3329 * how open or closed the center is. If 3 of the four center pawns *
3330 * are gone, the center is open and the bishop pair bonus is set to *
3331 * the max. If the four center pawns are locked (e4/e5/d5/d6 for *
3332 * example) then the bishop pair bonus is eliminated. if the center *
3333 * is somewhere in the middle of those extremes, then the bishop *
3334 * pair bonus is present but reduced. Castling now is a bit more *
3335 * intelligent. If a side has not castled, then moving either rook *
3336 * receives a penalty, where moving the king or the last unmoved *
3337 * rook receives a larger penalty. If the king has not castled, its *
3338 * 'safety' score is based on the most safe position of the possible *
3339 * options. If neither rook has moved, then the score is based on *
3340 * the safest of the three locations, either in the center where it *
3341 * is, or on the safest wing. If uncastled, this safaty is always *
3342 * reduced a bit to encourage castling before it becomes too late to *
3343 * do so. This was done to avoid a problem where the queen rook had *
3344 * been moved, Crafty had not castled, and it pushed the kingside *
3345 * pawns making it unsafe to castle there, leaving the center as the *
3346 * best place, yet had it not pushed the kingside pawns, castling *
3347 * would have been a better alternative. Two new 16 word vectors, *
3348 * safety_vector[]/tropism_vectorp[] are used to set the edge values *
3349 * for the king_safetyp[][] array. Interior values are filled in *
3350 * based on these two vectors, making it much easier to tweak the *
3351 * king safety scores without pulling your hair out. *
3352 * *
3353 * 20.8 When queens come off, the previous version cut the tropism scores *
3354 * and pawn shelter scores by 1/2 each, which had the effect of *
3355 * dropping the overall score by 75% (the score is a geometric *
3356 * computation). The safety/tropism values are now dropped, but by *
3357 * a smaller amount, since bishops + rooks + knights are still a *
3358 * dangerous threat. *
3359 * *
3360 * 20.9 Simple lazy eval (Mike Byrne) added. This simply avoids the more *
3361 * expensive piece evaluations if the pawn scoring and material *
3362 * leave the score well outside the alpha/beta search window. Looks *
3363 * like a 20% speed improvement in general. *
3364 * *
3365 * 20.10 Change to king safety pawn structure. Open files around the king *
3366 * are dangerous, but the h/g (or b/a) files are more dangerous than *
3367 * the f-e-d-c files since they are much harder to defend against *
3368 * with the castled king in the way. Modified the way the king *
3369 * safety matrix is computed so that at the tropism/pawnstructure *
3370 * values are more sane. It currently will get the same value for *
3371 * array indices of 5,0, 4,1, 3,2, 2,3, 1,4, or 0,5, which is better *
3372 * than what it was doing. I plan to tweak this more later to make *
3373 * 3,2 or 2,3 worse than 4,1 or 1,4 and 0,5 or 5,0, as the latter *
3374 * mean "unsafe king but no piece pressure" or "piece pressure but *
3375 * king pawn shelter is safe" whereas the middle values mean both *
3376 * components of an attack are present, unsafe king position and the *
3377 * pieces are closing in. *
3378 * *
3379 * 20.11 Minor fix to late move reduction code. Turns out it is possible *
3380 * to reach the block of code if (first_move) { } with status set to *
3381 * REMAINING_MOVES (this means no captures, no killer, no hash move, *
3382 * no history move, etc). That would let me try a reduction, and if *
3383 * it failed high, we would use that score as-is. We now re-search *
3384 * a fail-high here just like we did in the other block of code so *
3385 * that a fail-high on a reduction search is never trusted. *
3386 * *
3387 * 20.12 Further modifications to king safety initialization code to try *
3388 * scale back the values a bit to control score limits. *
3389 * *
3390 * 20.13 Fix to bench.c to remove two file closes that would wreck the *
3391 * program after the bench command was finished. Also the *
3392 * SMP-time-to-ply measurement was removed since it had no meaning. *
3393 * Old FUTILITY code re-inserted along with an extension limit *
3394 * modification by Mike Byrne to avoid limiting the search extension *
3395 * on one-reply extensions only. New lock.h submitted by Andreas *
3396 * Guettinger to support spinlocks on the PPC architecture (Linux). *
3397 * Some -D configuration options were changed so that none are *
3398 * needed to compile the "standard" Crafty. Futility is normally on *
3399 * now, and -DNOFUTILITY is required to compile it out. The new *
3400 * Makefile gives the configuration options, but the only ones that *
3401 * would normally need setting are the SMP and CPUS= options if you *
3402 * have a SMP platform. *
3403 * *
3404 * 20.14 Fix to EvaluateWinningChances() to correctly evaluate KRP vs KR *
3405 * type endings. Previously this was done in the wrong place and *
3406 * the score would favor the side with the pawn significantly, where *
3407 * the score is now zero. Minor bugfix to code that detects that an *
3408 * illegal position has been set up. It caught every possible *
3409 * problem except for positions with a king (or kings) missing. *
3410 * *
3411 * 20.15 Change to how Crafty chooses where to split. Previously, there *
3412 * was a min remaining depth limit to prevent Crafty from trying to *
3413 * split too close to the frontier nodes. Now that is specified as *
3414 * a percentage of the nominal search depth. For example, the *
3415 * default value is 50%, which says that on a 16 ply search, we can *
3416 * split if at least 8 plies of search are left. This provides *
3417 * better split overhead than a simple limit that doesn't take the *
3418 * actual search depth into consideration. History data arranged to *
3419 * be more cache friendly. The three values for a common history *
3420 * index value are now stored in adjacent memory words to take *
3421 * advantage of pre-fetching within a cache line. Additional *
3422 * tuning of the king safety matrix. *
3423 * *
3424 * 20.16 Evaluation of knights, bishops, rooks, queens and kings is now *
3425 * done on a 1000 point scale, then the sum is divided by 10. This *
3426 * allows us to use the same hashing mechanism, but with finer *
3427 * tuning precision. Minor queen eval tweak for 7th rank position. *
3428 * *
3429 * 20.17 New book learning, with a simplified book system. The export *
3430 * files (book.lrn, position.lrn) no longer are created/used, the *
3431 * learn mechanism no longer touches the real chess board which *
3432 * could cause problems in certain xboard/winboard timing *
3433 * situations. One major learning change is that we now only learn *
3434 * things from "Crafty's perspective". That is, if Crafty loses a *
3435 * game as black, it won't think that opening is good when it plays *
3436 * white since it might well not understand how to win using that *
3437 * particular opening. It will only "learn" on the actual moves it *
3438 * plays in a game. Old "history heuristic" removed. Testing *
3439 * showed that the LMR idea produced better results without the *
3440 * history ordering, since now more moves are reduced, but moves *
3441 * with good history values don't get reduced. *
3442 * *
3443 * 21.0 Finally did the bit-renumbering task so that bit 0 = LSB = A1, *
3444 * to eliminate the 63-n translation to the numbering scheme used *
3445 * on the Cray architecture. For all bit operations now, LSB=0, *
3446 * MSB=7, 15, 31 or 63 depending on the data size. A few minor *
3447 * bugs were fixed along the way as these changes were debugged. *
3448 * Minor bug in EvaluateKings() where it tested for a "won ending" *
3449 * and used a test that was too aggressive. This test did not get *
3450 * things quite right when the two kings were very close together *
3451 * and "opposition" prevented one king from moving closer to the *
3452 * pawns. *
3453 * *
3454 * 21.1 New piece scoring from Tracy, which changes the way pieces are *
3455 * scored based on squares they attack. *
3456 * *
3457 * 21.2 The scores are now scaled better for the transition from middle- *
3458 * game to end-game. Passed pawn scores climb as material is *
3459 * removed from the board, to prevent them from overwhelming the *
3460 * middlegame king safety scores. We do exactly the same scaling on *
3461 * king-safety scores, but they are scaled downward as material is *
3462 * removed so that they "phase out" as the endgame is reached. *
3463 * Weak pawn code changed to more accurately identify weak pawns. *
3464 * These are totaled and then used to index a scoring array that *
3465 * penalizes the number of weak pawns on each side. Pawn islands *
3466 * are now recognized and each side is penalized according to the *
3467 * number of islands he has, more being worse. *
3468 * *
3469 * 21.3 "Magic" move generation is now used, which eliminates the rotated *
3470 * bitboard approach completely. Not a significant speed change, *
3471 * but it is far simpler overall. Original code by Pradu Kannan as *
3472 * posted on CCC/Winboard forums, modified to work with Crafty. *
3473 * *
3474 * 21.4 Misc eval changes. More king safety changes to include a tropism *
3475 * distance of 1 for bishops or rooks that can slide to intercept *
3476 * any square surrounding the enemy king. Reduced rook slide score *
3477 * by 40%.
3478 * *
3479 * 21.5 passed pawn extension revisited. Bad trade was giving a penalty *
3480 * for being down an exchange (or a bonus for being up an exchange) *
3481 * which was not expected behavior. This has been fixed. EGTB *
3482 * initialization was being done during the first pass over the *
3483 * RC file, which was too early as the rest of the engine had not *
3484 * been initialized. Now the "egtb" command is the only thing that *
3485 * triggers initialization, and is only processed during the second *
3486 * pass over the RC file after paths have been properly set up. *
3487 * Abs() function bug fix. *
3488 * *
3489 * 21.6 Passed pawn evaluation changed with respect to distant passed *
3490 * pawns and distant majorities. Now, if both have a pawn majority *
3491 * we check to see if one is "distant" (away from the enemy king) as *
3492 * this represents a significant time advantage because the other *
3493 * side has to waste moves to reach and capture the pawn to prevent *
3494 * promotion. LMR no longer uses the history counters, which proved *
3495 * to be essentially random numbers. LMR decisions are now based *
3496 * solely on static characteristics of an individual move, rather *
3497 * than trying to determine how the move affected the search at *
3498 * other points in the tree. New wtm bonus added to evaluation. *
3499 * EvaluateMate() bug fixed where the score was set to a non-zero *
3500 * value which broke EvaluateMate() completely. New mobility code *
3501 * for bishops/rooks encourages better piece placement. Note that *
3502 * there are many other evaluation changes too numerous to list here *
3503 * in detail. *
3504 * *
3505 * 21.7 New reduce at root code added to do reductions at the root, but *
3506 * not on any move that has been a "best move" during the current *
3507 * search, unless the move drops too far in the move list. New nice *
3508 * mode for parallel search terminates threads while waiting on the *
3509 * opponent's move to avoid burning unnecessary CPU time (this nice *
3510 * mode is NOT the default mode however.) -DNOFUTILITY removed as *
3511 * futility is on by default and should not be removed. All of the *
3512 * search() code has been cleaned up and streamlined a bit for more *
3513 * clarity when reading the code. Nasty bug in EvaluatePawns() that *
3514 * unfortunattely used the king squares to make a decision dealing *
3515 * with outside passed pawns, but the hash signature for pawns does *
3516 * not include king position. This code was deemed unnecessary and *
3517 * was summarily removed (not summarily executed, it has had that *
3518 * done far too many times already). *
3519 * *
3520 * 22.0 Redesign of the data structures completed so that Crafty will no *
3521 * longer have duplicated code for wtm and btm cases. This has *
3522 * already resulted in a rewrite of movgen(), SEE(), Make() and *
3523 * Unmake() and cut that code size by almost exactly 50%. The result *
3524 * has been slightly faster speeds, but also the future benefits *
3525 * will be enormous by eliminating a lot of debugging caused by the *
3526 * duplicated code. Timing change to avoid starting an iteration *
3527 * and wasting significant time. We still search enough to get a *
3528 * quick fail-low, otherwise we stop and make the move and save the *
3529 * time we used to burn. Massive cleanup in the macros used to *
3530 * access much of the data since the new [wtm] approach resulted in *
3531 * many old macros becoming unused. Yet another rewrite of the code *
3532 * that handles repetition detection. There is an undetected bug in *
3533 * the previous code, related to pondering and SMP, that was not *
3534 * obvious. The code was completely rewritten and is now much *
3535 * simpler to understand, and has been verified to be bug-free with *
3536 * massive cluster testing. *
3537 * *
3538 * 22.1 Minor fix for CPUS=1, which would cause compile errors. Other *
3539 * eval tweaks to improve scoring. New "skill" command that can be *
3540 * used to "dumb down" Crafty. "Skill <n>" where n is a number *
3541 * between 1 and 100. 100 is max (default) skill. Skill 70 will *
3542 * drop the playing Elo by about 200 points. Skill 50 will drop it *
3543 * about 400 points. The curve is not linear, and the closer you *
3544 * get to 1, the lower the rating. To use this feature, you need to *
3545 * add -DSKILL to your Makefile options otherwise it is not included *
3546 * in the executable. *
3547 * *
3548 * 22.2 We are now back to using POSIX threads, since all current Linux *
3549 * distributions now use the posix-conforming NTPL implementation *
3550 * which should eliminate the various compatibility issues that *
3551 * caused problems in the past. This also should make the new *
3552 * smpnice mode work correctly for Linux and Windows since they will *
3553 * now both use threads for the SMP search. Fruit-like scoring *
3554 * (interpolation between mg and eg scores) fully implemented. AEL *
3555 * pruning (Heinz 2000) also fully implemented (we had razoring and *
3556 * futility, but not extended futility). "Eval" command has been *
3557 * removed and combined with the "personality" command so that eval *
3558 * parameters can be modified, in addition to some search parameters *
3559 * that also belong in the personality data. Mate threat extension *
3560 * and one legal reply to check extensions have been removed. Tests *
3561 * proved them to be absolutely useless, over 30,000 games for each *
3562 * test showed no gain and sometimes a loss in playing strength with *
3563 * them so we followed the "simple is better" and removed them. The *
3564 * fractional ply code was also removed since the only extension we *
3565 * now use is the "give check" extension which is a whole ply. A *
3566 * significant number of evaluation parameters have been changed, *
3567 * a few even removed as cluster testing helped us find optimal *
3568 * values. There are a few new terms, with more planned. *
3569 * *
3570 * 22.3 Corrected a bug in analysis mode where "back n" would crash. A *
3571 * bad array reference broke this during recent changes. *
3572 * *
3573 * 22.4 Corrected a bug in NextRootMove() that tries to calculate the NPS *
3574 * by adding up the node counters in each used split block. However *
3575 * should you not use all possible threads (mt=n where n is < the *
3576 * max CPUS value compiled in) then all split blocks will not be *
3577 * properly initialized (not even allocated) which will cause a *
3578 * segfault instantly. Pawn island evaluation term has also been *
3579 * removed as cluster testing showed that setting these values to *
3580 * zero produced a +14 Elo gain. There might be a better value for *
3581 * them, but the old value was too high. Further cluster testing is *
3582 * underway to test other (but smaller than original) values to see *
3583 * if one of them turns out to be better than zero. So far, no, but *
3584 * the test has not completed. *
3585 * *
3586 * 22.5 Minor eval tweaks. Pthread_create was called without giving it *
3587 * any attributes for the new thread(s) which makes them default to *
3588 * "joinable". When smpnice=1 terminates threads, the threads hang *
3589 * around using memory expecting that the parent will join with them *
3590 * to check the exit status. We now set "detached" as the proper *
3591 * attribute so that this memory leak no longer happens. *
3592 * *
3593 * 22.6 Compile issue fixed which would cause the pthread_lib calls to *
3594 * be used in a windows compile, which was incorrect. They are now *
3595 * protected by a #if defined(UNIX) && (CPUS > 1) conditional test. *
3596 * *
3597 * 22.7 Windows NUMA support fix to eliminate a memory leak caused by *
3598 * re-malloc'ing the split blocks each time a new game is started. *
3599 * This was not found in the previous memory leak testing as that *
3600 * problem was related to stopping/re-starting threads when using *
3601 * smpnice=1. This is unrelated, but similar, and has been around *
3602 * a long time. *
3603 * *
3604 * 22.8 Modified material imbalance fix from Tracy included. This *
3605 * produced an immediate +7 Elo improvement, and additional tuning *
3606 * is under way. Fix to GenerateChecks(). This code had bugs a few *
3607 * weeks back and they were fixed, but the fixes were somehow lost *
3608 * during copying files among multiple machines. The fixes are now *
3609 * back in and properly saved. *
3610 * *
3611 * 22.9 More eval tuning producing another +10 Elo gain. Curmv[n] was *
3612 * "overloaded" in that it was used to obtain the next move for a *
3613 * parallel thread and was also used to pass back a "fail high" move *
3614 * to store in a "LOWER" hash table entry. This led to some error *
3615 * messages internal to Crafty that could possibly cause problems. *
3616 * There is now a second variable "cutmove" used to pass the move *
3617 * back to eliminate race conditions. Hash.c modified extensively *
3618 * to improve readability as well as to eliminate duplicated code. *
3619 * Internal iterative deepening code removed. No measurable benefit *
3620 * in real game testing led to removal since it is simpler without *
3621 * the code. EvaluateMaterialDynamic() also removed. This was code *
3622 * that implemented ideas suggested by IM Larry Kaufman, but careful *
3623 * testing showed absolutely no effect on game results. Again, we *
3624 * chose "simpler is better" and removed it, as no tuning attempts *
3625 * helped for this code. Nasty pawn hashing bug fix, something that *
3626 * has been around for years. This was essentially the same sort of *
3627 * bug that the "lockless hashing algorithm" addressed for the main *
3628 * hash table, where out-of-order memory writes could produce a hash *
3629 * signature and the 64 bit word with score and best move which did *
3630 * not "go together". The same thing happens in pawn hashing, *
3631 * except that an entry is 32 bytes rather than 16, giving even *
3632 * higher probability of an entry that contains mismatched pieces. *
3633 * In the best case, we just got a bad score. In the worst case, *
3634 * this could cause a program crash since some of the data might be *
3635 * invalid, yet it can be used in ways that produce impossible array *
3636 * subscripts that would cause (very rarely) a segmentation fault. *
3637 * The solution was to do the same lockless hashing algorithm where *
3638 * the key is XORed with the other three 64 bit words when the entry *
3639 * is stored, then XORed with them again when we try to match. If *
3640 * the entry is mismatched, the signature will not match anything *
3641 * and we simply will not use the bad data and do a normal pawn *
3642 * evaluation to compute valid values. *
3643 * *
3644 * 23.0 Essentially a cleaned up 22.9 version. Comments have been *
3645 * reviewed to make sure they are consistent with what is actually *
3646 * done in the program. Major change is that the random numbers *
3647 * used to produce the Zobrist hash signature are now statically *
3648 * initialized which eliminates a source of compatibility issues *
3649 * where a different stream of random numbers is produced if an *
3650 * architecture has some feature that changes the generator, such *
3651 * as a case on an older 30/36 bit word machine. The issue with *
3652 * this change is that the old binary books are not compatible and *
3653 * need to be re-created with the current random numbers. The *
3654 * "lockless hash table" idea is back in. It was removed because *
3655 * the move from the hash table is recognized as illegal when this *
3656 * is appropriate, and no longer causes crashes. However, the above *
3657 * pawn hash issue showed that this happens enough that it is better *
3658 * to avoid any error at all, including the score, for safety. We *
3659 * made a significant change to the parallel search split logic in *
3660 * this version. We now use a different test to limit how near the *
3661 * tips we split. This test measures how large the sub-tree is for *
3662 * the first move at any possible split point, and requires that *
3663 * this be at least some minimum number of nodes before a split can *
3664 * be considered at this node. The older approach, which based this *
3665 * decsion on remaining search depth at a node led to some cases *
3666 * where the parallel search overhead was excessively high, or even *
3667 * excessively low (when we chose to not split frequently enough). *
3668 * This version appears to work well on a variety of platforms, even *
3669 * though NUMA architectures may well need additional tuning of this *
3670 * paramenter (smpsn) as well as (smpgroup) to try to contain most *
3671 * splits on a single NUMA node where memory is local. I attempted *
3672 * to automate this entire process, and tune for all sorts of plat- *
3673 * forms, but nothing worked for the general case, which leaves the *
3674 * current approach. When I converted back to threads from *
3675 * processes, I forgot to restore the alignment for the hash/pawn- *
3676 * hash tables. The normal hash table needs to be on a 16 byte *
3677 * boundary, which normally happens automatically, but pawn hash *
3678 * entries should be on a 32 byte boundary to align them properly in *
3679 * cache to avoid splitting an entry across two cache blocks and *
3680 * hurting performance. New rook/bishop cache introduced to limit *
3681 * overhead caused by mobility calculations. If the ranks/files the *
3682 * rook is on are the same as the last time we evaluated a rook on *
3683 * this specific square, we can reuse the mobility score with no *
3684 * calculation required. The code for "rook behind passed pawns" *
3685 * was moved to EvaluatePassedPawns() so that it is only done when *
3686 * there is a passed pawn on the board, not just when rooks are *
3687 * present. Book learning has been greatly cleaned up and *
3688 * simplified. The old "result learning" (which used the game *
3689 * result to modify the book) and "book learning" (which used the *
3690 * first N search scores to modify the book) were redundant, since *
3691 * result learning would overwrite whatever book learning did. The *
3692 * new approach uses the game result (if available) to update the *
3693 * book database when the program exits or starts a new game. If *
3694 * a result is not available, it will then rely on the previous *
3695 * search results so that it has some idea of whether this was a *
3696 * good opening or not, even if the game was not completed. Minor *
3697 * LMR bug in SearchRoot() could do a PVS fail-high research using *
3698 * the wrong depth (off by -1) because of the LMR reduction that had *
3699 * been set. The normal search module had this correct, but the *
3700 * SearchRoot() module did not. EvaluateDevelopment() was turned *
3701 * off for a side after castling. This caused a problem in that we *
3702 * do things like checking for a knight blocking the C-pawn in queen *
3703 * pawn openings. Unfortunately, the program could either block the *
3704 * pawn and then castle, which removed the blocked pawn penalty, or *
3705 * it could castle first and then block the pawn, making it more *
3706 * difficult to develop the queen-side. We now enable this code *
3707 * always and never disable it. This disable was done years ago *
3708 * when the castling evaluation of Crafty would scan the move list *
3709 * to see if Crafty had castled, when it noticed castling was no *
3710 * longer possible. Once it had castled, we disabled this to avoid *
3711 * the lengthy loop and the overhead it caused. Today the test is *
3712 * quite cheap anyway, and I measured no speed difference with it on *
3713 * or off, to speak of. Now we realize that the knight in front of *
3714 * the C-pawn is bad and needs to either not go there, or else move *
3715 * out of the way. *
3716 * *
3717 * 23.1 Xboard protocol support slightly modified so that draw results *
3718 * are now sent after the move that causes the draw. They were *
3719 * always sent before a move if the position prior to the move was *
3720 * drawn, but they were also sent just before playing a move to work *
3721 * around a xboard protocol race condition where I can send a move, *
3722 * and then a draw claim (xboard 'result string') and the GUI sees *
3723 * my move, relays it to my opponent, and gets an instant reply that *
3724 * it then sees before my draw claim. After making this move and *
3725 * forwarding it to me, it now thinks the draw claim is invalid. *
3726 * slight tweak to queen material value and the way our bishop pair *
3727 * scoring is done. The old razoring code has been removed. It is *
3728 * redundant with LMR, and it had the unwanted side-effect of *
3729 * reducing a few of the moves two plies. The futility pruning has *
3730 * been modified to work at the last N plies. We have an array of *
3731 * pruning margins (tuned on the cluster) where anytime the depth is *
3732 * less than "pruning_depth" we try the futility test. If the test *
3733 * succeeds, that move is discarded and not searched at all. Move *
3734 * ordering code modified slightly to call SEE() fewer times if the *
3735 * goodness of the capture can still be accurately assessed without *
3736 * the call. Hash table has been changed to use a bucket of 4 *
3737 * entries similar to a 4-way set associative cache. When a store *
3738 * is attempted, we replace the least useful entry (see hash.c for *
3739 * details). Additionally the hash table is forced to a 64 byte *
3740 * boundary alignment so that a bucket aligns on the start of a *
3741 * cache line for efficiency. The old approach used 3 entries per *
3742 * bucket, the Belle two-table approach, which caused 1/2 of the *
3743 * cache probes to result in two cache line reads rather than just *
3744 * one. Slight modification to "time overflow" logic. Now, if the *
3745 * score drops on the iteration where we reach the normal time *
3746 * allocation, Crafty will continue to search. Previously the score *
3747 * had to drop by 1/4 pawn, but cluster testing has shown that this *
3748 * change is better. Final bit of old rotated bitboard logic *
3749 * removed. We had two bitboards, RooksQueens and BishopsQueens *
3750 * that were updated in MakeMove() and UnmakeMove(). It turned out *
3751 * to be faster to just OR the needed piece bitboards together since *
3752 * they were infrequently used in the new "magic" approach, which *
3753 * allowed me to remove them completely from the position structure *
3754 * and make/unmake. Net result was a percent or two faster search *
3755 * overall. Old bug fixed related to EGTB usage. The Edwards *
3756 * format did not include en passant pawn captures, so it was *
3757 * necessary to avoid probing any position where both sides had a *
3758 * pawn and there was any possibility of an en passant capture (one *
3759 * pawn on original square, enemy pawn anywhere on either adjacent *
3760 * file). The Nalimov tables consider en passant correctly, but *
3761 * somehow this old code was either left in iterate.c or else added *
3762 * back in by accident. It is now no longer present. Minor changes *
3763 * (suggested by J. Cleveland on CCC) that avoids trying a null-move *
3764 * search when remaining depth == 1, and which saves some effort by *
3765 * remembering, when a node fails low, the first move searched. *
3766 * This move then gets stored in the hash table as the "best move". *
3767 * While this might be wrong, it has a chance of being right and *
3768 * when it is good enough to cause a cutoff, we can avoid a move *
3769 * generation which saves a bit of time. Fixed a significant bug in *
3770 * EvaluateWinningChances() where it was using a global variable *
3771 * "wtm" which tells who is to move in the real game, not at the *
3772 * current position in the treee. This value is used for tempo *
3773 * calculations to determine if the losing king (in a K + rook-pawn *
3774 * ending (with or without wrong bishop)) can reach the queening *
3775 * square before the winning side's king can block acccess. This *
3776 * would randomly make the tempo calculation off by one, so that the *
3777 * score could bounce from draw to win and back as the game *
3778 * progresses, since about 1/2 the time the wtm value is wrong. I *
3779 * simply passed the current wtm in as a formal parameter to solve *
3780 * this (a good example of why having a global variable and a formal *
3781 * argument paramenter using the same name is a bad idea.) In this *
3782 * same general area, EvaluateDraws() could set the score to *
3783 * DrawScore, which was somewhat "iffy". I changed this to simply *
3784 * determine if the side that ahead is score has any realistic *
3785 * winning chances. If not, I divide the score by 10 rather than *
3786 * setting it to the absolute drawscore. This has the same effect, *
3787 * but does let the evaluation guide the search to better moves when *
3788 * it is convinced all of them lead to draws. This version is about *
3789 * +100 Elo stronger than 23.0 based on cluster testing results. *
3790 * *
3791 * 23.2 Two changes related to draw handling. First, the 50-move draw *
3792 * rule is tricky. It is possible that the move on the 100th ply *
3793 * after the last non-reversible move might not be a draw, even if *
3794 * it is reversible itself, because it might deliver mate. In this *
3795 * specific case, the mate will end the game as a win. This has *
3796 * been fixed in Crafty to match this specific rule exception. Also *
3797 * draws by "insufficient material" have been changed to match the *
3798 * FIDE rules which say that mate can't be possible, even with worst *
3799 * possible play by the opponent. Crafty would claim a draw in a *
3800 * simple KN vs KN position, which is incorrect. Even though *
3801 * neither side can force mate, mate is possible and so the position *
3802 * is not a draw by FIDE rules. Mobility scoring changed for *
3803 * sliding pieces. Now the mobility scores are pre-computed and *
3804 * stored in a table that is addressed by the "magic number move *
3805 * generation idea". This completely eliminates the computational *
3806 * cost of the mobility scoring since all of the scores are pre- *
3807 * computed before the game starts. This was a modest speed *
3808 * improvement but really made the code simpler and smaller. Change *
3809 * to lazy eval cutoff code to improve accuracy. BookUP() had a *
3810 * minor bug that caused it to not report how many moves were not *
3811 * included because of the "maxply" limit. This has been fixed also *
3812 * so that it now reports the correct value. New xboard "cores" and *
3813 * "memory" command support added. Code to malloc() both was also *
3814 * rewritten completely to clean it up and simplify things. In an *
3815 * effort to avoid confusion, there is one caveat here. If your *
3816 * .craftyrc/crafty.rc file has an option to set the number of *
3817 * threads (mt=n/smpnt=n), then the "cores" option from xboard is *
3818 * automatically disabled so that the .craftyrc option effectively *
3819 * overrides any potential cores setting. If you set hash or hashp *
3820 * in the .craftyrc/crafty.rc file, then the "memory" option from *
3821 * xboard is automatically disabled, for the same reason. In short, *
3822 * you can let xboard set the number of threads and memory usage *
3823 * limit, or you can set them in your .craftyrc/crafty.rc file. But *
3824 * if you use the .craftyrc/crafty.rc file to set either, then the *
3825 * corresponding xboard command will be disabled. *
3826 * *
3827 * 23.3 Null-move search restriction changed to allow null-move searches *
3828 * at any node where the side on move has at least one piece of any *
3829 * type. Minor bug in ValidMove() fixed to catch "backward" pawn *
3830 * moves and flag them as illegal. This sometimes caused an error *
3831 * when annotating games and annotating for both sides. The killer *
3832 * move array could have "backward" moves due to flipping sides back *
3833 * and forth, which would cause some odd PV displays. Small change *
3834 * to "reduce-at-root". We no longer reduce moves that are flagged *
3835 * as "do not search in parallel". Check extension modified so that *
3836 * if "SEE" says the check is unsafe, the extension is not done. We *
3837 * found this to be worth about +10 Elo. We also now reduce any *
3838 * capture move that appears in the "REMAINING_MOVES" phase since *
3839 * they can only appear there if SEE returns a score indicating loss *
3840 * of material. We now reduce a bit more aggressively, reducing by` *
3841 * 2 plies once we have searched at least 4 moves at any ply. I *
3842 * tried going to 3 on very late moves, but could not find any case *
3843 * where this was better, even limiting it to near the root or other *
3844 * ideas. But reducing by 2 plies after the at least 2 moves are *
3845 * searched was an improvement. Minor change is that the first move *
3846 * is never reduced. It is possible that there is no hash move, no *
3847 * non-losing capture, and no killer move. That drops us into the *
3848 * REMAINING_MOVES phase which could reduce the first move searched, *
3849 * which was not intended. Very minor tweak, but a tweak all the *
3850 * same. *
3851 * *
3852 * 23.4 Bug in hash implementation fixed. It was possible to get a hash *
3853 * hit at ply=2, and alter the ply=1 PV when it should be left with *
3854 * no change. This could cause Crafty to display one move as best *
3855 * and play another move entirely. Usually this move was OK, but it *
3856 * could, on occasion, be an outright blunder. This has been fixed. *
3857 * The search.c code has been re-written to eliminate SearchRoot() *
3858 * entirely, which simplifies the code. The only duplication is in *
3859 * SearchParallel() which would be messier to eliminate. Ditto for *
3860 * quiesce.c, which now only has Quiesce() and QuiesceEvasions(). *
3861 * The old QuiesceChecks() has been combined with Quiesce, again to *
3862 * eliminate duplication and simplify the code. Stupid bug in code *
3863 * that handles time-out. One place checked the wrong variable and *
3864 * could cause a thread to attempt to output a PV after the search *
3865 * was in the process of timing out. That thread could back up an *
3866 * incomplete/bogus search result to the root in rare occasions, *
3867 * which would / could result in Crafty kibitzing one move but *
3868 * playing a different move. On occasion, the move played could be *
3869 * a horrible blunder. Minor bug caused StoreTransRef() to lose a *
3870 * best move when overwriting an old position with a null-move *
3871 * search result. Minor change by Tracy to lazy evaluation cutoff *
3872 * to speed up evaluation somewhat. Old "Trojan Horse" attack *
3873 * detection was removed. At today's depths, it was no longer *
3874 * needed. New hash idea stores the PV for an EXACT hash entry in a *
3875 * separate hash table. When an EXACT hit happens, this PV can be *
3876 * added to the incomplete PV we have so far so that we have the *
3877 * exact path that leads to the backed up score. New "phash" (path *
3878 * hash) command to set the number of entries in this path hash *
3879 * table. For longer searches, a larger table avoids path table *
3880 * collisions which will produce those short paths that end in <HT>. *
3881 * If <HT> appears in too many PVs, phash should be increased. The *
3882 * "Trojan Horse" code has been completely removed, which also *
3883 * resulted in the removal of the last bit of "pre-processing code" *
3884 * in preeval.c, so it has been completely removed as well. Current *
3885 * search depths are such that the Trojan Horse code is simply not *
3886 * needed any longer. A minor bug in TimeSet() fixed where on rare *
3887 * occasions, near the end of a time control, time_limit could be *
3888 * larger than the max time allowed (absolute_time_limit). We never *
3889 * check against this limit until we exceed the nominal time limit. *
3890 * Cleanup on the draw by repetition code to greatly simplify the *
3891 * code as well as speed it up. *
3892 * *
3893 * 23.5 Several pieces of code cleanup, both for readability and speed. *
3894 * We are now using stdint.h, which lets us specific the exact size *
3895 * of an integer value which gets rid of the int vs long issues that *
3896 * exist between MSVC and the rest of the world on X86_64. We still *
3897 * use things like "int" if we want to let the compiler choose the *
3898 * most efficient size, but when we need a specific number of bits, *
3899 * such as 64, we use a specific type (uint64_t for 64 bits). Minor *
3900 * change to forward pruning that does not toss out passed pawn *
3901 * moves if they are advanced enough (compared to remaining depth) *
3902 * that they might be worth searching. Cleanup to passed pawn eval *
3903 * code to help efficiency and readability. New options to the *
3904 * display command. "display nothing" turns all output off except *
3905 * for the move Crafty chooses to play. "display everything" will *
3906 * produce a veritable flood of information before it makes a move. *
3907 * Cleanup of personality code to fix some values that were not *
3908 * included, as well as clean up the formatting for simplicity. *
3909 * *
3910 * 23.6 Minor tweak to "adaptive hash" code + a fix to the usage warning *
3911 * that failed to explain how many parameters are required. New way *
3912 * of timing the search, replacing the old "easy move" code that was *
3913 * simply too ineffective. Now Crafty computes a "difficulty" level *
3914 * after each iteration. If the best move doesn't change, this *
3915 * level is reduced by 10% of the current value, until it reaches *
3916 * 60% where it stops dropping. If the best move changes during an *
3917 * iteration, it adjusts in one of two ways. If the current *
3918 * difficulty level is less than 100%, it reverts to 100% + the *
3919 * number of different best moves minus 1 times 20%. If the current *
3920 * difficulty level is already >= 100% it is set to 80% of the *
3921 * current value + (again) the number of different best moves - 1 *
3922 * times 20%. Repeated changes can run this up to 180% max. As the *
3923 * search progresses this difficulty level represents the percentage *
3924 * of the nominal target time limit it should use. It still tries *
3925 * to complete the current iteration before quitting, so this limit *
3926 * is a lower bound on the time it will use. Restored an old idea *
3927 * from earlier Crafty versions (and even Cray Blitz), that of *
3928 * trying the killers from two plies earlier in the tree, once the *
3929 * killers for the current ply have been tried. Was a +10 Elo gain, *
3930 * added to about +10 for the new time control logic. Old fail-high *
3931 * restriction removed. At one point in time, a fail-high on the *
3932 * null-window search at the root would cause problems. Crafty was *
3933 * modified so that the fail-high was ignored if the re-search *
3934 * failed low. Removing this produced an 8 Elo gain. *
3935 * *
3936 * 23.7 Minor fix to time check code. Was particularly broken at very *
3937 * low skill level settings, but it had a small impact everywhere. *
3938 * Some simplification with the reduction code, and how moves are *
3939 * counted as they are searched, which would not count any moves *
3940 * that were pruned, which could delay triggering reductions at a *
3941 * ply. Fixed significant killer move bug that would only surface *
3942 * during a parallel search. NextMove (remaining moves phase) culls *
3943 * killer moves as it selects, because they have already been tried. *
3944 * Unfortunately, in a parallel search, the killers could get *
3945 * modified by other threads, which could erroneously cause a move *
3946 * to be excluded that had not been searched. I discovered this bug *
3947 * on wac #266 where Crafty normally finds a mate at depth=11, but *
3948 * a parallel search would often miss the mate completely. Minor *
3949 * fix to new "difficulty" time management. It was possible for a *
3950 * move to look "easy" (several iterations without finding a new *
3951 * best move) but it could fail low at the beginning of the next *
3952 * iteration. Difficulty would be reduced due to not changing the *
3953 * best move at previous iterations, so the search could time out *
3954 * quicker than expected. Simple fix was to reset difficulty to *
3955 * 100% on a fail low, which makes sense anyway if it was supposed *
3956 * to be "easy" but the score is mysteriously dropping anyway. *
3957 * *
3958 * 23.8 MAXPLY changed to 128, which increases the max length of the PV's *
3959 * that can be displayed. The hash path stuff works so well that it *
3960 * often STILL has PVs with <HT> on the end, after 64 moves are *
3961 * displayed. While this can still probably be reached, it should *
3962 * be much less frequent. This does mean the search can go for 128 *
3963 * iterations, rather than the old 64 limit, of course. Bug in *
3964 * Search() that failed to update the PV on an EGTB hit, which would *
3965 * cause the hashed PV to contain illegal moves. When Crafty then *
3966 * tried to display this PV, it would promptly crash. *
3967 * *
3968 * 24.0 Major changes to portability/platform specific code. Crafty now *
3969 * supports Unix and Windows platforms. All the other spaghetti *
3970 * code has been removed, with an effort to make the code readable. *
3971 * Couple of bugs in EvaluateWinningChances() fixed, one in *
3972 * particular that makes the krp vs kr draw detection unreachable. *
3973 * strcpy() replaced with memmove() to fix problems with Apple OS X *
3974 * Mavericks where strcpy() with operands that overlap now causes an *
3975 * application to abort on the spot. Bug in Search() that caused an *
3976 * inefficiency in the parallel search. At some point the way moves *
3977 * are counted within a ply was changed, which changed the split *
3978 * algorithm unintentionally. The original intent was to search *
3979 * just one move and then allow splits. The bug changed this to *
3980 * search TWO moves before splitting is allowed, which slowed things *
3981 * down quite a bit. thread[i] is now an array of structures so *
3982 * that the thread pointers are separated from each other to fit *
3983 * into separate cache blocks, this avoids excessive cache traffic *
3984 * since they get changed regularly and were sitting in a single *
3985 * cache block with 8 cpus on 64 bit architectures. Bug in new *
3986 * "difficulty" time usage code would let the program run up against *
3987 * "absolute_time_limit" before stopping the search, even if we *
3988 * finished an iteration using beyond the normal target. This *
3989 * really burned a lot of unnecessary time. I had previously fixed *
3990 * the PVS window fail high (at the root) to force such a move to be *
3991 * played in the game. One unfortunate oversight however was that *
3992 * when splitting at the root, N different processors could fail *
3993 * high on N different moves, and they were searching those in *
3994 * parallel. I've modified this so that the PVS fail high at the *
3995 * root exits from Search() (after stopping other busy threads) and *
3996 * then returns to Iterate() which will print the fail-high notice *
3997 * and re-start the search with all threads searching just one fail *
3998 * high move to get a score quicker. Fail-high/fail-low code clean- *
3999 * up. In particular, the "delta" value to increment beta or *
4000 * decrement alpha is now two variables, so that an early fail-low *
4001 * won't increment the delta value and then the subsequent (hope- *
4002 * fully) fail-high starts off with a bad increment and jumps beta *
4003 * too quickly. All fail-highs at the root return to Iterate(), *
4004 * even the PVS null-window fail-highs. This re-starts the search *
4005 * with all processors working on that one move to get it resolved *
4006 * much quicker. Other minor fixes such as when failing low on the *
4007 * first move, we pop out of search and go back to Iterate() to *
4008 * lower alpha and start a new search. Unfortunately, after the *
4009 * first move is searched, a parallel split at the root would occur, *
4010 * only to be instantly aborted so that we could back out of Search()*
4011 * and then re-start. Wasted the split time unnecessarily although *
4012 * it was not a huge amount of time. Another simplification to the *
4013 * repetition-detection code while chasing a parallel search bug *
4014 * was missing repetitions. *
4015 * *
4016 * 24.1 LMR reductions changed to allow a more dynamic reduction amount *
4017 * rather than just 1 or 2. An array LMR_reductions[depth][moves] *
4018 * is initialized at start-up and sets the reduction amount for a *
4019 * specific depth remaining (larger reduction with more depth left) *
4020 * and the total moves searched at this node (again a larger *
4021 * reduction as more moves are searched.) This can easily be *
4022 * changed with the new "lmr" command (help lmr for details). The *
4023 * old "noise" stuff has been changed. Now, rather than noise *
4024 * specifying the number of nodes that have to be searched before *
4025 * any output is displayed (PV, fail high, etc) it now specifies a *
4026 * time that must pass before the first output is produced. This *
4027 * can still be displayed with noise=0, otherwise noise=n says no *
4028 * output until n seconds have passed (n can be a fraction of a *
4029 * second if wanted.) I restored the old adaptive null-move code, *
4030 * but changed the reduction (used to be 2 to 3 depending on the *
4031 * depth remaining) so that it is 3 + depth / 6. For each 6 plies *
4032 * of remaining depth, we reduce by another ply, with no real bound *
4033 * other than the max depth we can reasonably reach. The "6" in *
4034 * the above can be changed with the personality command or the new *
4035 * null m n command. When the changes to noise were made, Iterate() *
4036 * was also changed so that if the search terminates for any reason *
4037 * and no PV was displayed, whether because the noise limit was not *
4038 * satisfied or this search did not produce a PV because it started *
4039 * at an excessively deep search depth, Crafty now always displays *
4040 * at least one PV in the log file to show how the game is going to *
4041 * continue. One case where this was an issue was where Crafty did *
4042 * a LONG ponder search because the opponent took an excessive *
4043 * amount of time to make a move. If it finishes (say) a 30 ply *
4044 * search while pondering, when the opponent moves, Crafty will move *
4045 * instantly, but when it starts the next search, we start pondering *
4046 * at iteration 29, which might take a long time to finish. But we *
4047 * do still have the PV from the last search (the 30 ply one) and *
4048 * main() thoughtfully removed the first two moves (the move played *
4049 * and the move we are now pondering, so we always have something to *
4050 * display, and now we no longer terminate a search with no output *
4051 * (PV, time, etc) at all. Generation II of the parallel split code *
4052 * (see Thread() in the thread.c source file comments for specifics) *
4053 * that is a lighter-weight split/copy plus the individual threads *
4054 * do most of the copying rather than the thread that initiates the *
4055 * split. More work on the skill command. For each 10 units the *
4056 * skill level is reduced, the search speed is reduced by 50%. *
4057 * Additionally the null-move and LMR reduction values are also *
4058 * ramped down so that by the time skill drops below 10, there are *
4059 * no reductions left. *
4060 * *
4061 * 24.2 Bug in SetTime() fixed. The absolute time limit was set way too *
4062 * large in sudden death games (games with no secondary time control *
4063 * to add time on the clock) with an increment. It was intended to *
4064 * allow the search to use up to 5x the normal target time, unless *
4065 * that was larger than 1/2 of the total time remaining, but some- *
4066 * where along the way that 5x was removed and it always set the *
4067 * absolute time limit to 1/2 the remaining clock, which would burn *
4068 * clock time way too quickly. Complete re-factor of Search() to *
4069 * take the main loop and move that to a new procedure *
4070 * SearchMoveList() to eliminate the duplicated search code between *
4071 * Search() and SearchParallel() which has been replaced by *
4072 * SearchMoveList(). New addition to NextMove(). It was cleaned up *
4073 * to eliminate the old NextEvasion() code since one was a sub-set *
4074 * of the other. A minor change to limit the NPS impact on history *
4075 * ordering. We do not do history ordering within 6 plies of a *
4076 * terminal node, and we only try to order 1/2 of the moves before *
4077 * giving up and assuming this is an ALL node where ordering does *
4078 * not matter. *
4079 * *
4080 * 25.0 Complete re-factor of pawn evaluation code. There were too many *
4081 * overlapping terms that made tuning difficult. Now a pawn is *
4082 * classified as one specific class, there is no overlap between *
4083 * classes, which simplifies the code significantly. The code is *
4084 * now easier to understand and modify. In addition, the passed *
4085 * pawn evaluation was rewritten and consolidates all the passed *
4086 * pawn evaluation in one place. The evaluation used to add a bonus *
4087 * for rooks behind passed pawns in rook scoring, blockading some- *
4088 * where else, etc. All of this was moved to the passed pawn code *
4089 * to make it easier to understand and modify. A limited version of *
4090 * late move pruning (LMP) is used in the last two plies. Once a *
4091 * set number of moves have been searched with no fail high, non- *
4092 * interesting moves are simply skipped in a way similar to futility *
4093 * pruning. This version also contains a major rewrite of the *
4094 * parallel search code, now referred to as Generation II. It has a *
4095 * more lightweight split algorithm, that costs the parent MUCH less *
4096 * effort to split the search. The key is that now the individual *
4097 * "helper" threads do all the work, allocating a split block, *
4098 * copying the data from the parent, etc., rather than the parent *
4099 * doing it all. Gen II based on the DTS "late-join" idea so that a *
4100 * thread will try to join existing split points before it goes to *
4101 * the idle wait loop waiting for some other thread to split with *
4102 * it. In fact, this is now the basis for the new split method *
4103 * where the parent simply creates a split point by allocating a *
4104 * split block for itself, and then continuing the search, after the *
4105 * parent split block is marked as "joinable". Now any idle threads *
4106 * just "jump in" without the parent doing anything else, which *
4107 * means that currently idle threads will "join" this split block if *
4108 * they are in the "wait-for-work" spin loop, and threads that be- *
4109 * come idle also join in exactly the same way. This is MUCH more *
4110 * efficient, and also significantly reduces the number of split *
4111 * blocks needed during the search. We also now pre-split the *
4112 * search when we are reasonably close to the root of the tree, *
4113 * which is called a "gratuitous split. This leaves joinable split *
4114 * points laying around so that whenever a thread becomes idle, it *
4115 * can join in at these pre-existing split points immediately. We *
4116 * now use a much more conservative approach when dealing with fail *
4117 * highs at the root. Since LMR and such have introduced greater *
4118 * levels of search instability, we no longer trust a fail-high at *
4119 * the root if it fails low on the re-search. We maintain the last *
4120 * score returned for every root move, along with the PV. Either an *
4121 * exact score or the bound score that was returned. At the end of *
4122 * the iteration, we sort the root move list using the backed-up *
4123 * score as the sort key, and we play the move with the best score. *
4124 * This solves a particularly ugly issue where we get a score for *
4125 * the first move, then another move fails high, but then fails low *
4126 * and the re-search produces a score that is actually WORSE than *
4127 * the original best move. We still see that, but we always play *
4128 * the best move now. One other efficiency trick is that when the *
4129 * above happens, the search would tend to be less efficient since *
4130 * the best score for that fail-high/fail-low move is actually worse *
4131 * than the best move/score found so far. If this happens, the *
4132 * score is restored to the original best move score (in Search()) *
4133 * so that we continue searching with a good lower bound, not having *
4134 * to deal with moves that would fail high with this worse value, *
4135 * but not with the original best move's value. Minor change to *
4136 * history counters that now rely on a "saturating counter" idea. I *
4137 * wanted to avoid the aging idea, and it seemed to not be so clear *
4138 * that preferring history moves by the depth at which they were *
4139 * good was the way to go. I returned to a history counter idea I *
4140 * tested around 2005 but discarded, namely using a saturating *
4141 * counter. The idea is that a center value (at present 1024) *
4142 * represents a zero score. Decrementing it makes it worse, *
4143 * incrementing it makes it better. But to make it saturate at *
4144 * either end, I only reduce the counter by a fraction of its *
4145 * distance from the saturation point so that once it gets to either *
4146 * extreme value, it will not be modified further avoiding wrap- *
4147 * around. This basic idea was originally reported by Mark Winands *
4148 * in 2005. It seems to provide better results (slightly) on very *
4149 * deep searches. One impetus for this was an intent to fold this *
4150 * into a move so that I could sort the moves rather than doing the *
4151 * selection approach I currently use. However, this had a bad *
4152 * effect on testing, since history information is dynamic and is *
4153 * constantly changing, between two moves at the same ply in fact. *
4154 * The sort fixed the history counters to the value at the start of *
4155 * that ply. This was discarded after testing, but the history *
4156 * counter based on the saturating counter idea seemed to be OK and *
4157 * was left in even though it produced minimal Elo gain during *
4158 * testing. Change to the way moves are counted, to add a little *
4159 * more consistency to LMR. Now Next*() returns an order number *
4160 * that starts with 1 and monotonically increases, this order number *
4161 * is used for LMR and such decisions that vary things based on how *
4162 * far down the move list something occurs. Root move counting was *
4163 * particularly problematic with parallel searching, now things are *
4164 * at least "more consistent". The only negative impact is that now *
4165 * the move counter gets incremented even for illegal moves, but *
4166 * testing showed this was a no-change change with one thread, and *
4167 * the consistency with multiple threads made it useful. New method *
4168 * to automatically tune SMP parameters. The command is autotune *
4169 * and "help autotune" will explain how to run it. Added the *
4170 * "counter-move" heuristic for move ordering (Jos Uiterwijk, JICCA) *
4171 * which simply remembers a fail high move and the move at the *
4172 * previous ply. If the hash, captures or killer moves don't result *
4173 * in a fail high, this move is tried next. No significant cost, *
4174 * seems to reduce tree size noticeably. Added a follow-up idea *
4175 * based on the same idea, except we pair a move that fails high *
4176 * with the move two plies back, introducing a sort of "connection" *
4177 * between them. This is a sort of "plan" idea where the first move *
4178 * of the pair enables the second move to fail high. The benefit is *
4179 * that this introduces yet another pair of good moves that get *
4180 * ordered before history moves, and is therefore not subject to *
4181 * reduction. I have been unable to come up with a reference for *
4182 * this idea, but I believe I first saw it somewhere around the time *
4183 * Fruit showed up, I am thinking perhaps in the JICCA/JICGA. Any *
4184 * reference would be appreciated. Minor change to the way the PV *
4185 * and fail-hi/fail-low moves are displayed when pondering. Crafty *
4186 * now adds the ponder move to the front of the PV enclosed in ( ) *
4187 * so that it is always visible in console mode. The depths are *
4188 * reaching such extreme numbers the ponder move scrolls off the top *
4189 * of the screen when running in console mode or when "tail -f" is *
4190 * used to watch the log file while a game is in progress. This is *
4191 * a bit trickier than you might think since Crafty displays the *
4192 * game move numbers in the PV. Penalty for pawns on same color as *
4193 * bishop now only applies when there is one bishop. *
4194 * *
4195 * 25.1 Cleanup of NextMove() plus a minor ordering bug fix that would *
4196 * skip counter moves at ply = 2. Added NUMA code to force the hash *
4197 * tables to be spread across the numa nodes as equally as possible *
4198 * rather than all of the data sitting on just onenode. This makes *
4199 * one specific user policy important. BEFORE you set the hash size *
4200 * for any of the four hash tables, you should ALWAYS set the max *
4201 * threads limit first, so that the NUMA trick works correctly. Of *
4202 * course, if you do not use -DAFFINITY this is all irrelevant. The *
4203 * -DNUMA option has been removed. I no longer use any libnuma *
4204 * routines. A new "smpnuma" command is now used to enable/disable *
4205 * NUMA mode (which really only affects how the hash tables are *
4206 * cleared, all the other NUMA code works just fine no matter *
4207 * whether this is enabled or disabled. Fixed a bug with the xboard *
4208 * memory command that could overflow and cause preposterous malloc *
4209 * requests. Change to LMP that now enables it in the last 16 plies *
4210 * of search depth, although only the last 8-10 plies really have *
4211 * a chance for this to kick in unless there are more than 100 legal *
4212 * moves to try. Minor change to hash path in HashStore() that made *
4213 * it hard to store entries on the first search after the table was *
4214 * cleared. Removed Nalimov DTM EGTB code and converted to SYZYGY *
4215 * WDL/DTC tables instead (courtesy of Ronald de Man). This *
4216 * correctly handles the 50 move rule where the Nalimov tables *
4217 * would walk into forced draws (by 50 move rule) while convincing *
4218 * the search it was winning. Swindle mode now also activates when *
4219 * in a drawn ending with a material plus for the side on move, as *
4220 * well as when the best root move is a "cursed win" (forced win, *
4221 * but drawn because of the 50 move rule). This gives the non-EGTB *
4222 * opponent the opportunity to turn that 50 move draw into a loss. *
4223 * There are some changes in the scoring output as a result of this. *
4224 * The usual +/-MatNN scores show up for real mates, but when in *
4225 * EGTB endings, the scores are of the form Win or Lose with the *
4226 * appropriate sign correction (-Win means black is winning, +Lose *
4227 * means white is losing.) Basil Falcinelli contributed to the new *
4228 * syzygy code used in this version. Minor change to skill code to *
4229 * avoid altering search parameters since the speed reduction and *
4230 * randomness in the eval is more than enough to reduce the Elo. *
4231 * Minor change to HashProbe() where I now only update the AGE of an *
4232 * entry that matches the current hash signature if the entry *
4233 * actually causes a search termination, rather than updating it *
4234 * each time there is a signature match. If the search is not *
4235 * terminated on the spot, we have to store an entry when the search *
4236 * ends which will also overwrite the current exact match and update *
4237 * the age as well. Suggested by J. Wesley Cleveland on CCC. *
4238 * *
4239 * 25.2 Minor bug in the fail-high / fail-low code. Crafty is supposed *
4240 * to deal with the case where the first move produces a score, then *
4241 * a later move fails high but then produces a worse score. We are *
4242 * supposed to revert to the better move. An "optimization" made *
4243 * this fail, but it has been fixed here. "new" command removed as *
4244 * it is pretty difficult to restore everything once a game has been *
4245 * started. To start a new game, quit crafty and restart. Crafty *
4246 * now notifies xboard/winboard to do this automatically so using *
4247 * those interfaces requires no changes to anything. *
4248 * *
4249 *******************************************************************************
4250 */
main(int argc,char ** argv)4251 int main(int argc, char **argv) {
4252 TREE *tree;
4253 FILE *personality;
4254 int move, readstat, value = 0, i, v, result, draw_type;
4255 char announce[128];
4256
4257 #if defined(UNIX)
4258 char path[1024];
4259 struct passwd *pwd;
4260 #else
4261 char crafty_rc_file_spec[FILENAME_MAX];
4262 SYSTEM_INFO sysinfo;
4263 #endif
4264 #if defined(UNIX)
4265 hardware_processors = sysconf(_SC_NPROCESSORS_ONLN);
4266 #else
4267 GetSystemInfo(&sysinfo);
4268 hardware_processors = sysinfo.dwNumberOfProcessors;
4269 #endif
4270 /* Collect environmental variables */
4271 char *directory_spec = getenv("CRAFTY_BOOK_PATH");
4272
4273 if (directory_spec)
4274 strncpy(book_path, directory_spec, sizeof book_path);
4275 directory_spec = getenv("CRAFTY_LOG_PATH");
4276 if (directory_spec)
4277 strncpy(log_path, directory_spec, sizeof log_path);
4278 directory_spec = getenv("CRAFTY_TB_PATH");
4279 if (directory_spec)
4280 strncpy(tb_path, directory_spec, sizeof tb_path);
4281 directory_spec = getenv("CRAFTY_RC_PATH");
4282 if (directory_spec)
4283 strncpy(rc_path, directory_spec, sizeof rc_path);
4284 if (getenv("CRAFTY_XBOARD")) {
4285 Print(-1, "feature done=0\n");
4286 xboard_done = 0;
4287 } else if (argc > 1 && !strcmp(argv[1], "xboard")) {
4288 Print(-1, "feature done=0\n");
4289 xboard_done = 0;
4290 }
4291 /*
4292 ************************************************************
4293 * *
4294 * First, parse the command-line options and pick off the *
4295 * ones that need to be handled before any initialization *
4296 * is attempted (mainly path commands at present.) *
4297 * *
4298 ************************************************************
4299 */
4300 AlignedMalloc((void *) ((void *) &tree), 2048, (size_t) sizeof(TREE));
4301 block[0] = tree;
4302 memset((void *) block[0], 0, sizeof(TREE));
4303 tree->ply = 1;
4304 input_stream = stdin;
4305 for (i = 0; i < 512; i++)
4306 args[i] = (char *) malloc(256);
4307 if (argc > 1) {
4308 for (i = 1; i < argc; i++) {
4309 if (strstr(argv[i], "path") || strstr(argv[i], "log") ||
4310 strstr(argv[1], "affinity")) {
4311 strcpy(buffer, argv[i]);
4312 result = Option(tree);
4313 if (result == 0)
4314 Print(2048, "ERROR \"%s\" is unknown command-line option\n",
4315 buffer);
4316 display = tree->position;
4317 }
4318 }
4319 }
4320 /*
4321 ************************************************************
4322 * *
4323 * Now, read the crafty.rc/.craftyrc initialization file *
4324 * and process the commands that need to be handled prior *
4325 * to initializing things (path commands). *
4326 * *
4327 ************************************************************
4328 */
4329 #if defined(UNIX)
4330 input_stream = fopen(".craftyrc", "r");
4331 if (!input_stream)
4332 if ((pwd = getpwuid(getuid()))) {
4333 sprintf(path, "%s/.craftyrc", pwd->pw_dir);
4334 input_stream = fopen(path, "r");
4335 }
4336 if (input_stream)
4337 #else
4338 sprintf(crafty_rc_file_spec, "%s/crafty.rc", rc_path);
4339 if ((input_stream = fopen(crafty_rc_file_spec, "r")))
4340 #endif
4341 while (1) {
4342 readstat = Read(1, buffer);
4343 if (readstat < 0)
4344 break;
4345 if (!strstr(buffer, "path"))
4346 continue;
4347 result = Option(tree);
4348 if (result == 0)
4349 Print(2048, "ERROR \"%s\" is unknown rc-file option\n", buffer);
4350 if (input_stream == stdin)
4351 break;
4352 }
4353 /*
4354 ************************************************************
4355 * *
4356 * Initialize all data arrays and chess board. *
4357 * *
4358 ************************************************************
4359 */
4360 Initialize();
4361 /*
4362 ************************************************************
4363 * *
4364 * Now, parse the command-line options and pick off the *
4365 * ones that need to be handled after initialization is *
4366 * completed. *
4367 * *
4368 ************************************************************
4369 */
4370 if (argc > 1) {
4371 for (i = 1; i < argc; i++)
4372 if (strcmp(argv[i], "c"))
4373 if (!strstr(argv[i], "path")) {
4374 if (strlen(argv[i]) > 255)
4375 Print(-1, "ERROR ignoring token %s, 255 character max\n",
4376 argv[i]);
4377 else {
4378 strcpy(buffer, argv[i]);
4379 Print(32, "(info) command line option \"%s\"\n", buffer);
4380 result = Option(tree);
4381 if (result == 0)
4382 Print(2048, "ERROR \"%s\" is unknown command-line option\n",
4383 buffer);
4384 }
4385 }
4386 }
4387 display = tree->position;
4388 initialized = 1;
4389 move_actually_played = 0;
4390 /*
4391 ************************************************************
4392 * *
4393 * Next, read the crafty.rc/.craftyrc initialization file *
4394 * and process the commands that need to be handled after *
4395 * engine initialization has been completed. *
4396 * *
4397 ************************************************************
4398 */
4399 #if defined(UNIX)
4400 input_stream = fopen(".craftyrc", "r");
4401 if (!input_stream)
4402 if ((pwd = getpwuid(getuid()))) {
4403 sprintf(path, "%s/.craftyrc", pwd->pw_dir);
4404 input_stream = fopen(path, "r");
4405 }
4406 if (input_stream) {
4407 #else
4408 sprintf(crafty_rc_file_spec, "%s/crafty.rc", rc_path);
4409 if ((input_stream = fopen(crafty_rc_file_spec, "r"))) {
4410 #endif
4411 while (1) {
4412 readstat = Read(1, buffer);
4413 if (readstat < 0)
4414 break;
4415 if (strstr(buffer, "path"))
4416 continue;
4417 result = Option(tree);
4418 if (result == 0)
4419 Print(2048, "ERROR \"%s\" is unknown rc-file option\n", buffer);
4420 if (input_stream == stdin)
4421 break;
4422 }
4423 }
4424 input_stream = stdin;
4425 #if defined(UNIX)
4426 if (xboard)
4427 signal(SIGINT, SIG_IGN);
4428 #endif
4429 if (smp_max_threads)
4430 Print(32, "\nCrafty v%s (%d threads)\n\n", version, smp_max_threads);
4431 else
4432 Print(32, "\nCrafty v%s\n\n", version);
4433 if (hardware_processors > 0)
4434 Print(32, "machine has %d processors\n\n", hardware_processors);
4435
4436 /*
4437 ************************************************************
4438 * *
4439 * Check to see if we can find a "crafty.cpf" personality *
4440 * file which contains the default personality settings to *
4441 * be used unless overridden by the user. *
4442 * *
4443 ************************************************************
4444 */
4445 if ((personality = fopen("crafty.cpf", "r"))) {
4446 fclose(personality);
4447 Print(-1, "using default personality file \"crafty.cpf\"\n");
4448 sprintf(buffer, "personality load crafty.cpf");
4449 Option(tree);
4450 }
4451 /*
4452 ************************************************************
4453 * *
4454 * This is the "main loop" that never ends unless the user *
4455 * tells Crafty to "quit". We read commands/moves, *
4456 * execute them, and when a move is entered we change *
4457 * sides and execute a search to find a reply. We repeat *
4458 * this until the game ends or the opponent gets tired and *
4459 * tells us to terminate the engine. *
4460 * *
4461 * Prompt user and read input string for processing. As *
4462 * long as Option() returns a non-zero value, continue *
4463 * reading lines and calling Option(). When Option() *
4464 * fails to recogize a command, then try InputMove() to *
4465 * determine if this is a legal move. *
4466 * *
4467 * While we are waiting on a move, we call Ponder() which *
4468 * will find a move that it assumes the opponent will *
4469 * make, and then it will call Iterate() to find a reply *
4470 * for that move while we are waiting to see what is *
4471 * actually played in the game. Ponder() will return one *
4472 * of the following "results" (stored in "presult"): *
4473 * *
4474 * (0) This indicates that Ponder() did not run, either *
4475 * because pondering is disabled, or we are not in a *
4476 * state where pondering is allowed, such as using the *
4477 * xboard "force" command to set up a game that will *
4478 * be continued. *
4479 * *
4480 * (1) This indicates that we pondered a move, the *
4481 * opponent actually played this move, and we were *
4482 * able to complete a normal search for the proper *
4483 * amount of time and have a move ready to use. *
4484 * *
4485 * (2) This indicates that we pondered a move, but that *
4486 * for some reason, we did not need to continue until *
4487 * time ran out. For example, we found a forced mate *
4488 * and further searching is not needed. The search is *
4489 * not "in progress" but we still have a valid move *
4490 * to play here. *
4491 * *
4492 * (3) We pondered, but the opponent either played a *
4493 * different move, or else entered a command that *
4494 * forces us to unwind the search so that the command *
4495 * can be executed. In this case, we will re-start *
4496 * pondering, otherwise we make the correct move and *
4497 * then start a normal search. *
4498 * *
4499 ************************************************************
4500 */
4501 /*
4502 ************************************************************
4503 * *
4504 * From this point forward, we are in a state where it is *
4505 * *
4506 * O P P O N E N T ' S turn to move. *
4507 * *
4508 ************************************************************
4509 */
4510 while (1) {
4511 presult = 0;
4512 do {
4513 opponent_start_time = ReadClock();
4514 input_status = 0;
4515 display = tree->position;
4516 move = 0;
4517 presult = 0;
4518 if (xboard_done == 0 && xboard) {
4519 xboard_done = 1;
4520 Print(-1, "feature done=1\n");
4521 }
4522 do {
4523 if (presult != 2)
4524 presult = 0;
4525 result = 0;
4526 if (pong) {
4527 Print(-1, "pong %d\n", pong);
4528 pong = 0;
4529 }
4530 display = tree->position;
4531 if (presult != 2 && (move_number != 1 || !game_wtm))
4532 presult = Ponder(game_wtm);
4533 if (presult == 1)
4534 value = last_root_value;
4535 else if (presult == 2)
4536 value = ponder_value;
4537 if (presult == 0 || presult == 2) {
4538 if (!xboard) {
4539 printf("%s(%d): ", SideToMove(game_wtm), move_number);
4540 fflush(stdout);
4541 }
4542 readstat = Read(1, buffer);
4543 if (log_file)
4544 fprintf(log_file, "%s(%d): %s\n", SideToMove(game_wtm),
4545 move_number, buffer);
4546 if (readstat < 0 && input_stream == stdin) {
4547 strcpy(buffer, "end");
4548 Option(tree);
4549 }
4550 }
4551 if (presult == 1)
4552 break;
4553 opponent_end_time = ReadClock();
4554 result = Option(tree);
4555 if (result == 0) {
4556 nargs = ReadParse(buffer, args, " \t;");
4557 move = InputMove(tree, 0, game_wtm, 0, 0, args[0]);
4558 result = !move;
4559 if (move)
4560 last_pv.path[1] = 0;
4561 } else {
4562 input_status = 0;
4563 if (result == 3)
4564 presult = 0;
4565 }
4566 } while (result > 0);
4567 if (presult == 1)
4568 move = ponder_move;
4569 /*
4570 ************************************************************
4571 * *
4572 * We have a move. Make the move (returned by InputMove) *
4573 * and then change the side on move (wtm). *
4574 * *
4575 ************************************************************
4576 */
4577 if (result == 0) {
4578 fseek(history_file, ((move_number - 1) * 2 + 1 - game_wtm) * 10,
4579 SEEK_SET);
4580 fprintf(history_file, "%9s\n", OutputMove(tree, 0, game_wtm, move));
4581 MakeMoveRoot(tree, game_wtm, move);
4582 tree->curmv[0] = move;
4583 time_used_opponent = opponent_end_time - opponent_start_time;
4584 if (!force)
4585 Print(1, " time used: %s\n",
4586 DisplayTime(time_used_opponent));
4587 TimeAdjust(game_wtm, time_used_opponent);
4588 game_wtm = Flip(game_wtm);
4589 if (game_wtm)
4590 move_number++;
4591 move_actually_played = 1;
4592 last_opponent_move = move;
4593 /*
4594 ************************************************************
4595 * *
4596 * From this point forward, we are in a state where it is *
4597 * *
4598 * C R A F T Y ' S turn to move. *
4599 * *
4600 ************************************************************
4601 */
4602 /*
4603 ************************************************************
4604 * *
4605 * We have made the indicated move, before we do a search *
4606 * we need to determine if the present position is a draw *
4607 * by rule. If so, Crafty allowed it to happen and must *
4608 * be satisfied with a draw, so we will claim it and end *
4609 * the current game. *
4610 * *
4611 ************************************************************
4612 */
4613 if ((draw_type = Repeat3x(tree)) == 1) {
4614 Print(1, "I claim a draw by 3-fold repetition.\n");
4615 value = DrawScore(game_wtm);
4616 if (xboard)
4617 Print(-1, "1/2-1/2 {Drawn by 3-fold repetition}\n");
4618 }
4619 if (draw_type == 2) {
4620 if (!Mated(tree, 0, game_wtm)) {
4621 Print(1, "I claim a draw by the 50 move rule.\n");
4622 value = DrawScore(game_wtm);
4623 if (xboard)
4624 Print(-1, "1/2-1/2 {Drawn by 50-move rule}\n");
4625 }
4626 }
4627 if (Drawn(tree, last_search_value) == 2) {
4628 Print(1, "I claim a draw due to insufficient material.\n");
4629 if (xboard)
4630 Print(-1, "1/2-1/2 {Insufficient material}\n");
4631 }
4632 } else
4633 presult = 0;
4634 #if defined(DEBUG)
4635 ValidatePosition(tree, 0, move, "Main(1)");
4636 #endif
4637 } while (force);
4638 /*
4639 ************************************************************
4640 * *
4641 * Now call Iterate() to compute a move for the current *
4642 * position. (Note this is not done if Ponder() has al- *
4643 * ready computed a move.) *
4644 * *
4645 ************************************************************
4646 */
4647 crafty_is_white = game_wtm;
4648 if (presult == 2) {
4649 if (From(ponder_move) == From(move) && To(ponder_move) == To(move)
4650 && Piece(ponder_move) == Piece(move)
4651 && Captured(ponder_move) == Captured(move)
4652 && Promote(ponder_move) == Promote(move)) {
4653 presult = 1;
4654 if (!book_move)
4655 predicted++;
4656 } else
4657 presult = 0;
4658 }
4659 ponder_move = 0;
4660 thinking = 1;
4661 if (presult != 1) {
4662 strcpy(kibitz_text, "n/a");
4663 last_pv.pathd = 0;
4664 last_pv.pathl = 0;
4665 display = tree->position;
4666 tree->status[1] = tree->status[0];
4667 value = Iterate(game_wtm, think, 0);
4668 }
4669 /*
4670 ************************************************************
4671 * *
4672 * We've now completed a search and need to handle a *
4673 * pending draw offer based on what the search found. *
4674 * *
4675 * When we get a draw offer, we make a note, but we do not *
4676 * accept it until after we have a chance to see what *
4677 * happens after making the opponent's move that came with *
4678 * the draw offer. If he played a blunder, we are not *
4679 * going to mistakenly accept a draw when we are now *
4680 * winning. We make this decision to accept or decline *
4681 * since we have completed as search and now have a real *
4682 * score. *
4683 * *
4684 ************************************************************
4685 */
4686 if (draw_offer_pending) {
4687 int drawsc = abs_draw_score;
4688
4689 draw_offer_pending = 0;
4690 if (move_number < 40 || !accept_draws)
4691 drawsc = -300;
4692 if (value <= drawsc && (tc_increment != 0 ||
4693 tc_time_remaining[Flip(game_wtm)] >= 1000)) {
4694 if (xboard)
4695 Print(-1, "offer draw\n");
4696 else {
4697 Print(1, "Draw accepted.\n");
4698 if (audible_alarm)
4699 printf("%c", audible_alarm);
4700 if (speech) {
4701 strcpy(announce, "./speak ");
4702 strcat(announce, "Drawaccept");
4703 v = system(announce);
4704 if (v != 0)
4705 perror("main() system() error: ");
4706 }
4707 }
4708 Print(-1, "1/2-1/2 {Draw agreed}\n");
4709 strcpy(pgn_result, "1/2-1/2");
4710 } else {
4711 if (!xboard) {
4712 Print(1, "Draw declined.\n");
4713 if (speech) {
4714 strcpy(announce, "./speak ");
4715 strcat(announce, "Drawdecline");
4716 v = system(announce);
4717 if (v != 0)
4718 perror("main() system() error: ");
4719 }
4720 }
4721 }
4722 }
4723 /*
4724 ************************************************************
4725 * *
4726 * If the last_pv.path is null, then we were either *
4727 * checkmated or stalemated. We need to determine which *
4728 * and end the game appropriately. *
4729 * *
4730 * If we do have a PV, we will also check to see if it *
4731 * leads to mate and make the proper announcement if so. *
4732 * *
4733 ************************************************************
4734 */
4735 last_pv = tree->pv[0];
4736 last_value = value;
4737 if (MateScore(last_value))
4738 last_mate_score = last_value;
4739 thinking = 0;
4740 if (!last_pv.pathl) {
4741 if (Check(game_wtm)) {
4742 over = 1;
4743 if (game_wtm) {
4744 Print(-1, "0-1 {Black mates}\n");
4745 strcpy(pgn_result, "0-1");
4746 } else {
4747 Print(-1, "1-0 {White mates}\n");
4748 strcpy(pgn_result, "1-0");
4749 }
4750 if (speech) {
4751 strcpy(announce, "./speak ");
4752 strcat(announce, "Checkmate");
4753 v = system(announce);
4754 if (v != 0)
4755 perror("main() system() error: ");
4756 }
4757 } else {
4758 over = 1;
4759 if (!xboard) {
4760 Print(1, "stalemate\n");
4761 if (speech) {
4762 strcpy(announce, "./speak ");
4763 strcat(announce, "Stalemate");
4764 v = system(announce);
4765 if (v != 0)
4766 perror("main() system() error: ");
4767 }
4768 } else
4769 Print(-1, "1/2-1/2 {stalemate}\n");
4770 }
4771 } else {
4772 if (value > 32000 && value < MATE - 2) {
4773 Print(1, "\nmate in %d moves.\n\n", (MATE - value) / 2);
4774 Kibitz(1, game_wtm, 0, 0, (MATE - value) / 2, tree->nodes_searched, 0,
4775 0, " ");
4776 } else if (-value > 32000 && -value < MATE - 1) {
4777 Print(1, "\nmated in %d moves.\n\n", (MATE + value) / 2);
4778 Kibitz(1, game_wtm, 0, 0, -(MATE + value) / 2, tree->nodes_searched,
4779 0, 0, " ");
4780 }
4781 /*
4782 ************************************************************
4783 * *
4784 * See if we want to offer a draw based on the recent *
4785 * scores that have been returned. See resign.c for more *
4786 * details, but this is where we offer a draw, or resign, *
4787 * if appropriate. This has nothing to do with claiming a *
4788 * draw by rule, which is done later. *
4789 * *
4790 ************************************************************
4791 */
4792 tree->status[MAXPLY] = tree->status[0];
4793 ResignOrDraw(tree, value);
4794 /*
4795 ************************************************************
4796 * *
4797 * Now output the move chosen by the search, and the *
4798 * "result" string if this move checkmates our opponent. *
4799 * *
4800 ************************************************************
4801 */
4802 if (speech) {
4803 char *moveptr = OutputMove(tree, 0, game_wtm, last_pv.path[1]);
4804
4805 strcpy(announce, "./speak ");
4806 strcat(announce, moveptr);
4807 strcat(announce, " &");
4808 v = system(announce);
4809 if (v != 0)
4810 perror("main() system() error: ");
4811 }
4812 if (!xboard && audible_alarm)
4813 printf("%c", audible_alarm);
4814 Print(1, "%s(%d): %s\n", SideToMove(game_wtm), move_number,
4815 OutputMove(tree, 0, game_wtm, last_pv.path[1]));
4816 if (xboard)
4817 printf("move %s\n", OutputMove(tree, 0, game_wtm, last_pv.path[1]));
4818 fflush(stdout);
4819 if (value == MATE - 2) {
4820 if (game_wtm) {
4821 Print(-1, "1-0 {White mates}\n");
4822 strcpy(pgn_result, "1-0");
4823 } else {
4824 Print(-1, "0-1 {Black mates}\n");
4825 strcpy(pgn_result, "0-1");
4826 }
4827 }
4828 time_used = program_end_time - program_start_time;
4829 Print(1, " time used: %s\n", DisplayTime(time_used));
4830 TimeAdjust(game_wtm, time_used);
4831 fseek(history_file, ((move_number - 1) * 2 + 1 - game_wtm) * 10,
4832 SEEK_SET);
4833 fprintf(history_file, "%9s\n", OutputMove(tree, 0, game_wtm,
4834 last_pv.path[1]));
4835 last_search_value = value;
4836 if (kibitz) {
4837 if (kibitz_depth)
4838 Kibitz(2, game_wtm, kibitz_depth, end_time - start_time, value,
4839 tree->nodes_searched, busy_percent, tree->egtb_hits,
4840 kibitz_text);
4841 else
4842 Kibitz(4, game_wtm, 0, 0, 0, 0, 0, 0, kibitz_text);
4843 }
4844 MakeMoveRoot(tree, game_wtm, last_pv.path[1]);
4845 tree->curmv[0] = move;
4846 /*
4847 ************************************************************
4848 * *
4849 * From this point forward, we are in a state where it is *
4850 * *
4851 * O P P O N E N T ' S turn to move. *
4852 * *
4853 * We have made the indicated move, we need to determine *
4854 * if the present position is a draw by rule. If so, we *
4855 * need to send the appropriate game result to xboard *
4856 * and/or inform the operator/opponent. *
4857 * *
4858 ************************************************************
4859 */
4860 game_wtm = Flip(game_wtm);
4861 if (game_wtm)
4862 move_number++;
4863 move_actually_played = 1;
4864 if ((draw_type = Repeat3x(tree)) == 1) {
4865 Print(1, "I claim a draw by 3-fold repetition after my move.\n");
4866 if (xboard)
4867 Print(-1, "1/2-1/2 {Drawn by 3-fold repetition}\n");
4868 value = DrawScore(game_wtm);
4869 }
4870 if (draw_type == 2 && last_search_value < 32000) {
4871 Print(1, "I claim a draw by the 50 move rule after my move.\n");
4872 if (xboard)
4873 Print(-1, "1/2-1/2 {Drawn by 50-move rule}\n");
4874 value = DrawScore(game_wtm);
4875 }
4876 if (Drawn(tree, last_search_value) == 2) {
4877 Print(1,
4878 "I claim a draw due to insufficient material after my move.\n");
4879 if (xboard)
4880 Print(-1, "1/2-1/2 {Insufficient material}\n");
4881 }
4882 #if !defined(TEST)
4883 if (time_limit > 300)
4884 #endif
4885 if (log_file)
4886 DisplayChessBoard(log_file, tree->position);
4887 /*
4888 ************************************************************
4889 * *
4890 * Save the ponder_move from the current principal *
4891 * variation, then shift it left two moves to use as the *
4892 * starting point for the next search. Adjust the depth *
4893 * to start the next search at the right iteration. *
4894 * *
4895 ************************************************************
4896 */
4897 if (last_pv.pathl > 2 && VerifyMove(tree, 0, game_wtm, last_pv.path[2])) {
4898 ponder_move = last_pv.path[2];
4899 for (i = 1; i < (int) last_pv.pathl - 2; i++)
4900 last_pv.path[i] = last_pv.path[i + 2];
4901 last_pv.pathl = (last_pv.pathl > 2) ? last_pv.pathl - 2 : 0;
4902 last_pv.pathd -= 2;
4903 if (last_pv.pathd > last_pv.pathl)
4904 last_pv.pathd = last_pv.pathl;
4905 if (last_pv.pathl == 0)
4906 last_pv.pathd = 0;
4907 tree->pv[0] = last_pv;
4908 } else {
4909 last_pv.pathd = 0;
4910 last_pv.pathl = 0;
4911 ponder_move = 0;
4912 tree->pv[0] = last_pv;
4913 }
4914 }
4915 #if defined(TEST)
4916 strcpy(buffer, "score");
4917 Option(tree);
4918 #endif
4919 if ((i = GameOver(game_wtm))) {
4920 if (i == 1)
4921 Print(-1, "1/2-1/2 {stalemate}\n");
4922 }
4923 if (book_move) {
4924 moves_out_of_book = 0;
4925 predicted++;
4926 if (ponder_move)
4927 sprintf(book_hint, "%s", OutputMove(tree, 0, game_wtm, ponder_move));
4928 } else
4929 moves_out_of_book++;
4930 #if defined(DEBUG)
4931 ValidatePosition(tree, 0, last_pv.path[1], "Main(2)");
4932 #endif
4933 /*
4934 ************************************************************
4935 * *
4936 * Now execute LearnValue() to record the scores for the *
4937 * first N searches out of book. see learn.c for details *
4938 * on how this is used and when. *
4939 * *
4940 ************************************************************
4941 */
4942 if (learning && moves_out_of_book && !learn_value)
4943 LearnValue(last_value, last_pv.pathd + 2);
4944 if (learn_positions_count < 63) {
4945 learn_seekto[learn_positions_count] = book_learn_seekto;
4946 learn_key[learn_positions_count] = book_learn_key;
4947 learn_nmoves[learn_positions_count++] = book_learn_nmoves;
4948 }
4949 if (mode == tournament_mode) {
4950 strcpy(buffer, "clock");
4951 Option(tree);
4952 Print(32, "if clocks are wrong, use 'settc' command to adjust them\n");
4953 }
4954 }
4955 }
4956