Subversion Repositories Games.Chess Giants

Rev

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

Rev 33 Rev 108
Line 2... Line 2...
2
#include "data.h"
2
#include "data.h"
3
#if defined(UNIX)
3
#if defined(UNIX)
4
#  include <unistd.h>
4
#  include <unistd.h>
5
#  include <pwd.h>
5
#  include <pwd.h>
6
#  include <sys/types.h>
6
#  include <sys/types.h>
7
#endif
-
 
8
#if defined(NUMA) && defined(UNIX)
-
 
9
#  include <numa.h>
-
 
10
#endif
7
#endif
11
#include <signal.h>
8
#include <signal.h>
12
/* last modified 02/24/14 */
9
/* last modified 02/24/14 */
13
/*
10
/*
14
 *******************************************************************************
11
 *******************************************************************************
15
 *                                                                             *
12
 *                                                                             *
16
 *  Crafty, copyright 1996-2011 by Robert M. Hyatt, Ph.D., Associate Professor *
13
 *  Crafty, copyright 1996-2015 by Robert M. Hyatt, Ph.D., Associate Professor *
17
 *  of Computer and Information Sciences, University of Alabama at Birmingham. *
14
 *  of Computer and Information Sciences, University of Alabama at Birmingham. *
18
 *                                                                             *
15
 *                                                                             *
19
 *  Crafty is a team project consisting of the following members.  These are   *
16
 *  Crafty is a team project consisting of the following members.  These are   *
20
 *  the people involved in the continuing development of this program, there   *
17
 *  the people involved in the continuing development of this program, there   *
21
 *  are no particular members responsible for any specific aspect of Crafty,   *
18
 *  are no particular members responsible for any specific aspect of Crafty,   *
22
 *  although R. Hyatt wrote 99%+ of the existing code, excepting the Magic .   *
19
 *  although R. Hyatt wrote 99%+ of the existing code, excepting the Magic .   *
23
 *  move stuff by Pradu Kanan, egtb.cpp written by Eugene Nalimov, and the epd *
20
 *  move stuff by Pradu Kaanan, egtb.cpp written by Eugene Nalimov, and the    *
24
 *  stuff written by S. Edwards.                                               *
21
 *  epd stuff written by S. Edwards.                                           *
25
 *                                                                             *
22
 *                                                                             *
26
 *     Robert Hyatt, University of Alabama at Birmingham.                      *
23
 *     Robert Hyatt, University of Alabama at Birmingham.                      *
-
 
24
 *     Mike Byrne, Pen Argyl, PA.                                              *
27
 *     Tracy Riegle, Hershey, PA.                                              *
25
 *     Tracy Riegle, Hershey, PA.                                              *
28
 *     Peter Skinner, Edmonton, AB  Canada.                                    *
26
 *     Peter Skinner, Edmonton, AB  Canada.                                    *
29
 *                                                                             *
27
 *                                                                             *
30
 *  All rights reserved.  No part of this program may be reproduced in any     *
28
 *  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        *
29
 *  form or by any means, for other than your personal use, without the        *
Line 276... Line 274...
276
 *           one side is "in distress" pieces are attracted to that king in    *
274
 *           one side is "in distress" pieces are attracted to that king in    *
277
 *           "big hurry" to either attack or defend.                           *
275
 *           "big hurry" to either attack or defend.                           *
278
 *                                                                             *
276
 *                                                                             *
279
 *    3.4    "Threat extensions" added.  Simply, this is a null-move search    *
277
 *    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  *
278
 *           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    *
279
 *           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 *
280
 *           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     *
281
 *           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 *
282
 *           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  *
283
 *           might be a horizon move.  To test this, re-search this move with  *
286
 *           the depth increased by one.                                       *
284
 *           the depth increased by one.                                       *
Line 377... Line 375...
377
 *           a normal evaluation and/or further search is futile, this test    *
375
 *           a normal evaluation and/or further search is futile, this test    *
378
 *           has been moved to inside the loop *before* Quiesce() is           *
376
 *           has been moved to inside the loop *before* Quiesce() is           *
379
 *           recursively called, avoiding the MakeMove() work only to          *
377
 *           recursively called, avoiding the MakeMove() work only to          *
380
 *           discover that the resulting position won't be searched further.   *
378
 *           discover that the resulting position won't be searched further.   *
381
 *                                                                             *
379
 *                                                                             *
382
 *    5.4    New Swap() function that now understands indirect attacks through *
380
 *    5.4    New SEE() function that now understands indirect attacks through  *
383
 *           the primary attacking piece(s).  This corrects a lot of sloppy    *
381
 *           the primary attacking piece(s).  This corrects a lot of sloppy    *
384
 *           move ordering as well as make the "futility" cutoffs added in     *
382
 *           move ordering as well as make the "futility" cutoffs added in     *
385
 *           in version 5.3 much more reliable.                                *
383
 *           in version 5.3 much more reliable.                                *
386
 *                                                                             *
384
 *                                                                             *
387
 *    5.5    Checks are now back in the quiescence search.  Crafty now stores  *
385
 *    5.5    Checks are now back in the quiescence search.  Crafty now stores  *
Line 391... Line 389...
391
 *           to cause some tactical oversights in the search.                  *
389
 *           to cause some tactical oversights in the search.                  *
392
 *                                                                             *
390
 *                                                                             *
393
 *    5.6    Improved move ordering by using the old "killer move" idea.  An   *
391
 *    5.6    Improved move ordering by using the old "killer move" idea.  An   *
394
 *           additional advantage is that the killers can be tried before      *
392
 *           additional advantage is that the killers can be tried before      *
395
 *           generating any moves (after the captures.)  Quiescence now only   *
393
 *           generating any moves (after the captures.)  Quiescence now only   *
396
 *           includes "safe" checks (using Swap() to determine if it is a safe *
394
 *           includes "safe" checks (using SEE() to determine if it is a safe  *
397
 *           checking move.                                                    *
395
 *           checking move.                                                    *
398
 *                                                                             *
396
 *                                                                             *
399
 *    5.7    King safety now "hates" a pawn at b3/g3 (white) or b6/g6 (black)  *
397
 *    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.                      *
398
 *           to try and avoid the resulting mate threats.                      *
401
 *                                                                             *
399
 *                                                                             *
Line 485... Line 483...
485
 *           is no longer done if the major scoring contributors in Evaluate() *
483
 *           is no longer done if the major scoring contributors in Evaluate() *
486
 *           haven't pulled the score within the alpha/beta window, and the    *
484
 *           haven't pulled the score within the alpha/beta window, and the    *
487
 *           remainder of Evaluate() can't possible accomplish this either.    *
485
 *           remainder of Evaluate() can't possible accomplish this either.    *
488
 *           Gross error in EvaluatePawns() fixed, which would "forget" all    *
486
 *           Gross error in EvaluatePawns() fixed, which would "forget" all    *
489
 *           of the pawn scoring done up to the point where doubled white      *
487
 *           of the pawn scoring done up to the point where doubled white      *
490
 *           pawns were found.  error was xx=+ rather than xx+=, which had     *
488
 *           pawns were found.  Error was xx=+ rather than xx+=, which had     *
491
 *           an extremely harmful effect on pawn structure evaluation.         *
489
 *           an extremely harmful effect on pawn structure evaluation.         *
492
 *                                                                             *
490
 *                                                                             *
493
 *    7.4    Performance improvements produced by elimination of bit-fields.   *
491
 *    7.4    Performance improvements produced by elimination of bit-fields.   *
494
 *           This was accomplished by hand-coding the necessary ANDs, ORs, and *
492
 *           This was accomplished by hand-coding the necessary ANDs, ORs, and *
495
 *           SHIFTs necessary to accomplish the same thing, only faster.       *
493
 *           SHIFTs necessary to accomplish the same thing, only faster.       *
Line 634... Line 632...
634
 *           to edit Makefile and set "target" to the appropriate value from   *
632
 *           to edit Makefile and set "target" to the appropriate value from   *
635
 *           the list provided.  Then, when getting a new version, save your   *
633
 *           the list provided.  Then, when getting a new version, save your   *
636
 *           Makefile, extract the new source, copy in your makefile and you   *
634
 *           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  *
635
 *           will be ready, except for those rare occasions where I add a new  *
638
 *           source module.  Other changes are performance tweaks.  One is a   *
636
 *           source module.  Other changes are performance tweaks.  One is a   *
639
 *           simple trick to order captures while avoiding Swap() if possible. *
637
 *           simple trick to order captures while avoiding SEE() if possible.  *
640
 *           If the captured piece is more valuable than the capturing piece,  *
638
 *           If the captured piece is more valuable than the capturing piece,  *
641
 *           we can simply use the difference (pessimistic value) rather than  *
639
 *           we can simply use the difference (pessimistic value) rather than  *
642
 *           calling Swap() since this pessimistic value is still > 0.  Other  *
640
 *           calling SEE() since this pessimistic value is still > 0.  Other   *
643
 *           tweaks to the various Next_*() routines to avoid a little un-     *
641
 *           tweaks to the various Next_*() routines to avoid a little un-     *
644
 *           necessary work.                                                   *
642
 *           necessary work.                                                   *
645
 *                                                                             *
643
 *                                                                             *
646
 *    8.18   Book move selection algorithm changed.  Note that this is highly  *
644
 *    8.18   Book move selection algorithm changed.  Note that this is highly  *
647
 *           speculative, but when best book play is selected, Crafty will     *
645
 *           speculative, but when best book play is selected, Crafty will     *
Line 721... Line 719...
721
 *                                                                             *
719
 *                                                                             *
722
 *    8.22   EPD support (courtesy of Steven Edwards [thanks]) is now standard *
720
 *    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  *
721
 *           in Crafty.  For porting, I'll provide a small test run which can  *
724
 *           be used to validate Crafty once it's been compiled.               *
722
 *           be used to validate Crafty once it's been compiled.               *
725
 *                                                                             *
723
 *                                                                             *
726
 *    8.23   Cleanup/speedup in hashing.  HashProbe() and HashStore() now      *
724
 *    8.23   Cleanup/speedup in hashing.  ProbeTransRef() and StoreTransRef()  *
727
 *           carefully cast the boolean operations to the most efficient size  *
725
 *           now carefully cast the boolean operations to the most efficient   *
728
 *           to avoid 64bit operations when only the right 32 bits are         *
726
 *           size to avoid 64bit operations when only the right 32 bits are    *
729
 *           significant. Repeat() code completely re-written to maintain two  *
727
 *           significant. Repeat() code completely re-written to maintain two  *
730
 *           repetition lists, one for each side.  Quiesce() now handles the   *
728
 *           repetition lists, one for each side.  Quiesce() now handles the   *
731
 *           repetition check a little different, being careful to not call it *
729
 *           repetition check a little different, being careful to not call it *
732
 *           when it's unimportant, but calling it when repetitions are        *
730
 *           when it's unimportant, but calling it when repetitions are        *
733
 *           possible.                                                         *
731
 *           possible.                                                         *
Line 735... Line 733...
735
 *    8.24   Tweaks for king tropism to encourage pieces to collect near the   *
733
 *    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   *
734
 *           king, or to encourage driving them away when being attacked.  A   *
737
 *           modification to Evaluate() to address the problem where Crafty    *
735
 *           modification to Evaluate() to address the problem where Crafty    *
738
 *           is forced to play Kf1 or Kf8, blocking the rook in and getting    *
736
 *           is forced to play Kf1 or Kf8, blocking the rook in and getting    *
739
 *           into tactical difficulties as a result.  Book problem fixed where *
737
 *           into tactical difficulties as a result.  Book problem fixed where *
740
 *           BookUp was attempting to group moves with a common ancestor       *
738
 *           Bookup was attempting to group moves with a common ancestor       *
741
 *           position together.  Unfortunately, captures were separated from   *
739
 *           position together.  Unfortunately, captures were separated from   *
742
 *           this group, meaning capture moves in the book could never be      *
740
 *           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       *
741
 *           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     *
742
 *           worked because Crafty would drop out of book (not finding the     *
745
 *           capture) and then the search would "save" it.  However, if there  *
743
 *           capture) and then the search would "save" it.  However, if there  *
Line 777... Line 775...
777
 *           if the side on move is either significantly ahead or behind,      *
775
 *           if the side on move is either significantly ahead or behind,      *
778
 *           depending on the extension.  For example, getting out of check    *
776
 *           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     *
777
 *           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    *
778
 *           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.     *
779
 *           the side on move is ahead a rook, since he's already winning.     *
782
 *           minor adjustments for efficiency as well.  The next few           *
780
 *           minor adjustments for efficiency as well.  The next few versions  *
783
 *           versions in this series will have module names in these comments  *
781
 *           in this series will have module names in these comments           *
784
 *           indicating which modules have been "cleaned" up.  This is an      *
782
 *           indicating which modules have been "cleaned" up.  This is an      *
785
 *           effort at optimizing, although it is currently directed at a line *
783
 *           effort at optimizing, although it is currently directed at a line *
786
 *           by line analysis within modules, rather than major changes that   *
784
 *           by line analysis within modules, rather than major changes that   *
787
 *           effect more global ideas.  This type of optimization will come at *
785
 *           effect more global ideas.  This type of optimization will come at *
788
 *           a later point in time.                                            *
786
 *           a later point in time.                                            *
Line 918... Line 916...
918
 *                                                                             *
916
 *                                                                             *
919
 *    9.15   Evaluate() now attempts to recognize the case where a knight is   *
917
 *    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     *
918
 *           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   *
919
 *           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  *
920
 *           neither of the two potential flight squares are safe (checked by  *
923
 *           Swap()) then a large penalty is given.  This was done to avoid    *
921
 *           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 *
922
 *           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  *
923
 *           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      *
924
 *           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 *
925
 *           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   *
926
 *           in this version:  (1) nodes_per_second was getting clobbered at   *
Line 1443... Line 1441...
1443
 *           the piece could let passed pawns race in undisturbed which would  *
1441
 *           the piece could let passed pawns race in undisturbed which would  *
1444
 *           affect the score.  This pruning is turned off when there are not  *
1442
 *           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   *
1443
 *           at least two pieces left on the board.  Another bug in the move   *
1446
 *           generator produced pawn promotions twice, once when captures were *
1444
 *           generator produced pawn promotions twice, once when captures were *
1447
 *           generated, then again when the rest of the moves are produced.    *
1445
 *           generated, then again when the rest of the moves are produced.    *
1448
 *           this was also repaired.  Small book now will work.  The BookUp()  *
1446
 *           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  *
1447
 *           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.       *
1448
 *           PGN Result tag, so that the small book will work correctly.       *
1451
 *                                                                             *
1449
 *                                                                             *
1452
 *   11.6    Modifications to time allocation in a further attempt to make     *
1450
 *   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 *
1451
 *           Crafty speed up if time gets short, to avoid flagging.  It is now *
Line 1523... Line 1521...
1523
 *   11.13   Endgame threshold lowered to the other side having a queen or     *
1521
 *   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       *
1522
 *           less (9) rather than (13) points.  Queen+bishop can be very       *
1525
 *           dangerous to the king for example, or two rooks and a bishop.     *
1523
 *           dangerous to the king for example, or two rooks and a bishop.     *
1526
 *           Learning "curve" modified.  It was accidentally left in a sort    *
1524
 *           Learning "curve" modified.  It was accidentally left in a sort    *
1527
 *           of "geometric" shape, with the last move getting the full learn   *
1525
 *           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    *
1526
 *           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  *
1527
 *           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..   *
1528
 *           moves, the last gets the full value, the next gets 19/20, etc..   *
1531
 *           Also the "percentage played" was hosed and is fixed.              *
1529
 *           Also the "percentage played" was hosed and is fixed.              *
1532
 *                                                                             *
1530
 *                                                                             *
1533
 *   11.14   Minor modification to book learn 4 code so that when you start    *
1531
 *   11.14   Minor modification to book learn 4 code so that when you start    *
Line 1646... Line 1644...
1646
 *           cache thrashing.  PopCnt() no longer used to recognize that we    *
1644
 *           cache thrashing.  PopCnt() no longer used to recognize that we    *
1647
 *           have reached an endgame database, there's now a counter for the   *
1645
 *           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   *
1646
 *           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  *
1647
 *           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   *
1648
 *           and UnmakeMove to make things a couple of percent faster, but a   *
1651
 *           whole lot cleaner.  Ditto for Swap and Quiesce.  More speed, and  *
1649
 *           whole lot cleaner.  Ditto for SEE and Quiesce.  More speed, and   *
1652
 *           cleaner code.  Outside passed pawn scored scaled down except when *
1650
 *           cleaner code.  Outside passed pawn scored scaled down except when *
1653
 *           the opponent has no pieces at all.  "Lazy eval" cleaned up.  We   *
1651
 *           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    *
1652
 *           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    *
1653
 *           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.    *
1654
 *           how large the positional scores have gotten to make this work.    *
Line 1664... Line 1662...
1664
 *           status not only indicates whether castling is legal or not, but   *
1662
 *           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.    *
1663
 *           if it's not, whether that side castled or move the king/rooks.    *
1666
 *           this let ValidateMove() fail to correctly detect that a castling  *
1664
 *           this let ValidateMove() fail to correctly detect that a castling  *
1667
 *           move from the hash table might be invalid, which could wreck the  *
1665
 *           move from the hash table might be invalid, which could wreck the  *
1668
 *           search easily.  This was an oversight from the new status code.   *
1666
 *           search easily.  This was an oversight from the new status code.   *
1669
 *           Serious book bug fixed.  BookUp() was not counting wins and       *
1667
 *           Serious book bug fixed.  Bookup() was not counting wins and       *
1670
 *           losses correctly, a bug introduced to make small.pgn work. Minor  *
1668
 *           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  *
1669
 *           bug in the "trapped bishop" (a2/h2/a7/h7) code fixed.  Minor bug  *
1672
 *           in Swap() also fixed (early exit that was not safe in rare cases.)*
1670
 *           in SEE() also fixed (early exit that was not safe in rare cases.) *
1673
 *                                                                             *
1671
 *                                                                             *
1674
 *   11.18   EvaluatePawns() modified to recognize that if there are two white *
1672
 *   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  *
1673
 *           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     *
1674
 *           pawns on the d-file are also effectively rammed as well since     *
1677
 *           there is no hope for advancing it.  Auto232 automatic play code   *
1675
 *           there is no hope for advancing it.  Auto232 automatic play code   *
Line 1952... Line 1950...
1952
 *           again, even if this choice was at move 2, and the remainder of    *
1950
 *           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   *
1951
 *           the book line was completely forced.  All in an effort to learn   *
1954
 *           more quickly.                                                     *
1952
 *           more quickly.                                                     *
1955
 *                                                                             *
1953
 *                                                                             *
1956
 *   14.5    annotate bug fixed where if there was only one legal move, the    *
1954
 *   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   *
1955
 *           annotation would stop with no warning.  Bookup() now produces a   *
1958
 *           more useful error message, giving the exact line number in the    *
1956
 *           more useful error message, giving the exact line number in the    *
1959
 *           input file where the error occurred, to make fixing them easier.  *
1957
 *           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    *
1958
 *           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()    *
1959
 *           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  *
1960
 *           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   *
1961
 *           files to create your opening book, without having problems.  It   *
1964
 *           understands that nesting () {} characters "hides" the stuff in-   *
1962
 *           understands that nesting () {} characters "hides" the stuff in-   *
1965
 *           side them, as well as accepting non-standard PGN comments that    *
1963
 *           side them, as well as accepting non-standard PGN comments that    *
1966
 *           are inside [].  Annotate() now will annotate a PGN file with      *
1964
 *           are inside [].  Annotate() now will annotate a PGN file with      *
Line 2179... Line 2177...
2179
 *           promotion moves with no promotion piece specified.  The book      *
2177
 *           promotion moves with no promotion piece specified.  The book      *
2180
 *           create code also now correctly reports when you run out of disk   *
2178
 *           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  *
2179
 *           space and this should work under any system to let you know when  *
2182
 *           you run out of space.                                             *
2180
 *           you run out of space.                                             *
2183
 *                                                                             *
2181
 *                                                                             *
2184
 *   15.15   Major modifications to Book() and BookUp().  BookUp() now needs   *
2182
 *   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     *
2183
 *           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-   *
2184
 *           less under windows).  Also, a book position is now 16 bytes in-   *
2187
 *           stead of 20 (or 24 under windows) further reducing the space      *
2185
 *           stead of 20 (or 24 under windows) further reducing the space      *
2188
 *           requirements.  The "win/lose/draw" counts are no longer absolute, *
2186
 *           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 *
2187
 *           rather they are relative so they can be stored in one byte. A new *
Line 2294... Line 2292...
2294
 *           which gives them the most flexibility in advancing.  A change to  *
2292
 *           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 *
2293
 *           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   *
2294
 *           when the B's are on opposite colors, but to also consider other   *
2297
 *           positons like RB vs RB drawish with opposite B's.                 *
2295
 *           positons like RB vs RB drawish with opposite B's.                 *
2298
 *                                                                             *
2296
 *                                                                             *
2299
 *   16.0    Hash functions renamed to HashProbe() and HashStore().  The store *
2297
 *   16.0    Hash functions renamed to ProbeTransRef() and StoreTransRef().    *
2300
 *           functions (2) were combined to eliminate some duplicate code and  *
2298
 *           The store functions (2) were combined to eliminate some duplicate *
2301
 *           shrink the cache footprint a bit.  Adjustment to "losing the      *
2299
 *           code and shrink the cache footprint a bit.  Adjustment to "losing *
2302
 *           right to castle" so that the penalty is much less if this is done *
2300
 *           the right to castle" so that the penalty is much less if this is  *
2303
 *           when trading queens, since a king in the center becomes less of a *
2301
 *           done when trading queens, since a king in the center becomes less *
2304
 *           problem there. Several eval tweaks.  Support for Eugene Nalimov's *
2302
 *           of a problem there. Several eval tweaks.  Support for Eugene      *
2305
 *           new endgame databases that reduce the size by 50%.  Added a new   *
2303
 *           Nalimov's new endgame databases that reduce the size by 50%.      *
2306
 *           cache=xxx command to set the tablebase cache (more memory means   *
2304
 *           Added a new cache=xxx command to set the tablebase cache (more    *
2307
 *           less I/O of course).  The "egtb" command now has two uses.  If    *
2305
 *           memory means less I/O of course).  The "egtb" command now has two *
2308
 *           use egtb=0, you can disable tablebases for testing.  Otherwise,   *
2306
 *           uses.  If you enter egtb=0, you can disable tablebases for        *
2309
 *           you just add "egtb" to your command line or .craftyrc file and    *
2307
 *           testing.  Otherwise, you just add "egtb" to your command line or  *
2310
 *           Crafty automatically recognizes the files that are present and    *
2308
 *           .craftyrc file and Crafty automatically recognizes the files that *
2311
 *           sets up to probe them properly.  Added an eval term to catch a    *
2309
 *           are present and sets up to probe them properly.  Added an eval    *
2312
 *           closed position with pawns at e4/d3/c4 and then avoiding the      *
2310
 *           term to catch a closed position with pawns at e4/d3/c4 and then   *
2313
 *           temptation to castle into an attack.  Most of the evaluation      *
2311
 *           avoiding the temptation to castle into an attack.  Most of the    *
2314
 *           discontinuities have been removed, using the two new macros       *
2312
 *           evaluation discontinuities have been removed, using the two new   *
2315
 *           ScaleToMaterial() and InverseScaleToMaterial().  Scale() is used  *
2313
 *           macros ScaleToMaterial() and InverseScaleToMaterial().  Scale()   *
2316
 *           to reduce scores as material is removed from the board, while     *
2314
 *           is used to reduce scores as material is removed from the board,   *
2317
 *           InverseScale() is used to increase the score as material is       *
2315
 *           while InverseScale() is used to increase the score as material    *
2318
 *           removed.  This removed a few ugly effects of things happening     *
2316
 *           is removed.  This removed a few ugly effects of things happening  *
2319
 *           right around the EG_MAT threshold.                                *
2317
 *           right around the EG_MAT threshold.                                *
2320
 *                                                                             *
2318
 *                                                                             *
2321
 *   16.1    Bug in EGTBProbe() which used the wrong variable to access the    *
2319
 *   16.1    Bug in EGTBProbe() which used the wrong variable to access the    *
2322
 *           enpassant target square was fixed.  The cache=x command now       *
2320
 *           enpassant target square was fixed.  The cache=x command now       *
2323
 *           checks for a failed malloc() and reverts to the default cache     *
2321
 *           checks for a failed malloc() and reverts to the default cache     *
Line 2327... Line 2325...
2327
 *           mode.                                                             *
2325
 *           mode.                                                             *
2328
 *                                                                             *
2326
 *                                                                             *
2329
 *   16.2    More evaluation changes, specifically to bring king safety down   *
2327
 *   16.2    More evaluation changes, specifically to bring king safety down   *
2330
 *           to reasonable levels.  Support for the DGT electronic chess board *
2328
 *           to reasonable levels.  Support for the DGT electronic chess board *
2331
 *           is now included (but only works in text mode, not in conjunction  *
2329
 *           is now included (but only works in text mode, not in conjunction  *
2332
 *           with xboard/winboard yet.  Fix to HashStore() that corrected a    *
2330
 *           with xboard/winboard yet.  Fix to StoreTransRef() that corrected  *
2333
 *           problem with moving an entry from tablea to tableb, but to the    *
2331
 *           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).    *
2332
 *           wrong address 50% of the time (thanks to J. Wesley Cleveland).    *
2335
 *                                                                             *
2333
 *                                                                             *
2336
 *   16.3    Performance tweaks plus a few evaluation changes.  An oversight   *
2334
 *   16.3    Performance tweaks plus a few evaluation changes.  An oversight   *
2337
 *           would let Crafty play a move like exd5 when cxd5 was playable.    *
2335
 *           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." *
2336
 *           IE it didn't follow the general rule "capture toward the center." *
Line 2360... Line 2358...
2360
 *           probe limit, it wouldn't probe yet Iterate() would terminate the  *
2358
 *           probe limit, it wouldn't probe yet Iterate() would terminate the  *
2361
 *           search after a couple of plies.  And the move chosen could draw.  *
2359
 *           search after a couple of plies.  And the move chosen could draw.  *
2362
 *           New code submitted by George Barrett, which adds a new command    *
2360
 *           New code submitted by George Barrett, which adds a new command    *
2363
 *           "html on".  Using this will cause the annotate command to produce *
2361
 *           "html on".  Using this will cause the annotate command to produce *
2364
 *           a game.html file (rather than game.can) which includes nice board *
2362
 *           a game.html file (rather than game.can) which includes nice board *
2365
 *           displays (bitmapped images) everywhere Crafty suggests a different*
2363
 *           displays (bitmapped images) everywhere Crafty suggests a          *
2366
 *           move.  You will need to download the bitmaps directory files to   *
2364
 *           different move.  You will need to download the bitmaps directory  *
2367
 *           make this work.  Note that html on enables this or you will get   *
2365
 *           files to make this work.  Note that html on enables this or you   *
2368
 *           normal annotation output in the .can file.  Final hashing changes *
2366
 *           will get normal annotation output in the .can file.  Final        *
2369
 *           made.  Now crafty has only two hash tables, the 'depth preferred' *
2367
 *           hashing changes made.  Now crafty has only two hash tables, the   *
2370
 *           and 'always store' tables, but not one for each side.             *
2368
 *           'depth preferred' and 'always store' tables, but not one for each *
-
 
2369
 *           side.                                                             *
2371
 *                                                                             *
2370
 *                                                                             *
2372
 *   16.5    Minor glitch in internal iterative deepening code (in search.c)   *
2371
 *   16.5    Minor glitch in internal iterative deepening code (in search.c)   *
2373
 *           could sometimes produce an invalid move.  Crafty now probes the   *
2372
 *           could sometimes produce an invalid move.  Crafty now probes the   *
2374
 *           hash table to find the best move which works in all cases.        *
2373
 *           hash table to find the best move which works in all cases.        *
2375
 *           Interesting tablebase bug fixed.  By probing at ply=2, the        *
2374
 *           Interesting tablebase bug fixed.  By probing at ply=2, the        *
2376
 *           search could overlook a repetition/50 move draw, and turn a won   *
2375
 *           search could overlook a repetition/50 move draw, and turn a won   *
2377
 *           position into a draw.  Crafty now only probes at ply > 2, to      *
2376
 *           position into a draw.  Crafty now only probes at ply > 2, to      *
-
 
2377
 *           let the Repeat() function have a chance.  Added code by Dan       *
2378
 *           let the Repeat() function have a chance.  Added code by Dan       * *           Corbitt to add environment variables for the tablebases, books,   *
2378
 *           Corbitt to add environment variables for the tablebases, books,   *
2379
 *           logfiles and the .craftyrc file paths.  The environment variables *
2379
 *           logfiles and the .craftyrc file paths.  The environment variables *
2380
 *           CRAFTY_TB_PATH, CRAFTY_BOOK_PATH, CRAFTY_LOG_PATH and             *
2380
 *           CRAFTY_TB_PATH, CRAFTY_BOOK_PATH, CRAFTY_LOG_PATH and             *
2381
 *           CRAFTY_RC_PATH should point to where these files are located and  *
2381
 *           CRAFTY_RC_PATH should point to where these files are located and  *
2382
 *           offer an alternative to specifying them on the command line.      *
2382
 *           offer an alternative to specifying them on the command line.      *
2383
 *           Final version of the EGTB code is included in this version.  This *
2383
 *           Final version of the EGTB code is included in this version.  This *
Line 2427... Line 2427...
2427
 *           which was intentionally ignored in the last major revision.  Many *
2427
 *           which was intentionally ignored in the last major revision.  Many *
2428
 *           other scoring terms have been modified as well to attempt to      *
2428
 *           other scoring terms have been modified as well to attempt to      *
2429
 *           bring the scores back closer to something reasonable.             *
2429
 *           bring the scores back closer to something reasonable.             *
2430
 *                                                                             *
2430
 *                                                                             *
2431
 *   16.8    Bug in evaluate.c (improper editing) broke the scoring for white  *
2431
 *   16.8    Bug in evaluate.c (improper editing) broke the scoring for white  *
2432
 *           rooks on open files (among other things.)  new twist on null-     *
2432
 *           rooks on open files (among other things.)  New twist on null-     *
2433
 *           move search...  Crafty now uses R=3 near the root of the tree,    *
2433
 *           move search...  Crafty now uses R=3 near the root of the tree,    *
2434
 *           and R=2 near the top.  It also uses null-move so long as there is *
2434
 *           and R=2 near the top.  It also uses null-move so long as there is *
2435
 *           a single piece on the board, but when material drops to a rook or *
2435
 *           a single piece on the board, but when material drops to a rook or *
2436
 *           less, null move is turned off and only used in the last 7 plies   *
2436
 *           less, null move is turned off and only used in the last 7 plies   *
2437
 *           to push the zugzwang errors far enough off that they can be       *
2437
 *           to push the zugzwang errors far enough off that they can be       *
Line 2492... Line 2492...
2492
 *           Evaluate() procedure, which could produce bizarre effects.  A few *
2492
 *           Evaluate() procedure, which could produce bizarre effects.  A few *
2493
 *           minor eval glitches that caused asymmetric scores unintentionally *
2493
 *           minor eval glitches that caused asymmetric scores unintentionally *
2494
 *           were removed.                                                     *
2494
 *           were removed.                                                     *
2495
 *                                                                             *
2495
 *                                                                             *
2496
 *   16.17   Minor "hole" in SMP code fixed.  It was possible that a move      *
2496
 *   16.17   Minor "hole" in SMP code fixed.  It was possible that a move      *
2497
 *           displayed as the best in Output() would not get played.     *
2497
 *           displayed as the best in Output() would not get played.           *
2498
 *           Very subtle timing issue dealing with the search timing out and   *
2498
 *           Very subtle timing issue dealing with the search timing out and   *
2499
 *           forgetting to copy the best move back to the right data area.     *
2499
 *           forgetting to copy the best move back to the right data area.     *
2500
 *           Minor fixes to the modified -USE_ATTACK_FUNCTIONS option that     *
2500
 *           Minor fixes to the modified -USE_ATTACK_FUNCTIONS option that     *
2501
 *           was broken when the And()/Or()/ShiftX() macros were replaced by   *
2501
 *           was broken when the And()/Or()/ShiftX() macros were replaced by   *
2502
 *           their direct bitwise operator replacements.                       *
2502
 *           their direct bitwise operator replacements.                       *
Line 2505... Line 2505...
2505
 *           toward the opponent king in a coordinated way).  The scoring term *
2505
 *           toward the opponent king in a coordinated way).  The scoring term *
2506
 *           that kept the queen from going to the opposite side of the board  *
2506
 *           that kept the queen from going to the opposite side of the board  *
2507
 *           was not working well which would also cause attacking problems.   *
2507
 *           was not working well which would also cause attacking problems.   *
2508
 *           Razoring code has been disabled, as it neither helps or hurts on  *
2508
 *           Razoring code has been disabled, as it neither helps or hurts on  *
2509
 *           tactical tests, and it creates a few hashing problems that are    *
2509
 *           tactical tests, and it creates a few hashing problems that are    *
2510
 *           annoying.  Bug in HashStorePV() that would store the PV into the  *
2510
 *           annoying.  Bug in StoreTransRefPV() that would store the PV into  *
2511
 *           hash table, but possibly in the wrong table entry, which could    *
2511
 *           the hash table, but possibly in the wrong table entry, which      *
2512
 *           stuff a bad move in a hash entry, or overwrite a key entry that   *
2512
 *           could stuff a bad move in a hash entry, or overwrite a key entry  *
2513
 *           could have been useful later.  Book random 0 was slightly wrong   *
2513
 *           that could have been useful later.  Book random 0 was slightly    *
2514
 *           as it could not ignore book moves if the search said that the     *
2514
 *           wrong as it could not ignore book moves if the search said that   *
2515
 *           score was bad.  Also the search would not time-out properly on a  *
2515
 *           the score was bad.  Also the search would not time-out properly   *
2516
 *           forced move, it would use the entire time alotted which was a big *
2516
 *           on a forced move, it would use the entire time alotted which was  *
2517
 *           waste of time when there was only one legal move to make. A very  *
2517
 *           a big waste of time when there was only one legal move to make.   *
2518
 *           interesting bug was found in storing mate bounds in the hash      *
2518
 *           A very interesting bug was found in storing mate bounds in the    *
2519
 *           table, one I had not heard of before.  Another change to          *
2519
 *           hash table, one I had not heard of before.  Another change to     *
2520
 *           Iterate() to make it avoid exiting as soon as a mate is found, so *
2520
 *           Iterate() to make it avoid exiting as soon as a mate is found, so *
2521
 *           that it can find the shortest mate possible.                      *
2521
 *           that it can find the shortest mate possible.                      *
2522
 *                                                                             *
2522
 *                                                                             *
2523
 *   16.19   Savepos now pads each rank to 8 characters so that programs that  *
2523
 *   16.19   Savepos now pads each rank to 8 characters so that programs that  *
2524
 *           don't handle abbreviated FEN will be able to parse Crafty's FEN   *
2524
 *           don't handle abbreviated FEN will be able to parse Crafty's FEN   *
Line 2689... Line 2689...
2689
 *           black pawn to g7 made it work fine.   Also if both sides had an   *
2689
 *           black pawn to g7 made it work fine.   Also if both sides had an   *
2690
 *           equal number of pawns (black pawn at a7/b7, white pawns at b2/c2  *
2690
 *           equal number of pawns (black pawn at a7/b7, white pawns at b2/c2  *
2691
 *           the code would not notice black had an outside passer candidate   *
2691
 *           the code would not notice black had an outside passer candidate   *
2692
 *           since pawns were 'equal' in number.                               *
2692
 *           since pawns were 'equal' in number.                               *
2693
 *                                                                             *
2693
 *                                                                             *
2694
 *   17.12   BookUp() will now create a book with all sorts of games in it, so *
2694
 *   17.12   Bookup() will now create a book with all sorts of games in it, so *
2695
 *           long as the various games have the FEN string to properly set the *
2695
 *           long as the various games have the FEN string to properly set the *
2696
 *           initial chess board position.                                     *
2696
 *           initial chess board position.                                     *
2697
 *                                                                             *
2697
 *                                                                             *
2698
 *   17.13   Endgame evaluation problem fixed.  King scoring now dynamically   *
2698
 *   17.13   Endgame evaluation problem fixed.  King scoring now dynamically   *
2699
 *           chooses the right piece/square table depending on which side of   *
2699
 *           chooses the right piece/square table depending on which side of   *
Line 2734... Line 2734...
2734
 *           Even if the other side had pawns all over the board.  Passed pawn *
2734
 *           Even if the other side had pawns all over the board.  Passed pawn *
2735
 *           scores increased a bit.  Minor change to "bad trade" code to turn *
2735
 *           scores increased a bit.  Minor change to "bad trade" code to turn *
2736
 *           off in endings.  S list removed.  The trojan horse check is now   *
2736
 *           off in endings.  S list removed.  The trojan horse check is now   *
2737
 *           automatically enabled when the key position is recognized at the  *
2737
 *           automatically enabled when the key position is recognized at the  *
2738
 *           root of the tree.  It is disabled once the key position is no     *
2738
 *           root of the tree.  It is disabled once the key position is no     *
2739
 *           longer seen at the root.  Bug in BookUp() would break if a FEN    *
2739
 *           longer seen at the root.  Bug in Bookup() would break if a FEN    *
2740
 *           string was included in a game used for input.  SetBoard() was     *
2740
 *           string was included in a game used for input.  SetBoard() was     *
2741
 *           setting castling status incorrectly.  Internal iterative          *
2741
 *           setting castling status incorrectly.  Internal iterative          *
2742
 *           deepening bug could (on very rare occasions) cause Crafty to try  *
2742
 *           deepening bug could (on very rare occasions) cause Crafty to try  *
2743
 *           to search an illegal move that would bomb the search.  This       *
2743
 *           to search an illegal move that would bomb the search.  This       *
2744
 *           version fully supports the new xboard protocol version 2.  One    *
2744
 *           version fully supports the new xboard protocol version 2.  One    *
Line 2775... Line 2775...
2775
 *           than testing R=2/3 as the real null-move search uses.  The kibitz *
2775
 *           than testing R=2/3 as the real null-move search uses.  The kibitz *
2776
 *           for "Hello from Crafty Vx.xx" has been moved so that it works     *
2776
 *           for "Hello from Crafty Vx.xx" has been moved so that it works     *
2777
 *           with the new xboard/winboard 4.2.2 versions.  Book learning was   *
2777
 *           with the new xboard/winboard 4.2.2 versions.  Book learning was   *
2778
 *           badly broken in the previous version and has been fixed/tested.   *
2778
 *           badly broken in the previous version and has been fixed/tested.   *
2779
 *                                                                             *
2779
 *                                                                             *
2780
 *   18.4    Recapture extension was left in SearchParallel() by mistake.  This*
2780
 *   18.4    Recapture extension was left in SearchParallel() by mistake.      *
2781
 *           has now been protected by a #ifdef just like it was in Search().  *
2781
 *           This has now been protected by a #ifdef just like it was in       *
2782
 *           Bug in Repeat() was causing problems in SMP versions.  The entire *
2782
 *           Search().  Bug in Repeat() was causing problems in SMP versions.  *
2783
 *           repetition list code was modified to clean this up.  The problem  *
2783
 *           The entire repetition list code was modified to clean this up.    *
2784
 *           was most noticable on things like fine #70.  Bug in               *
2784
 *           The problem was most noticable on things like fine #70.  Bug in   *
2785
 *           LearnImportBook() confused the learn value sign, due to the other *
2785
 *           LearnImportBook() confused the learn value sign, due to the other *
2786
 *           changes to make +=white all the time.  opposite bishop scoring    *
2786
 *           changes to make +=white all the time.  Opposite bishop scoring    *
2787
 *           has been beefed up a bit to avoid these drawish endings.          *
2787
 *           has been beefed up a bit to avoid these drawish endings.          *
2788
 *                                                                             *
2788
 *                                                                             *
2789
 *   18.5    Minor change to RootMove() to use Quiesce() rather than the more  *
2789
 *   18.5    Minor change to RootMove() to use Quiesce() rather than the more  *
2790
 *           complicated way it was ordering with Evaluate()/EnPrise().  This  *
2790
 *           complicated way it was ordering with Evaluate()/EnPrise().  This  *
2791
 *           is no faster, but it is simpler and eliminated the need for the   *
2791
 *           is no faster, but it is simpler and eliminated the need for the   *
Line 2958... Line 2958...
2958
 *                                                                             *
2958
 *                                                                             *
2959
 *   19.3    Change to EvaluateMaterial to realize that a rook for five pawns  *
2959
 *   19.3    Change to EvaluateMaterial to realize that a rook for five pawns  *
2960
 *           is also likely a "bad trade."  Adaptive hash table size code was  *
2960
 *           is also likely a "bad trade."  Adaptive hash table size code was  *
2961
 *           added so that the hash size is set automatically based on the     *
2961
 *           added so that the hash size is set automatically based on the     *
2962
 *           estimated NPS and time per move values for a specific "level"     *
2962
 *           estimated NPS and time per move values for a specific "level"     *
2963
 *           command setting.   Repeat() rewritten.  The old code had an       *
2963
 *           command setting.  Repeat() rewritten.  The old code had an        *
2964
 *           unexplained bug that would overlook repetitions in a parallel     *
2964
 *           unexplained bug that would overlook repetitions in a parallel     *
2965
 *           search in rare cases.  The old cold was complex enough that it    *
2965
 *           search in rare cases.  The old cold was complex enough that it    *
2966
 *           was time to rewrite it and simplify it significantly.             *
2966
 *           was time to rewrite it and simplify it significantly.             *
2967
 *                                                                             *
2967
 *                                                                             *
2968
 *   19.4    Initial depth "seed" value changed to iteration_depth + 1/2 ply,  *
2968
 *   19.4    Initial depth "seed" value changed to iteration_depth + 1/2 ply,  *
Line 2989... Line 2989...
2989
 *                                                                             *
2989
 *                                                                             *
2990
 *   19.7    Changes to draw code so that Crafty will first claim a draw and   *
2990
 *   19.7    Changes to draw code so that Crafty will first claim a draw and   *
2991
 *           then play the move, to avoid any confusion in whether the draw    *
2991
 *           then play the move, to avoid any confusion in whether the draw    *
2992
 *           was made according to FIDE rules or not.  Minor bug in evaluate() *
2992
 *           was made according to FIDE rules or not.  Minor bug in evaluate() *
2993
 *           dealing with candidate passed pawns fixed.  A few additions to    *
2993
 *           dealing with candidate passed pawns fixed.  A few additions to    *
2994
 *           support my AMD Opteron inline assembly for MSB(), LSB()  *
2994
 *           support my AMD Opteron inline assembly for MSB(), LSB()           *
2995
 *           and PopCnt() procedures.                                          *
2995
 *           and PopCnt() procedures.                                          *
2996
 *                                                                             *
2996
 *                                                                             *
2997
 *   19.8    Changes to lock.h to (a) eliminate NT/alpha, since Microsoft no   *
2997
 *   19.8    Changes to lock.h to (a) eliminate NT/alpha, since Microsoft no   *
2998
 *           longer supports the alpha, which makes lock.h much more readable. *
2998
 *           longer supports the alpha, which makes lock.h much more readable. *
2999
 *           CLONE is no longer an option either, further simplyfying the .h   *
2999
 *           CLONE is no longer an option either, further simplyfying the .h   *
Line 3138... Line 3138...
3138
 *           burn CPU time when not actually playing a game.                   *
3138
 *           burn CPU time when not actually playing a game.                   *
3139
 *                                                                             *
3139
 *                                                                             *
3140
 *   19.17   Changes to pawn evaluation to limit positional scores that could  *
3140
 *   19.17   Changes to pawn evaluation to limit positional scores that could  *
3141
 *           get a bit out of sane boundaries in some positions.               *
3141
 *           get a bit out of sane boundaries in some positions.               *
3142
 *                                                                             *
3142
 *                                                                             *
3143
 *   19.18   HashProbe() no longer adjusts alpha/beta bounds if the entry is   *
3143
 *   19.18   ProbeTransRef() no longer adjusts alpha/beta bounds if the entry  *
3144
 *           not good enough to terminate the search here.  This has helped    *
3144
 *           is not good enough to terminate the search here.  This has helped *
3145
 *           speed things up (reduced size of tree) over many test positions   *
3145
 *           speed things up (reduced size of tree) over many test positions   *
3146
 *           so either it was buggy or not worthwhile.  Regardless, it is now  *
3146
 *           so either it was buggy or not worthwhile.  Regardless, it is now  *
3147
 *           'gone'.  Connected passed pawns now scored as a simple pair of    *
3147
 *           'gone'.  Connected passed pawns now scored as a simple pair of    *
3148
 *           pawns that are better as they are advanced, the old connected     *
3148
 *           pawns that are better as they are advanced, the old connected     *
3149
 *           passed pawns on the 6th rank special code has been removed.       *
3149
 *           passed pawns on the 6th rank special code has been removed.       *
Line 3369... Line 3369...
3369
 *           array indices of 5,0, 4,1, 3,2, 2,3, 1,4, or 0,5, which is better *
3369
 *           array indices of 5,0, 4,1, 3,2, 2,3, 1,4, or 0,5, which is better *
3370
 *           than what it was doing.  I plan to tweak this more later to make  *
3370
 *           than what it was doing.  I plan to tweak this more later to make  *
3371
 *           3,2 or 2,3 worse than 4,1 or 1,4 and 0,5 or 5,0, as the latter    *
3371
 *           3,2 or 2,3 worse than 4,1 or 1,4 and 0,5 or 5,0, as the latter    *
3372
 *           mean "unsafe king but no piece pressure" or "piece pressure but   *
3372
 *           mean "unsafe king but no piece pressure" or "piece pressure but   *
3373
 *           king pawn shelter is safe" whereas the middle values mean both    *
3373
 *           king pawn shelter is safe" whereas the middle values mean both    *
3374
 *           components of an attack are present, unsafe king position and the
3374
 *           components of an attack are present, unsafe king position and the *
3375
 *           pieces are closing in.                                            *
3375
 *           pieces are closing in.                                            *
3376
 *                                                                             *
3376
 *                                                                             *
3377
 *   20.11   Minor fix to late move reduction code.  Turns out it is possible  *
3377
 *   20.11   Minor fix to late move reduction code.  Turns out it is possible  *
3378
 *           to reach the block of code if (first_move) { } with status set to *
3378
 *           to reach the block of code if (first_move) { } with status set to *
3379
 *           REMAINING_MOVES (this means no captures, no killer, no hash move, *
3379
 *           REMAINING_MOVES (this means no captures, no killer, no hash move, *
Line 3515... Line 3515...
3515
 *           was summarily removed (not summarily executed, it has had that    *
3515
 *           was summarily removed (not summarily executed, it has had that    *
3516
 *           done far too many times already).                                 *
3516
 *           done far too many times already).                                 *
3517
 *                                                                             *
3517
 *                                                                             *
3518
 *   22.0    Redesign of the data structures completed so that Crafty will no  *
3518
 *   22.0    Redesign of the data structures completed so that Crafty will no  *
3519
 *           longer have duplicated code for wtm and btm cases.  This has      *
3519
 *           longer have duplicated code for wtm and btm cases.  This has      *
3520
 *           already resulted in a rewrite of movgen(), swap(), make() and     *
3520
 *           already resulted in a rewrite of movgen(), SEE(), Make() and      *
3521
 *           Unmake() and cut that code size by almost exactly 50%. The result *
3521
 *           Unmake() and cut that code size by almost exactly 50%. The result *
3522
 *           has been slightly faster speeds, but also the future benefits     *
3522
 *           has been slightly faster speeds, but also the future benefits     *
3523
 *           will be enormous by eliminating a lot of debugging caused by the  *
3523
 *           will be enormous by eliminating a lot of debugging caused by the  *
3524
 *           duplicated code.  Timing change to avoid starting an iteration    *
3524
 *           duplicated code.  Timing change to avoid starting an iteration    *
3525
 *           and wasting significant time.  We still search enough to get a    *
3525
 *           and wasting significant time.  We still search enough to get a    *
Line 3727... Line 3727...
3727
 *           reducing a few of the moves two plies.  The futility pruning has  *
3727
 *           reducing a few of the moves two plies.  The futility pruning has  *
3728
 *           been modified to work at the last N plies.  We have an array of   *
3728
 *           been modified to work at the last N plies.  We have an array of   *
3729
 *           pruning margins (tuned on the cluster) where anytime the depth is *
3729
 *           pruning margins (tuned on the cluster) where anytime the depth is *
3730
 *           less than "pruning_depth" we try the futility test.  If the test  *
3730
 *           less than "pruning_depth" we try the futility test.  If the test  *
3731
 *           succeeds, that move is discarded and not searched at all.  Move   *
3731
 *           succeeds, that move is discarded and not searched at all.  Move   *
3732
 *           ordering code modified slightly to call Swap() fewer times if the *
3732
 *           ordering code modified slightly to call SEE() fewer times if the  *
3733
 *           goodness of the capture can still be accurately assessed without  *
3733
 *           goodness of the capture can still be accurately assessed without  *
3734
 *           the call.  Hash table has been changed to use a bucket of 4       *
3734
 *           the call.  Hash table has been changed to use a bucket of 4       *
3735
 *           entries similar to a 4-way set associative cache.  When a store   *
3735
 *           entries similar to a 4-way set associative cache.  When a store   *
3736
 *           is attempted, we replace the least useful entry (see hash.c for   *
3736
 *           is attempted, we replace the least useful entry (see hash.c for   *
3737
 *           details).  Additionally the hash table is forced to a 64 byte     *
3737
 *           details).  Additionally the hash table is forced to a 64 byte     *
Line 3862... Line 3862...
3862
 *           could cause a thread to attempt to output a PV after the search   *
3862
 *           could cause a thread to attempt to output a PV after the search   *
3863
 *           was in the process of timing out.  That thread could back up an   *
3863
 *           was in the process of timing out.  That thread could back up an   *
3864
 *           incomplete/bogus search result to the root in rare occasions,     *
3864
 *           incomplete/bogus search result to the root in rare occasions,     *
3865
 *           which would / could result in Crafty kibitzing one move but       *
3865
 *           which would / could result in Crafty kibitzing one move but       *
3866
 *           playing a different move.  On occasion, the move played could be  *
3866
 *           playing a different move.  On occasion, the move played could be  *
3867
 *           a horrible blunder.  Minor bug caused HashStore() to lose a best  *
3867
 *           a horrible blunder.  Minor bug caused StoreTransRef() to lose a   *
3868
 *           move when overwriting an old position with a null-move search     *
3868
 *           best move when overwriting an old position with a null-move       *
3869
 *           result.  Minor change by Tracy to lazy evaluation cutoff to speed *
3869
 *           search result.  Minor change by Tracy to lazy evaluation cutoff   *
3870
 *           up evaluation somewhat.  Old "Trojan Horse" attack detection was  *
3870
 *           to speed up evaluation somewhat.  Old "Trojan Horse" attack       *
3871
 *           removed.  At today's depths, it was no longer needed.  New hash   *
3871
 *           detection was removed.  At today's depths, it was no longer       *
3872
 *           idea stores the PV for an EXACT hash entry in a separate hash     *
3872
 *           needed.  New hash idea stores the PV for an EXACT hash entry in a *
3873
 *           table.  When an EXACT hit happens, this PV can be added to the    *
3873
 *           separate hash table.  When an EXACT hit happens, this PV can be   *
3874
 *           incomplete PV we have so far so that we have the exact path that  *
3874
 *           added to the incomplete PV we have so far so that we have the     *
3875
 *           leads to the backed up score.  New "phash" (path hash) command to *
3875
 *           exact path that leads to the backed up score.  New "phash" (path  *
3876
 *           set the number of entries in this path hash table.  For longer    *
3876
 *           hash) command to set the number of entries in this path hash      *
3877
 *           searches, a larger table avoids path table collisions which will  *
3877
 *           table.  For longer searches, a larger table avoids path table     *
3878
 *           produce those short paths that end in <HT>.  If <HT> appears in   *
3878
 *           collisions which will produce those short paths that end in <HT>. *
3879
 *           too many PVs, phash should be increased.  The "Trojan Horse" code *
3879
 *           If <HT> appears in too many PVs, phash should be increased.  The  *
3880
 *           has been completely removed, which also resulted in the removal   *
3880
 *           "Trojan Horse" code has been completely removed, which also       *
3881
 *           of the last bit of "pre-processing code" in preeval.c, so it has  *
3881
 *           resulted in the removal of the last bit of "pre-processing code"  *
3882
 *           been completely removed as well.  Current search depths are such  *
3882
 *           in preeval.c, so it has been completely removed as well.  Current *
3883
 *           that the Trojan Horse code is simply not needed any longer.  A    *
3883
 *           search depths are such that the Trojan Horse code is simply not   *
3884
 *           minor bug in TimeSet() fixed where on rare occasions, near the    *
3884
 *           needed any longer.  A minor bug in TimeSet() fixed where on rare  *
3885
 *           end of a time control, time_limit could be larger than the max    *
3885
 *           occasions, near the end of a time control, time_limit could be    *
3886
 *           time allowed (absolute_time_limit).  We never check against this  *
3886
 *           larger than the max time allowed (absolute_time_limit).  We never *
3887
 *           limit until we exceed the nominal time limit.  Cleanup on the     *
3887
 *           check against this limit until we exceed the nominal time limit.  *
3888
 *           draw by repetition code to greatly simplify the code as well as   *
3888
 *           Cleanup on the draw by repetition code to greatly simplify the    *
3889
 *           speed it up.                                                      *
3889
 *           code as well as speed it up.                                      *
3890
 *                                                                             *
3890
 *                                                                             *
3891
 *    23.5   Several pieces of code cleanup, both for readability and speed.   *
3891
 *    23.5   Several pieces of code cleanup, both for readability and speed.   *
3892
 *           We are now using stdint.h, which lets us specific the exact size  *
3892
 *           We are now using stdint.h, which lets us specific the exact size  *
3893
 *           of an integer value which gets rid of the int vs long issues that *
3893
 *           of an integer value which gets rid of the int vs long issues that *
3894
 *           exist between MSVC and the rest of the world on X86_64.  We still *
3894
 *           exist between MSVC and the rest of the world on X86_64.  We still *
Line 4008... Line 4008...
4008
 *           only to be instantly aborted so that we could back out of Search()*
4008
 *           only to be instantly aborted so that we could back out of Search()*
4009
 *           and then re-start.  Wasted the split time unnecessarily although  *
4009
 *           and then re-start.  Wasted the split time unnecessarily although  *
4010
 *           it was not a huge amount of time.  Another simplification to the  *
4010
 *           it was not a huge amount of time.  Another simplification to the  *
4011
 *           repetition-detection code while chasing a parallel search bug     *
4011
 *           repetition-detection code while chasing a parallel search bug     *
4012
 *           was missing repetitions.                                          *
4012
 *           was missing repetitions.                                          *
-
 
4013
 *                                                                             *
-
 
4014
 *    24.1   LMR reductions changed to allow a more dynamic reduction amount   *
-
 
4015
 *           rather than just 1 or 2.  An array LMR_reductions[depth][moves]   *
-
 
4016
 *           is initialized at start-up and sets the reduction amount for a    *
-
 
4017
 *           specific depth remaining (larger reduction with more depth left)  *
-
 
4018
 *           and the total moves searched at this node (again a larger         *
-
 
4019
 *           reduction as more moves are searched.)  This can easily be        *
-
 
4020
 *           changed with the new "lmr" command (help lmr for details).  The   *
-
 
4021
 *           old "noise" stuff has been changed.  Now, rather than noise       *
-
 
4022
 *           specifying the number of nodes that have to be searched before    *
-
 
4023
 *           any output is displayed (PV, fail high, etc) it now specifies a   *
-
 
4024
 *           time that must pass before the first output is produced.  This    *
-
 
4025
 *           can still be displayed with noise=0, otherwise noise=n says no    *
-
 
4026
 *           output until n seconds have passed (n can be a fraction of a      *
-
 
4027
 *           second if wanted.)  I restored the old adaptive null-move code,   *
-
 
4028
 *           but changed the reduction (used to be 2 to 3 depending on the     *
-
 
4029
 *           depth remaining) so that it is 3 + depth / 6.  For each 6 plies   *
-
 
4030
 *           of remaining depth, we reduce by another ply, with no real bound  *
-
 
4031
 *           other than the max depth we can reasonably reach.  The "6" in     *
-
 
4032
 *           the above can be changed with the personality command or the new  *
-
 
4033
 *           null m n command.  When the changes to noise were made, Iterate() *
-
 
4034
 *           was also changed so that if the search terminates for any reason  *
-
 
4035
 *           and no PV was displayed, whether because the noise limit was not  *
-
 
4036
 *           satisfied or this search did not produce a PV because it started  *
-
 
4037
 *           at an excessively deep search depth, Crafty now always displays   *
-
 
4038
 *           at least one PV in the log file to show how the game is going to  *
-
 
4039
 *           continue.  One case where this was an issue was where Crafty did  *
-
 
4040
 *           a LONG ponder search because the opponent took an excessive       *
-
 
4041
 *           amount of time to make a move.  If it finishes (say) a 30 ply     *
-
 
4042
 *           search while pondering, when the opponent moves, Crafty will move *
-
 
4043
 *           instantly, but when it starts the next search, we start pondering *
-
 
4044
 *           at iteration 29, which might take a long time to finish.  But we  *
-
 
4045
 *           do still have the PV from the last search (the 30 ply one) and    *
-
 
4046
 *           main() thoughtfully removed the first two moves (the move played  *
-
 
4047
 *           and the move we are now pondering, so we always have something to *
-
 
4048
 *           display, and now we no longer terminate a search with no output   *
-
 
4049
 *           (PV, time, etc) at all.  Generation II of the parallel split code *
-
 
4050
 *           (see Thread() in the thread.c source file comments for specifics) *
-
 
4051
 *           that is a lighter-weight split/copy plus the individual threads   *
-
 
4052
 *           do most of the copying rather than the thread that initiates the  *
-
 
4053
 *           split.  More work on the skill command.  For each 10 units the    *
-
 
4054
 *           skill level is reduced, the search speed is reduced by 50%.       *
-
 
4055
 *           Additionally the null-move and LMR reduction values are also      *
-
 
4056
 *           ramped down so that by the time skill drops below 10, there are   *
-
 
4057
 *           no reductions left.                                               *
-
 
4058
 *                                                                             *
-
 
4059
 *    24.2   Bug in SetTime() fixed.  The absolute time limit was set way too  *
-
 
4060
 *           large in sudden death games (games with no secondary time control *
-
 
4061
 *           to add time on the clock) with an increment.  It was intended to  *
-
 
4062
 *           allow the search to use up to 5x the normal target time, unless   *
-
 
4063
 *           that was larger than 1/2 of the total time remaining, but some-   *
-
 
4064
 *           where along the way that 5x was removed and it always set the     *
-
 
4065
 *           absolute time limit to 1/2 the remaining clock, which would burn  *
-
 
4066
 *           clock time way too quickly.  Complete re-factor of Search() to    *
-
 
4067
 *           take the main loop and move that to a new procedure               *
-
 
4068
 *           SearchMoveList() to eliminate the duplicated search code between  *
-
 
4069
 *           Search() and SearchParallel() which has been replaced by          *
-
 
4070
 *           SearchMoveList().  New addition to NextMove().  It was cleaned up *
-
 
4071
 *           to eliminate the old NextEvasion() code since one was a sub-set   *
-
 
4072
 *           of the other.  A minor change to limit the NPS impact on history  *
-
 
4073
 *           ordering.  We do not do history ordering within 6 plies of a      *
-
 
4074
 *           terminal node, and we only try to order 1/2 of the moves before   *
-
 
4075
 *           giving up and assuming this is an ALL node where ordering does    *
-
 
4076
 *           not matter.                                                       *
-
 
4077
 *                                                                             *
-
 
4078
 *    25.0   Complete re-factor of pawn evaluation code.  There were too many  *
-
 
4079
 *           overlapping terms that made tuning difficult.  Now a pawn is      *
-
 
4080
 *           classified as one specific class, there is no overlap between     *
-
 
4081
 *           classes, which simplifies the code significantly.  The code is    *
-
 
4082
 *           now easier to understand and modify.  In addition, the passed     *
-
 
4083
 *           pawn evaluation was rewritten and consolidates all the passed     *
-
 
4084
 *           pawn evaluation in one place.  The evaluation used to add a bonus *
-
 
4085
 *           for rooks behind passed pawns in rook scoring, blockading some-   *
-
 
4086
 *           where else, etc.  All of this was moved to the passed pawn code   *
-
 
4087
 *           to make it easier to understand and modify.  A limited version of *
-
 
4088
 *           late move pruning (LMP) is used in the last two plies.  Once a    *
-
 
4089
 *           set number of moves have been searched with no fail high, non-    *
-
 
4090
 *           interesting moves are simply skipped in a way similar to futility *
-
 
4091
 *           pruning.  This version also contains a major rewrite of the       *
-
 
4092
 *           parallel search code, now referred to as Generation II.  It has a *
-
 
4093
 *           more lightweight split algorithm, that costs the parent MUCH less *
-
 
4094
 *           effort to split the search.  The key is that now the individual   *
-
 
4095
 *           "helper" threads do all the work, allocating a split block,       *
-
 
4096
 *           copying the data from the parent, etc., rather than the parent    *
-
 
4097
 *           doing it all.  Gen II based on the DTS "late-join" idea so that a *
-
 
4098
 *           thread will try to join existing split points before it goes to   *
-
 
4099
 *           the idle wait loop waiting for some other thread to split with    *
-
 
4100
 *           it.  In fact, this is now the basis for the new split method      *
-
 
4101
 *           where the parent simply creates a split point by allocating a     *
-
 
4102
 *           split block for itself, and then continuing the search, after the *
-
 
4103
 *           parent split block is marked as "joinable".  Now any idle threads *
-
 
4104
 *           just "jump in" without the parent doing anything else, which      *
-
 
4105
 *           means that currently idle threads will "join" this split block if *
-
 
4106
 *           they are in the "wait-for-work" spin loop, and threads that be-   *
-
 
4107
 *           come idle also join in exactly the same way.  This is MUCH more   *
-
 
4108
 *           efficient, and also significantly reduces the number of split     *
-
 
4109
 *           blocks needed during the search.  We also now pre-split the       *
-
 
4110
 *           search when we are reasonably close to the root of the tree,      *
-
 
4111
 *           which is called a "gratuitous split.  This leaves joinable split  *
-
 
4112
 *           points laying around so that whenever a thread becomes idle, it   *
-
 
4113
 *           can join in at these pre-existing split points immediately.  We   *
-
 
4114
 *           now use a much more conservative approach when dealing with fail  *
-
 
4115
 *           highs at the root.  Since LMR and such have introduced greater    *
-
 
4116
 *           levels of search instability, we no longer trust a fail-high at   *
-
 
4117
 *           the root if it fails low on the re-search.  We maintain the last  *
-
 
4118
 *           score returned for every root move, along with the PV.  Either an *
-
 
4119
 *           exact score or the bound score that was returned.  At the end of  *
-
 
4120
 *           the iteration, we sort the root move list using the backed-up     *
-
 
4121
 *           score as the sort key, and we play the move with the best score.  *
-
 
4122
 *           This solves a particularly ugly issue where we get a score for    *
-
 
4123
 *           the first move, then another move fails high, but then fails low  *
-
 
4124
 *           and the re-search produces a score that is actually WORSE than    *
-
 
4125
 *           the original best move.  We still see that, but we always play    *
-
 
4126
 *           the best move now.  One other efficiency trick is that when the   *
-
 
4127
 *           above happens, the search would tend to be less efficient since   *
-
 
4128
 *           the best score for that fail-high/fail-low move is actually worse *
-
 
4129
 *           than the best move/score found so far.  If this happens, the      *
-
 
4130
 *           score is restored to the original best move score (in Search())   *
-
 
4131
 *           so that we continue searching with a good lower bound, not having *
-
 
4132
 *           to deal with moves that would fail high with this worse value,    *
-
 
4133
 *           but not with the original best move's value.  Minor change to     *
-
 
4134
 *           history counters that now rely on a "saturating counter" idea.  I *
-
 
4135
 *           wanted to avoid the aging idea, and it seemed to not be so clear  *
-
 
4136
 *           that preferring history moves by the depth at which they were     *
-
 
4137
 *           good was the way to go.  I returned to a history counter idea I   *
-
 
4138
 *           tested around 2005 but discarded, namely using a saturating       *
-
 
4139
 *           counter.  The idea is that a center value (at present 1024)       *
-
 
4140
 *           represents a zero score.  Decrementing it makes it worse,         *
-
 
4141
 *           incrementing it makes it better.  But to make it saturate at      *
-
 
4142
 *           either end, I only reduce the counter by a fraction of its        *
-
 
4143
 *           distance from the saturation point so that once it gets to either *
-
 
4144
 *           extreme value, it will not be modified further avoiding wrap-     *
-
 
4145
 *           around.  This basic idea was originally reported by Mark Winands  *
-
 
4146
 *           in 2005.  It seems to provide better results (slightly) on very   *
-
 
4147
 *           deep searches.  One impetus for this was an intent to fold this   *
-
 
4148
 *           into a move so that I could sort the moves rather than doing the  *
-
 
4149
 *           selection approach I currently use.  However, this had a bad      *
-
 
4150
 *           effect on testing, since history information is dynamic and is    *
-
 
4151
 *           constantly changing, between two moves at the same ply in fact.   *
-
 
4152
 *           The sort fixed the history counters to the value at the start of  *
-
 
4153
 *           that ply.  This was discarded after testing, but the history      *
-
 
4154
 *           counter based on the saturating counter idea seemed to be OK and  *
-
 
4155
 *           was left in even though it produced minimal Elo gain during       *
-
 
4156
 *           testing.  Change to the way moves are counted, to add a little    *
-
 
4157
 *           more consistency to LMR.  Now Next*() returns an order number     *
-
 
4158
 *           that starts with 1 and monotonically increases, this order number *
-
 
4159
 *           is used for LMR and such decisions that vary things based on how  *
-
 
4160
 *           far down the move list something occurs.  Root move counting was  *
-
 
4161
 *           particularly problematic with parallel searching, now things are  *
-
 
4162
 *           at least "more consistent".  The only negative impact is that now *
-
 
4163
 *           the move counter gets incremented even for illegal moves, but     *
-
 
4164
 *           testing showed this was a no-change change with one thread, and   *
-
 
4165
 *           the consistency with multiple threads made it useful.  New method *
-
 
4166
 *           to automatically tune SMP parameters.  The command is autotune    *
-
 
4167
 *           and "help autotune" will explain how to run it.  Added the        *
-
 
4168
 *           "counter-move" heuristic for move ordering (Jos Uiterwijk, JICCA) *
-
 
4169
 *           which simply remembers a fail high move and the move at the       *
-
 
4170
 *           previous ply.  If the hash, captures or killer moves don't result *
-
 
4171
 *           in a fail high, this move is tried next.  No significant cost,    *
-
 
4172
 *           seems to reduce tree size noticeably.  Added a follow-up idea     *
-
 
4173
 *           based on the same idea, except we pair a move that fails high     *
-
 
4174
 *           with the move two plies back, introducing a sort of "connection"  *
-
 
4175
 *           between them.  This is a sort of "plan" idea where the first move *
-
 
4176
 *           of the pair enables the second move to fail high.  The benefit is *
-
 
4177
 *           that this introduces yet another pair of good moves that get      *
-
 
4178
 *           ordered before history moves, and is therefore not subject to     *
-
 
4179
 *           reduction.  I have been unable to come up with a reference for    *
-
 
4180
 *           this idea, but I believe I first saw it somewhere around the time *
-
 
4181
 *           Fruit showed up, I am thinking perhaps in the JICCA/JICGA.  Any   *
-
 
4182
 *           reference would be appreciated.  Minor change to the way the PV   *
-
 
4183
 *           and fail-hi/fail-low moves are displayed when pondering.  Crafty  *
-
 
4184
 *           now adds the ponder move to the front of the PV enclosed in ( )   *
-
 
4185
 *           so that it is always visible in console mode.  The depths are     *
-
 
4186
 *           reaching such extreme numbers the ponder move scrolls off the top *
-
 
4187
 *           of the screen when running in console mode or when "tail -f" is   *
-
 
4188
 *           used to watch the log file while a game is in progress.  This is  *
-
 
4189
 *           a bit trickier than you might think since Crafty displays the     *
-
 
4190
 *           game move numbers in the PV.  Penalty for pawns on same color as  *
-
 
4191
 *           bishop now only applies when there is one bishop.                 *
-
 
4192
 *                                                                             *
-
 
4193
 *    25.0.1 Cleanup of NextMove() plus a minor ordering bug fix that would    *
-
 
4194
 *           skip counter moves at ply = 2. Added NUMA code to force the hash  *
-
 
4195
 *           tables to be spread across the numa nodes as equally as possible  *
-
 
4196
 *           rather than all of the data sitting on just onenode.  This makes  *
-
 
4197
 *           one specific user policy important.  BEFORE you set the hash size *
-
 
4198
 *           for any of the four hash tables, you should ALWAYS set the max    *
-
 
4199
 *           threads limit first, so that the NUMA trick works correctly.  Of  *
-
 
4200
 *           course, if you do not use -DAFFINITY this is all irrelevant.  The *
-
 
4201
 *           -DNUMA option has been removed.  I no longer use any libnuma      *
-
 
4202
 *           routines.  A new "smpnuma" command is now used to enable/disable  *
-
 
4203
 *           NUMA mode (which really only affects how the hash tables are      *
-
 
4204
 *           cleared, all the other NUMA code works just fine no matter        *
-
 
4205
 *           whether this is enabled or disabled.  Fixed a bug with the xboard *
-
 
4206
 *           memory command that could overflow and cause preposterous malloc  *
-
 
4207
 *           requests.                                                         *
4013
 *                                                                             *
4208
 *                                                                             *
4014
 *******************************************************************************
4209
 *******************************************************************************
4015
 */
