home *** CD-ROM | disk | FTP | other *** search
/ Dream 57 / Amiga_Dream_57.iso / Amiga / Jeux / Reflexion / Crafty-15.19.lha / crafty-15.19 / src / resign.c < prev    next >
C/C++ Source or Header  |  1998-09-13  |  5KB  |  113 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include "chess.h"
  5. #include "data.h"
  6.  
  7. /* last modified 06/05/98 */
  8. /*
  9. ********************************************************************************
  10. *                                                                              *
  11. *   ResignOrDraw() is used to determine if the program should either resign    *
  12. *   or offer a draw.  this decision is based on two criteria:  (1) current     *
  13. *   search evaluation and (2) time remaining on opponent's clock.              *
  14. *                                                                              *
  15. *   the evaluation returned by the last search must be less than the resign    *
  16. *   threshold to trigger the resign code, or else must be exactly equal to the *
  17. *   draw score to trigger the draw code.                                       *
  18. *                                                                              *
  19. *   the opponent must have enough time to be able to win or draw the game if   *
  20. *   were played out as well.                                                   *
  21. *                                                                              *
  22. ********************************************************************************
  23. */
  24. void ResignOrDraw(TREE *tree, int value, int wtm)
  25. {
  26.   int returnv=0;
  27. /*
  28.  ----------------------------------------------------------
  29. |                                                          |
  30. |   if the game is a technical draw, where there are no    |
  31. |   pawns and material is balanced, the offer a draw.      |
  32. |                                                          |
  33.  ----------------------------------------------------------
  34. */
  35.   if(Drawn(tree,value) == 1) returnv=2;
  36. /*
  37.  ----------------------------------------------------------
  38. |                                                          |
  39. |   first check to see if the increment is 2 seconds or    |
  40. |   more.  if so, then the game is being played slowly     |
  41. |   enough that a draw offer or resignation is worth       |
  42. |   consideration.  otherwise, if the opponent has at      |
  43. |   least 30 seconds left, he can probably play the draw   |
  44. |   or win out.                                            |
  45. |                                                          |
  46. |   if the value is below the resignation threshold, and   |
  47. |   then crafty should resign and get on to the next game. |
  48. |   note that it is necessary to have a bad score for      |
  49. |   <resign_count> moves in a row before resigning.        |
  50. |                                                          |
  51.  ----------------------------------------------------------
  52. */
  53.   if ((tc_increment > 200) || (tc_time_remaining_opponent >= 3000)) {
  54.     if (resign) {
  55.       if (value < -(MATE-15)) {
  56.         if (++resign_counter >= resign_count) returnv=1;
  57.       }
  58.       else if (value<-resign*100 && value>-(MATE-100)) {
  59.         if (++resign_counter >= resign_count) returnv=1;
  60.       }
  61.       else resign_counter=0;
  62.     }
  63.   }
  64. /*
  65.  ----------------------------------------------------------
  66. |                                                          |
  67. |   if the value is exactly equal to the draw score, then  |
  68. |   crafty should offer the opponent a draw.  note that  . |
  69. |   it is necessary that the draw score occur on exactly   |
  70. |   <draw_count> moves in a row before making the offer.   |
  71. |   note also that the draw offer will be repeated every   |
  72. |   <draw_count> moves so setting this value too low can   |
  73. |   make the program behave "obnoxiously."                 |
  74. |                                                          |
  75.  ----------------------------------------------------------
  76. */
  77.   if ((tc_increment > 200) || (tc_time_remaining_opponent >= 3000)) {
  78.     if (value==DrawScore(1) && moves_out_of_book>3) {
  79.       if (++draw_counter >= draw_count) {
  80.         draw_counter=0;
  81.         returnv=3;
  82.       }
  83.     }
  84.     else draw_counter=0;
  85.   }
  86. /*
  87.  ----------------------------------------------------------
  88. |                                                          |
  89. |   now print the draw offer or resignation if appropriate |
  90. |   but be sure and do it in a form that ICC/FICS will     |
  91. |   understand if the "ics" or "xboard" flag is set.       |
  92. |                                                          |
  93.  ----------------------------------------------------------
  94. */
  95.   if (returnv == 1) {
  96.     if (xboard) Print(4095,"tellics resign\n");
  97.     if (crafty_is_white) {
  98.       Print(4095,"0-1 {White resigns}\n");
  99.       strcpy(pgn_result,"0-1");
  100.     }
  101.     else {
  102.       Print(4095,"1-0 {Black resigns}\n");
  103.       strcpy(pgn_result,"1-0");
  104.     }
  105.     LearnResult(tree,crafty_is_white);
  106.   }
  107.   if (returnv == 2) {
  108.     if (!ics && !xboard) Print(4095,"\nI offer a draw.\n\n");
  109.     else if (xboard) Print(4095,"offer draw\n");
  110.     else Print(4095,"\n*draw\n");
  111.   }
  112. }
  113.