4210
 */
4016
int main(int argc, char **argv) {
4211
int main(int argc, char **argv) {
4017
  int move, readstat;
-
 
4018
  int value = 0, i, result;
-
 
4019
  int draw_type;
-
 
4020
  TREE *tree;
4212
  TREE *tree;
4021
  FILE *personality;
4213
  FILE *personality;
-
 
4214
  int move, readstat, value = 0, i, v, result, draw_type;
4022
  char announce[128];
4215
  char announce[128];
4023
 
4216
 
4024
#if defined(UNIX)
4217
#if defined(UNIX)
4025
  char path[1024];
4218
  char path[1024];
4026
  struct passwd *pwd;
4219
  struct passwd *pwd;
Line 4029... Line 4222...
4029
#endif
4222
#endif
4030
/* Collect environmental variables */
4223
/* Collect environmental variables */
4031
  char *directory_spec = getenv("CRAFTY_BOOK_PATH");
4224
  char *directory_spec = getenv("CRAFTY_BOOK_PATH");
4032
 
4225
 
4033
  if (directory_spec)
4226
  if (directory_spec)
4034
    strcpy_s(book_path, sizeof (book_path), directory_spec); // Pierre-Marie Baty -- use safe version
4227
    strncpy(book_path, directory_spec, sizeof book_path);
4035
  directory_spec = getenv("CRAFTY_LOG_PATH");
4228
  directory_spec = getenv("CRAFTY_LOG_PATH");
4036
  if (directory_spec)
4229
  if (directory_spec)
4037
    strcpy_s(log_path, sizeof (log_path), directory_spec); // Pierre-Marie Baty -- use safe version
4230
    strncpy(log_path, directory_spec, sizeof log_path);
4038
  directory_spec = getenv("CRAFTY_TB_PATH");
4231
  directory_spec = getenv("CRAFTY_TB_PATH");
4039
  if (directory_spec)
4232
  if (directory_spec)
4040
    strcpy_s(tb_path, sizeof (tb_path), directory_spec); // Pierre-Marie Baty -- use safe version
4233
    strncpy(tb_path, directory_spec, sizeof tb_path);
4041
  directory_spec = getenv("CRAFTY_RC_PATH");
4234
  directory_spec = getenv("CRAFTY_RC_PATH");
4042
  if (directory_spec)
4235
  if (directory_spec)
4043
    strcpy_s(rc_path, sizeof (rc_path), directory_spec); // Pierre-Marie Baty -- use safe version
4236
    strncpy(rc_path, directory_spec, sizeof rc_path);
4044
  if (getenv("CRAFTY_XBOARD")) {
4237
  if (getenv("CRAFTY_XBOARD")) {
4045
    Print(4095, "feature done=0\n");
4238
    Print(-1, "feature done=0\n");
4046
    done = 0;
4239
    xboard_done = 0;
4047
  } else if (argc > 1 && !strcmp(argv[1], "xboard")) {
4240
  } else if (argc > 1 && !strcmp(argv[1], "xboard")) {
4048
    Print(4095, "feature done=0\n");
4241
    Print(-1, "feature done=0\n");
4049
    done = 0;
4242
    xboard_done = 0;
4050
  }
4243
  }
4051
/*
4244
/*
4052
 ************************************************************
4245
 ************************************************************
4053
 *                                                          *
4246
 *                                                          *
4054
 *  First, parse the command-line options and pick off the  *
4247
 *  First, parse the command-line options and pick off the  *
4055
 *  ones that need to be handled before any initialization  *
4248
 *  ones that need to be handled before any initialization  *
4056
 *  is attempted (mainly path commands at present.)         *
4249
 *  is attempted (mainly path commands at present.)         *
4057
 *                                                          *
4250
 *                                                          *
4058
 ************************************************************
4251
 ************************************************************
4059
 */
4252
 */
4060
  AlignedMalloc((void **) &tree, 2048, (size_t) sizeof(TREE));
4253
  AlignedMalloc((void *) ((void *) &tree), 2048, (size_t) sizeof(TREE));
4061
  block[0] = tree;
4254
  block[0] = tree;
4062
  tree->parent = 0;
4255
  memset((void *) block[0], 0, sizeof(TREE));
4063
  tree->used = 1;
-
 
4064
  tree->stop = 0;
-
 
4065
  tree->ply = 1;
4256
  tree->ply = 1;
4066
  tree->nprocs = 0;
-
 
4067
  tree->thread_id = 0;
-
 
4068
  input_stream = stdin;
4257
  input_stream = stdin;
4069
  for (i = 0; i < 512; i++)
4258
  for (i = 0; i < 512; i++)
4070
    args[i] = (char *) malloc(256);
4259
    args[i] = (char *) malloc(256);
4071
  if (argc > 1) {
4260
  if (argc > 1) {
4072
    for (i = 1; i < argc; i++) {
4261
    for (i = 1; i < argc; i++) {
4073
      if (strstr(argv[i], "path") || strstr(argv[i], "log")) {
4262
      if (strstr(argv[i], "path") || strstr(argv[i], "log") ||
-
 
4263
          strstr(argv[1], "affinity")) {
4074
        strcpy_s(buffer, sizeof (buffer), argv[i]); // Pierre-Marie Baty -- use safe version
4264
        strcpy(buffer, argv[i]);
4075
        result = Option(tree);
4265
        result = Option(tree);
4076
        if (result == 0)
4266
        if (result == 0)
4077
          printf("ERROR \"%s\" is unknown command-line option\n", buffer);
4267
          Print(2048, "ERROR \"%s\" is unknown command-line option\n",
-
 
4268
              buffer);
4078
        display = tree->position;
4269
        display = tree->position;
4079
      }
4270
      }
4080
    }
4271
    }
4081
  }
4272
  }
4082
/*
4273
/*
Line 4095... Line 4286...
4095
      sprintf(path, "%s/.craftyrc", pwd->pw_dir);
4286
      sprintf(path, "%s/.craftyrc", pwd->pw_dir);
4096
      input_stream = fopen(path, "r");
4287
      input_stream = fopen(path, "r");
4097
    }
4288
    }
4098
  if (input_stream)
4289
  if (input_stream)
4099
#else
4290
#else
4100
  sprintf_s(crafty_rc_file_spec, sizeof (crafty_rc_file_spec), "%s/crafty.rc", rc_path);
4291
  sprintf(crafty_rc_file_spec, "%s/crafty.rc", rc_path);
4101
  if ((input_stream = fopen(crafty_rc_file_spec, "r")))
4292
  if ((input_stream = fopen(crafty_rc_file_spec, "r")))
4102
#endif
4293
#endif
4103
    while (1) {
4294
    while (1) {
4104
      readstat = Read(1, buffer, sizeof (buffer)); // Pierre-Marie Baty -- use safe version
4295
      readstat = Read(1, buffer);
4105
      if (readstat < 0)
4296
      if (readstat < 0)
4106
        break;
4297
        break;
4107
      if (!strstr(buffer, "path"))
4298
      if (!strstr(buffer, "path"))
4108
        continue;
4299
        continue;
4109
      result = Option(tree);
4300
      result = Option(tree);
4110
      if (result == 0)
4301
      if (result == 0)
4111
        printf("ERROR \"%s\" is unknown rc-file option\n", buffer);
4302
        Print(2048, "ERROR \"%s\" is unknown rc-file option\n", buffer);
4112
      if (input_stream == stdin)
4303
      if (input_stream == stdin)
4113
        break;
4304
        break;
4114
    }
4305
    }
4115
/*
-
 
4116
 ************************************************************
-
 
4117
 *                                                          *
-
 
4118
 *  If NUMA is enabled, report on the current machine       *
-
 
4119
 *  configuration.                                          *
-
 
4120
 *                                                          *
-
 
4121
 ************************************************************
-
 
4122
 */
-
 
4123
#if defined(NUMA) && defined(UNIX)
-
 
4124
  if (numa_available() >= 0) {
-
 
4125
    unsigned long cpus[8];
-
 
4126
 
-
 
4127
    numa_node_to_cpus(0, cpus, 64);
-
 
4128
    printf("\nMachine is NUMA, %d nodes (%d cpus/node)\n\n",
-
 
4129
        numa_max_node() + 1, PopCnt(cpus[0]));
-
 
4130
  }
-
 
4131
#endif
-
 
4132
/*
4306
/*
4133
 ************************************************************
4307
 ************************************************************
4134
 *                                                          *
4308
 *                                                          *
4135
 *   Initialize all data arrays and chess board.            *
4309
 *   Initialize all data arrays and chess board.            *
4136
 *                                                          *
4310
 *                                                          *
Line 4149... Line 4323...
4149
  if (argc > 1) {
4323
  if (argc > 1) {
4150
    for (i = 1; i < argc; i++)
4324
    for (i = 1; i < argc; i++)
4151
      if (strcmp(argv[i], "c"))
4325
      if (strcmp(argv[i], "c"))
4152
        if (!strstr(argv[i], "path")) {
4326
        if (!strstr(argv[i], "path")) {
4153
          if (strlen(argv[i]) > 255)
4327
          if (strlen(argv[i]) > 255)
4154
            Print(4095, "ERROR ignoring token %s, 255 character max\n",
4328
            Print(-1, "ERROR ignoring token %s, 255 character max\n",
4155
                argv[i]);
4329
                argv[i]);
4156
          else {
4330
          else {
4157
            strcpy_s(buffer, sizeof (buffer), argv[i]); // Pierre-Marie Baty -- use safe version
4331
            strcpy(buffer, argv[i]);
4158
            Print(128, "(info) command line option \"%s\"\n", buffer);
4332
            Print(32, "(info) command line option \"%s\"\n", buffer);
4159
            result = Option(tree);
4333
            result = Option(tree);
4160
            if (result == 0)
4334
            if (result == 0)
4161
              printf("ERROR \"%s\" is unknown command-line option\n", buffer);
4335
              Print(2048, "ERROR \"%s\" is unknown command-line option\n",
-
 
4336
                  buffer);
4162
          }
4337
          }
4163
        }
4338
        }
4164
  }
4339
  }
4165
  display = tree->position;
4340
  display = tree->position;
4166
  initialized = 1;
4341
  initialized = 1;
Line 4181... Line 4356...
4181
      sprintf(path, "%s/.craftyrc", pwd->pw_dir);
4356
      sprintf(path, "%s/.craftyrc", pwd->pw_dir);
4182
      input_stream = fopen(path, "r");
4357
      input_stream = fopen(path, "r");
4183
    }
4358
    }
4184
  if (input_stream)
4359
  if (input_stream)
4185
#else
4360
#else
4186
  sprintf_s(crafty_rc_file_spec, sizeof (crafty_rc_file_spec), "%s/crafty.rc", rc_path); // Pierre-Marie Baty -- use safe version
4361
  sprintf(crafty_rc_file_spec, "%s/crafty.rc", rc_path);
4187
  if ((input_stream = fopen(crafty_rc_file_spec, "r")))
4362
  if ((input_stream = fopen(crafty_rc_file_spec, "r")))
4188
#endif
4363
#endif
4189
    while (1) {
4364
    while (1) {
4190
      readstat = Read(1, buffer, sizeof (buffer));
4365
      readstat = Read(1, buffer);
4191
      if (readstat < 0)
4366
      if (readstat < 0)
4192
        break;
4367
        break;
4193
      if (strstr(buffer, "path"))
4368
      if (strstr(buffer, "path"))
4194
        continue;
4369
        continue;
4195
      result = Option(tree);
4370
      result = Option(tree);
4196
      if (result == 0)
4371
      if (result == 0)
4197
        printf("ERROR \"%s\" is unknown rc-file option\n", buffer);
4372
        Print(2048, "ERROR \"%s\" is unknown rc-file option\n", buffer);
4198
      if (input_stream == stdin)
4373
      if (input_stream == stdin)
4199
        break;
4374
        break;
4200
    }
4375
    }
4201
  input_stream = stdin;
4376
  input_stream = stdin;
4202
#if defined(UNIX)
4377
#if defined(UNIX)
4203
  if (xboard)
4378
  if (xboard)
4204
    signal(SIGINT, SIG_IGN);
4379
    signal(SIGINT, SIG_IGN);
4205
#endif
4380
#endif
4206
  Print(128, "\nCrafty v%s (%d cpus)\n\n", version, Max(smp_max_threads, 1));
4381
  Print(32, "\nCrafty v%s (%d cpus)\n\n", version, Max(smp_max_threads, 1));
4207
  NewGame(1);
4382
  NewGame(1);
4208
/*
4383
/*
4209
 ************************************************************
4384
 ************************************************************
4210
 *                                                          *
4385
 *                                                          *
4211
 *  Check to see if we can find a "crafty.cpf" personality  *
4386
 *  Check to see if we can find a "crafty.cpf" personality  *
Line 4214... Line 4389...
4214
 *                                                          *
4389
 *                                                          *
4215
 ************************************************************
4390
 ************************************************************
4216
 */
4391
 */
4217
  if ((personality = fopen("crafty.cpf", "r"))) {
4392
  if ((personality = fopen("crafty.cpf", "r"))) {
4218
    fclose(personality);
4393
    fclose(personality);
4219
    Print(4095, "using default personality file \"crafty.cpf\"\n");
4394
    Print(-1, "using default personality file \"crafty.cpf\"\n");
4220
    sprintf_s(buffer, sizeof (buffer), "personality load crafty.cpf"); // Pierre-Marie Baty -- use safe version
4395
    sprintf(buffer, "personality load crafty.cpf");
4221
    (void) Option(tree);
4396
    Option(tree);
4222
  }
4397
  }
4223
/*
4398
/*
4224
 ************************************************************
4399
 ************************************************************
4225
 *                                                          *
4400
 *                                                          *
4226
 *  This is the "main loop" that never ends unless the user *
4401
 *  This is the "main loop" that never ends unless the user *
Line 4287... Line 4462...
4287
      opponent_start_time = ReadClock();
4462
      opponent_start_time = ReadClock();
4288
      input_status = 0;
4463
      input_status = 0;
4289
      display = tree->position;
4464
      display = tree->position;
4290
      move = 0;
4465
      move = 0;
4291
      presult = 0;
4466
      presult = 0;
4292
      if (done == 0 && xboard) {
4467
      if (xboard_done == 0 && xboard) {
4293
        done = 1;
4468
        xboard_done = 1;
4294
        Print(128, "feature done=1\n");
4469
        Print(-1, "feature done=1\n");
4295
      }
4470
      }
4296
      do {
4471
      do {
4297
        if (presult != 2)
4472
        if (presult != 2)
4298
          presult = 0;
4473
          presult = 0;
4299
        result = 0;
4474
        result = 0;
4300
        if (pong) {
4475
        if (pong) {
4301
          Print(4095, "pong %d\n", pong);
4476
          Print(-1, "pong %d\n", pong);
4302
          pong = 0;
4477
          pong = 0;
4303
        }
4478
        }
4304
        display = tree->position;
4479
        display = tree->position;
4305
        if (presult != 2 && (move_number != 1 || !game_wtm))
4480
        if (presult != 2 && (move_number != 1 || !game_wtm))
4306
          presult = Ponder(game_wtm);
4481
          presult = Ponder(game_wtm);
Line 4311... Line 4486...
4311
        if (presult == 0 || presult == 2) {
4486
        if (presult == 0 || presult == 2) {
4312
          if (!xboard) {
4487
          if (!xboard) {
4313
            printf("%s(%d): ", SideToMove(game_wtm), move_number);
4488
            printf("%s(%d): ", SideToMove(game_wtm), move_number);
4314
            fflush(stdout);
4489
            fflush(stdout);
4315
          }
4490
          }
4316
          readstat = Read(1, buffer, sizeof (buffer));
4491
          readstat = Read(1, buffer);
4317
          if (log_file)
4492
          if (log_file)
4318
            fprintf(log_file, "%s(%d): %s\n", SideToMove(game_wtm),
4493
            fprintf(log_file, "%s(%d): %s\n", SideToMove(game_wtm),
4319
                move_number, buffer);
4494
                move_number, buffer);
4320
          if (readstat < 0 && input_stream == stdin) {
4495
          if (readstat < 0 && input_stream == stdin) {
4321
            strcpy_s(buffer, sizeof (buffer), "end"); // Pierre-Marie Baty -- use safe version
4496
            strcpy(buffer, "end");
4322
            (void) Option(tree);
4497
            Option(tree);
4323
          }
4498
          }
4324
        }
4499
        }
4325
        if (presult == 1)
4500
        if (presult == 1)
4326
          break;
4501
          break;
4327
        opponent_end_time = ReadClock();
4502
        opponent_end_time = ReadClock();
4328
        result = Option(tree);
4503
        result = Option(tree);
4329
        if (result == 0) {
4504
        if (result == 0) {
4330
          nargs = ReadParse(buffer, args, "     ;");
4505
          nargs = ReadParse(buffer, args, " \t;");
4331
          move = InputMove(tree, args[0], 0, game_wtm, 0, 0);
4506
          move = InputMove(tree, 0, game_wtm, 0, 0, args[0]);
4332
          result = !move;
4507
          result = !move;
4333
          if (move)
4508
          if (move)
4334
            last_pv.path[1] = 0;
4509
            last_pv.path[1] = 0;
4335
        } else {
4510
        } else {
4336
          input_status = 0;
4511
          input_status = 0;
Line 4349... Line 4524...
4349
 ************************************************************
4524
 ************************************************************
4350
 */
4525
 */
4351
      if (result == 0) {
4526
      if (result == 0) {
4352
        fseek(history_file, ((move_number - 1) * 2 + 1 - game_wtm) * 10,
4527
        fseek(history_file, ((move_number - 1) * 2 + 1 - game_wtm) * 10,
4353
            SEEK_SET);
4528
            SEEK_SET);
4354
        fprintf(history_file, "%9s\n", OutputMove(tree, move, 0, game_wtm));
4529
        fprintf(history_file, "%9s\n", OutputMove(tree, 0, game_wtm, move));
4355
        MakeMoveRoot(tree, move, game_wtm);
4530
        MakeMoveRoot(tree, game_wtm, move);
-
 
4531
        tree->curmv[0] = move;
4356
        time_used_opponent = opponent_end_time - opponent_start_time;
4532
        time_used_opponent = opponent_end_time - opponent_start_time;
4357
        if (!force)
4533
        if (!force)
4358
          Print(1, "              time used: %s\n",
4534
          Print(1, "              time used: %s\n",
4359
              DisplayTime(time_used_opponent));
4535
              DisplayTime(time_used_opponent));
4360
        TimeAdjust(time_used_opponent, game_wtm);
4536
        TimeAdjust(game_wtm, time_used_opponent);
4361
        game_wtm = Flip(game_wtm);
4537
        game_wtm = Flip(game_wtm);
4362
        if (game_wtm)
4538
        if (game_wtm)
4363
          move_number++;
4539
          move_number++;
4364
        move_actually_played = 1;
4540
        move_actually_played = 1;
4365
        last_opponent_move = move;
4541
        last_opponent_move = move;
Line 4381... Line 4557...
4381
 *  be satisfied with a draw, so we will claim it and end   *
4557
 *  be satisfied with a draw, so we will claim it and end   *
4382
 *  the current game.                                       *
4558
 *  the current game.                                       *
4383
 *                                                          *
4559
 *                                                          *
4384
 ************************************************************
4560
 ************************************************************
4385
 */
4561
 */
4386
        if ((draw_type = Repeat3x(tree, game_wtm)) == 1) {
4562
        if ((draw_type = Repeat3x(tree)) == 1) {
4387
          Print(128, "I claim a draw by 3-fold repetition.\n");
4563
          Print(1, "I claim a draw by 3-fold repetition.\n");
4388
          value = DrawScore(game_wtm);
4564
          value = DrawScore(game_wtm);
4389
          if (xboard)
4565
          if (xboard)
4390
            Print(4095, "1/2-1/2 {Drawn by 3-fold repetition}\n");
4566
            Print(-1, "1/2-1/2 {Drawn by 3-fold repetition}\n");
4391
        }
4567
        }
4392
        if (draw_type == 2) {
4568
        if (draw_type == 2) {
4393
          Print(128, "I claim a draw by the 50 move rule.\n");
4569
          Print(1, "I claim a draw by the 50 move rule.\n");
4394
          value = DrawScore(game_wtm);
4570
          value = DrawScore(game_wtm);
4395
          if (xboard)
4571
          if (xboard)
4396
            Print(4095, "1/2-1/2 {Drawn by 50-move rule}\n");
4572
            Print(-1, "1/2-1/2 {Drawn by 50-move rule}\n");
4397
        }
4573
        }
4398
        if (Drawn(tree, last_search_value) == 2) {
4574
        if (Drawn(tree, last_search_value) == 2) {
4399
          Print(128, "I claim a draw due to insufficient material.\n");
4575
          Print(1, "I claim a draw due to insufficient material.\n");
4400
          if (xboard)
4576
          if (xboard)
4401
            Print(4095, "1/2-1/2 {Insufficient material}\n");
4577
            Print(-1, "1/2-1/2 {Insufficient material}\n");
4402
        }
4578
        }
4403
      } else {
4579
      } else {
4404
        tree->status[1] = tree->status[0];
4580
        tree->status[1] = tree->status[0];
4405
        presult = 0;
4581
        presult = 0;
4406
      }
4582
      }
Line 4430... Line 4606...
4430
        presult = 0;
4606
        presult = 0;
4431
    }
4607
    }
4432
    ponder_move = 0;
4608
    ponder_move = 0;
4433
    thinking = 1;
4609
    thinking = 1;
4434
    if (presult != 1) {
4610
    if (presult != 1) {
4435
      strcpy_s(kibitz_text, sizeof (kibitz_text), "n/a"); // Pierre-Marie Baty -- use safe version
4611
      strcpy(kibitz_text, "n/a");
4436
      last_pv.pathd = 0;
4612
      last_pv.pathd = 0;
4437
      last_pv.pathl = 0;
4613
      last_pv.pathl = 0;
4438
      display = tree->position;
4614
      display = tree->position;
4439
      value = Iterate(game_wtm, think, 0);
4615
      value = Iterate(game_wtm, think, 0);
4440
    }
4616
    }
Line 4462... Line 4638...
4462
      if (move_number < 40 || !accept_draws)
4638
      if (move_number < 40 || !accept_draws)
4463
        drawsc = -300;
4639
        drawsc = -300;
4464
      if (value <= drawsc && (tc_increment != 0 ||
4640
      if (value <= drawsc && (tc_increment != 0 ||
4465
              tc_time_remaining[Flip(game_wtm)] >= 1000)) {
4641
              tc_time_remaining[Flip(game_wtm)] >= 1000)) {
4466
        if (xboard)
4642
        if (xboard)
4467
          Print(4095, "offer draw\n");
4643
          Print(-1, "offer draw\n");
4468
        else {
4644
        else {
4469
          Print(128, "Draw accepted.\n");
4645
          Print(1, "Draw accepted.\n");
4470
          if (audible_alarm)
4646
          if (audible_alarm)
4471
            printf("%c", audible_alarm);
4647
            printf("%c", audible_alarm);
4472
          if (speech) {
4648
          if (speech) {
4473
            strcpy_s(announce, sizeof (announce), SPEAK); // Pierre-Marie Baty -- use safe version
4649
            strcpy(announce, "./speak ");
4474
            strcat_s(announce, sizeof (announce), " Drawaccept"); // Pierre-Marie Baty -- use safe version
4650
            strcat(announce, "Drawaccept");
4475
            system(announce);
4651
            v = system(announce);
-
 
4652
            if (v != 0)
-
 
4653
              perror("main() system() error: ");
4476
          }
4654
          }
4477
        }
4655
        }
4478
        Print(4095, "1/2-1/2 {Draw agreed}\n");
4656
        Print(-1, "1/2-1/2 {Draw agreed}\n");
4479
        strcpy_s(pgn_result, sizeof (pgn_result), "1/2-1/2");
4657
        strcpy(pgn_result, "1/2-1/2");
4480
      } else {
4658
      } else {
4481
        if (!xboard)
4659
        if (!xboard) {
4482
          Print(4095, "Draw declined.\n");
4660
          Print(1, "Draw declined.\n");
-
 
4661
          if (speech) {
-
 
4662
            strcpy(announce, "./speak ");
-
 
4663
            strcat(announce, "Drawdecline");
-
 
4664
            v = system(announce);
-
 
4665
            if (v != 0)
-
 
4666
              perror("main() system() error: ");
-
 
4667
          }
-
 
4668
        }
4483
      }
4669
      }
4484
    }
4670
    }
4485
/*
4671
/*
4486
 ************************************************************
4672
 ************************************************************
4487
 *                                                          *
4673
 *                                                          *
Line 4501... Line 4687...
4501
    thinking = 0;
4687
    thinking = 0;
4502
    if (!last_pv.pathl) {
4688
    if (!last_pv.pathl) {
4503
      if (value == -MATE + 1) {
4689
      if (value == -MATE + 1) {
4504
        over = 1;
4690
        over = 1;
4505
        if (game_wtm) {
4691
        if (game_wtm) {
4506
          Print(4095, "0-1 {Black mates}\n");
4692
          Print(-1, "0-1 {Black mates}\n");
4507
          strcpy_s(pgn_result, sizeof (pgn_result), "0-1"); // Pierre-Marie Baty -- use safe version
4693
          strcpy(pgn_result, "0-1");
4508
        } else {
4694
        } else {
4509
          Print(4095, "1-0 {White mates}\n");
4695
          Print(-1, "1-0 {White mates}\n");
4510
          strcpy_s(pgn_result, sizeof (pgn_result), "1-0"); // Pierre-Marie Baty -- use safe version
4696
          strcpy(pgn_result, "1-0");
4511
        }
4697
        }
4512
        if (speech) {
4698
        if (speech) {
4513
          strcpy_s(announce, sizeof (announce), SPEAK); // Pierre-Marie Baty -- use safe version
4699
          strcpy(announce, "./speak ");
4514
          strcat_s(announce, sizeof (announce), " Checkmate"); // Pierre-Marie Baty -- use safe version
4700
          strcat(announce, "Checkmate");
4515
          system(announce);
4701
          v = system(announce);
-
 
4702
          if (v != 0)
-
 
4703
            perror("main() system() error: ");
4516
        }
4704
        }
4517
      } else {
4705
      } else {
4518
        over = 1;
4706
        over = 1;
4519
        if (!xboard) {
4707
        if (!xboard) {
4520
          Print(128, "stalemate\n");
4708
          Print(1, "stalemate\n");
4521
          if (speech) {
4709
          if (speech) {
4522
            strcpy_s(announce, sizeof (announce), SPEAK); // Pierre-Marie Baty -- use safe version
4710
            strcpy(announce, "./speak ");
4523
            strcat_s(announce, sizeof (announce), " Stalemate"); // Pierre-Marie Baty -- use safe version
4711
            strcat(announce, "Stalemate");
4524
            system(announce);
4712
            v = system(announce);
-
 
4713
            if (v != 0)
-
 
4714
              perror("main() system() error: ");
4525
          }
4715
          }
4526
        } else
4716
        } else
4527
          Print(4095, "1/2-1/2 {stalemate}\n");
4717
          Print(-1, "1/2-1/2 {stalemate}\n");
4528
      }
4718
      }
4529
    } else {
4719
    } else {
4530
      if (value > 32000 && value < MATE - 2) {
4720
      if (value > 32000 && value < MATE - 2) {
4531
        Print(128, "\nmate in %d moves.\n\n", (MATE - value) / 2);
4721
        Print(1, "\nmate in %d moves.\n\n", (MATE - value) / 2);
4532
        Kibitz(1, game_wtm, 0, 0, (MATE - value) / 2, tree->nodes_searched, 0,
4722
        Kibitz(1, game_wtm, 0, 0, (MATE - value) / 2, tree->nodes_searched, 0,
4533
            0, " ");
4723
            0, " ");
4534
      } else if (-value > 32000 && -value < MATE - 1) {
4724
      } else if (-value > 32000 && -value < MATE - 1) {
4535
        Print(128, "\nmated in %d moves.\n\n", (MATE + value) / 2);
4725
        Print(1, "\nmated in %d moves.\n\n", (MATE + value) / 2);
4536
        Kibitz(1, game_wtm, 0, 0, -(MATE + value) / 2, tree->nodes_searched,
4726
        Kibitz(1, game_wtm, 0, 0, -(MATE + value) / 2, tree->nodes_searched,
4537
            0, 0, " ");
4727
            0, 0, " ");
4538
      }
4728
      }
4539
/*
4729
/*
4540
 ************************************************************
4730
 ************************************************************
Line 4556... Line 4746...
4556
 *  "result" string if this move checkmates our opponent.   *
4746
 *  "result" string if this move checkmates our opponent.   *
4557
 *                                                          *
4747
 *                                                          *
4558
 ************************************************************
4748
 ************************************************************
4559
 */
4749
 */
4560
      if (speech) {
4750
      if (speech) {
4561
        char *moveptr = OutputMove(tree, last_pv.path[1], 0, game_wtm);
4751
        char *moveptr = OutputMove(tree, 0, game_wtm, last_pv.path[1]);
4562
 
4752
 
4563
        strcpy_s(announce, sizeof (announce), SPEAK); // Pierre-Marie Baty -- use safe version
4753
        strcpy(announce, "./speak ");
4564
        strcat_s(announce, sizeof (announce), moveptr); // Pierre-Marie Baty -- use safe version
4754
        strcat(announce, moveptr);
-
 
4755
        strcat(announce, " &");
4565
        system(announce);
4756
        v = system(announce);
-
 
4757
        if (v != 0)
-
 
4758
          perror("main() system() error: ");
4566
      }
4759
      }
4567
      if (!xboard && audible_alarm)
4760
      if (!xboard && audible_alarm)
4568
        printf("%c", audible_alarm);
4761
        printf("%c", audible_alarm);
4569
      Print(1, "%s(%d): %s\n", SideToMove(game_wtm), move_number,
4762
      Print(1, "%s(%d): %s\n", SideToMove(game_wtm), move_number,
4570
          OutputMove(tree, last_pv.path[1], 0, game_wtm));
4763
          OutputMove(tree, 0, game_wtm, last_pv.path[1]));
4571
      if (xboard)
4764
      if (xboard)
4572
        printf("move %s\n", OutputMove(tree, last_pv.path[1], 0, game_wtm));
4765
        printf("move %s\n", OutputMove(tree, 0, game_wtm, last_pv.path[1]));
-
 
4766
      fflush(stdout);
4573
      if (value == MATE - 2) {
4767
      if (value == MATE - 2) {
4574
        if (game_wtm) {
4768
        if (game_wtm) {
4575
          Print(4095, "1-0 {White mates}\n");
4769
          Print(-1, "1-0 {White mates}\n");
4576
          strcpy_s(pgn_result, sizeof (pgn_result), "1-0"); // Pierre-Marie Baty -- use safe version
4770
          strcpy(pgn_result, "1-0");
4577
        } else {
4771
        } else {
4578
          Print(4095, "0-1 {Black mates}\n");
4772
          Print(-1, "0-1 {Black mates}\n");
4579
          strcpy_s(pgn_result, sizeof (pgn_result), "0-1"); // Pierre-Marie Baty -- use safe version
4773
          strcpy(pgn_result, "0-1");
4580
        }
4774
        }
4581
      }
4775
      }
4582
      time_used = program_end_time - program_start_time;
4776
      time_used = program_end_time - program_start_time;
4583
      Print(1, "              time used: %s\n", DisplayTime(time_used));
4777
      Print(1, "              time used: %s\n", DisplayTime(time_used));
4584
      TimeAdjust(time_used, game_wtm);
4778
      TimeAdjust(game_wtm, time_used);
4585
      fseek(history_file, ((move_number - 1) * 2 + 1 - game_wtm) * 10,
4779
      fseek(history_file, ((move_number - 1) * 2 + 1 - game_wtm) * 10,
4586
          SEEK_SET);
4780
          SEEK_SET);
4587
      fprintf(history_file, "%9s\n", OutputMove(tree, last_pv.path[1], 0,
4781
      fprintf(history_file, "%9s\n", OutputMove(tree, 0, game_wtm,
4588
              game_wtm));
4782
              last_pv.path[1]));
4589
      last_search_value = value;
4783
      last_search_value = value;
4590
      if (kibitz) {
4784
      if (kibitz) {
4591
        if (kibitz_depth)
4785
        if (kibitz_depth)
4592
          Kibitz(2, game_wtm, kibitz_depth, end_time - start_time, value,
4786
          Kibitz(2, game_wtm, kibitz_depth, end_time - start_time, value,
4593
              tree->nodes_searched, idle_percent,
4787
              tree->nodes_searched, busy_percent, (int) tree->egtb_hits, // Pierre-Marie Baty -- added type cast
4594
              tree->egtb_probes_successful, kibitz_text);
4788
              kibitz_text);
4595
        else
4789
        else
4596
          Kibitz(4, game_wtm, 0, 0, 0, 0, 0, 0, kibitz_text);
4790
          Kibitz(4, game_wtm, 0, 0, 0, 0, 0, 0, kibitz_text);
4597
      }
4791
      }
4598
      MakeMoveRoot(tree, last_pv.path[1], game_wtm);
4792
      MakeMoveRoot(tree, game_wtm, last_pv.path[1]);
-
 
4793
      tree->curmv[0] = move;
4599
/*
4794
/*
4600
 ************************************************************
4795
 ************************************************************
4601
 *                                                          *
4796
 *                                                          *
4602
 *  From this point forward, we are in a state where it is  *
4797
 *  From this point forward, we are in a state where it is  *
4603
 *                                                          *
4798
 *                                                          *
Line 4612... Line 4807...
4612
 */
4807
 */
4613
      game_wtm = Flip(game_wtm);
4808
      game_wtm = Flip(game_wtm);
4614
      if (game_wtm)
4809
      if (game_wtm)
4615
        move_number++;
4810
        move_number++;
4616
      move_actually_played = 1;
4811
      move_actually_played = 1;
4617
      if ((draw_type = Repeat3x(tree, game_wtm)) == 1) {
4812
      if ((draw_type = Repeat3x(tree)) == 1) {
4618
        Print(128, "I claim a draw by 3-fold repetition after my move.\n");
4813
        Print(1, "I claim a draw by 3-fold repetition after my move.\n");
4619
        if (xboard)
4814
        if (xboard)
4620
          Print(4095, "1/2-1/2 {Drawn by 3-fold repetition}\n");
4815
          Print(-1, "1/2-1/2 {Drawn by 3-fold repetition}\n");
4621
        value = DrawScore(game_wtm);
4816
        value = DrawScore(game_wtm);
4622
      }
4817
      }
4623
      if (draw_type == 2 && last_search_value < 32000) {
4818
      if (draw_type == 2 && last_search_value < 32000) {
4624
        Print(128, "I claim a draw by the 50 move rule after my move.\n");
4819
        Print(1, "I claim a draw by the 50 move rule after my move.\n");
4625
        if (xboard)
4820
        if (xboard)
4626
          Print(4095, "1/2-1/2 {Drawn by 50-move rule}\n");
4821
          Print(-1, "1/2-1/2 {Drawn by 50-move rule}\n");
4627
        value = DrawScore(game_wtm);
4822
        value = DrawScore(game_wtm);
4628
      }
4823
      }
4629
      if (Drawn(tree, last_search_value) == 2) {
4824
      if (Drawn(tree, last_search_value) == 2) {
4630
        Print(128,
4825
        Print(1,
4631
            "I claim a draw due to insufficient material after my move.\n");
4826
            "I claim a draw due to insufficient material after my move.\n");
4632
        if (xboard)
4827
        if (xboard)
4633
          Print(4095, "1/2-1/2 {Insufficient material}\n");
4828
          Print(-1, "1/2-1/2 {Insufficient material}\n");
4634
      }
4829
      }
4635
#if !defined(TEST)
4830
#if !defined(TEST)
4636
      if (time_limit > 300)
4831
      if (time_limit > 300)
4637
#endif
4832
#endif
4638
        if (log_file)
4833
        if (log_file)
Line 4655... Line 4850...
4655
        last_pv.pathd -= 2;
4850
        last_pv.pathd -= 2;
4656
        if (last_pv.pathd > last_pv.pathl)
4851
        if (last_pv.pathd > last_pv.pathl)
4657
          last_pv.pathd = last_pv.pathl;
4852
          last_pv.pathd = last_pv.pathl;
4658
        if (last_pv.pathl == 0)
4853
        if (last_pv.pathl == 0)
4659
          last_pv.pathd = 0;
4854
          last_pv.pathd = 0;
-
 
4855
        tree->pv[0] = last_pv;
4660
      } else {
4856
      } else {
4661
        last_pv.pathd = 0;
4857
        last_pv.pathd = 0;
4662
        last_pv.pathl = 0;
4858
        last_pv.pathl = 0;
4663
        ponder_move = 0;
4859
        ponder_move = 0;
-
 
4860
        tree->pv[0] = last_pv;
4664
      }
4861
      }
4665
    }
4862
    }
4666
#if defined(TEST)
4863
#if defined(TEST)
4667
    strcpy_s(buffer, sizeof (buffer), "score"); // Pierre-Marie Baty -- use safe version
4864
    strcpy(buffer, "score");
4668
    Option(tree);
4865
    Option(tree);
4669
#endif
4866
#endif
4670
    if ((i = GameOver(game_wtm))) {
4867
    if ((i = GameOver(game_wtm))) {
4671
      if (i == 1)
4868
      if (i == 1)
4672
        Print(4095, "1/2-1/2 {stalemate}\n");
4869
        Print(-1, "1/2-1/2 {stalemate}\n");
4673
    }
4870
    }
4674
    if (book_move) {
4871
    if (book_move) {
4675
      moves_out_of_book = 0;
4872
      moves_out_of_book = 0;
4676
      predicted++;
4873
      predicted++;
4677
      if (ponder_move)
4874
      if (ponder_move)
4678
        sprintf_s(book_hint, sizeof (book_hint), "%s", OutputMove(tree, ponder_move, 0, game_wtm)); // Pierre-Marie Baty -- use safe version
4875
        sprintf(book_hint, "%s", OutputMove(tree, 0, game_wtm, ponder_move));
4679
    } else
4876
    } else
4680
      moves_out_of_book++;
4877
      moves_out_of_book++;
4681
#if defined(DEBUG)
4878
#if defined(DEBUG)
4682
    ValidatePosition(tree, 0, last_pv.path[1], "Main(2)");
4879
    ValidatePosition(tree, 0, last_pv.path[1], "Main(2)");
4683
#endif
4880
#endif
Line 4696... Line 4893...
4696
      learn_seekto[learn_positions_count] = book_learn_seekto;
4893
      learn_seekto[learn_positions_count] = book_learn_seekto;
4697
      learn_key[learn_positions_count] = book_learn_key;
4894
      learn_key[learn_positions_count] = book_learn_key;
4698
      learn_nmoves[learn_positions_count++] = book_learn_nmoves;
4895
      learn_nmoves[learn_positions_count++] = book_learn_nmoves;
4699
    }
4896
    }
4700
    if (mode == tournament_mode) {
4897
    if (mode == tournament_mode) {
4701
      strcpy_s(buffer, sizeof (buffer), "clock"); // Pierre-Marie Baty -- use safe version
4898
      strcpy(buffer, "clock");
4702
      Option(tree);
4899
      Option(tree);
4703
      Print(128, "if clocks are wrong, use 'settc' command to adjust them\n");
4900
      Print(32, "if clocks are wrong, use 'settc' command to adjust them\n");
4704
    }
4901
    }
4705
  }
4902
  }
4706
}
4903
}