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

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include "chess.h"
  4. #include "data.h"
  5. #include "evaluate.h"
  6.  
  7. /* last modified 05/18/96 */
  8. /*
  9. ********************************************************************************
  10. *                                                                              *
  11. *   PreEvaluate() is used to set the piece/square tables.  these tables        *
  12. *   contain evaluation parameters that are not dynamic in nature and don't     *
  13. *   change during the course of a single iteration.                            *
  14. *                                                                              *
  15. *   there is one piece/square table for each type of piece on the board, one   *
  16. *   for each side so that opposite sides evaluate things from their per-       *
  17. *   spective.                                                                  *
  18. *                                                                              *
  19. ********************************************************************************
  20. */
  21. void PreEvaluate(TREE *tree, int wtm)
  22. {
  23.   int i, j;
  24.   static int hashing_pawns = 0;
  25.   static int hashing_opening = 0;
  26.   static int hashing_middle_game = 0;
  27.   static int hashing_end_game = 0;
  28.   static int last_wtm = 0;
  29.   int hash_pawns=0;
  30. /*
  31.  ----------------------------------------------------------
  32. |                                                          |
  33. |   the first step is to determine if we are in the        |
  34. |   opening (not castled), middle-game, or end-game (with  |
  35. |   material <= 15 for both sides).                        |
  36. |                                                          |
  37.  ----------------------------------------------------------
  38. */
  39.   Phase();
  40. /*
  41.  ----------------------------------------------------------
  42. |                                                          |
  43. |   pawn advances.  before castling, moving the king-side  |
  44. |   pawns is a no-no.  also, the b-pawn is restrained just |
  45. |   in case we castle queen-side.                          |
  46. |                                                          |
  47.  ----------------------------------------------------------
  48. */
  49.   if (opening) {
  50.     hash_pawns=1;
  51.     pawn_advance[0]=PAWN_ADVANCE_BC_A;
  52.     pawn_advance[1]=PAWN_ADVANCE_BC_B;
  53.     pawn_advance[2]=PAWN_ADVANCE_BC_C;
  54.     pawn_advance[3]=PAWN_ADVANCE_BC_D;
  55.     pawn_advance[4]=PAWN_ADVANCE_BC_E;
  56.     pawn_advance[5]=PAWN_ADVANCE_BC_F;
  57.     pawn_advance[6]=PAWN_ADVANCE_BC_G;
  58.     pawn_advance[7]=PAWN_ADVANCE_BC_H;
  59.   }
  60.   else if (middle_game) {
  61.     hash_pawns=2;
  62.     pawn_advance[0]=PAWN_ADVANCE_A;
  63.     pawn_advance[1]=PAWN_ADVANCE_B;
  64.     pawn_advance[2]=PAWN_ADVANCE_C;
  65.     pawn_advance[3]=PAWN_ADVANCE_D;
  66.     pawn_advance[4]=PAWN_ADVANCE_E;
  67.     pawn_advance[5]=PAWN_ADVANCE_F;
  68.     pawn_advance[6]=PAWN_ADVANCE_G;
  69.     pawn_advance[7]=PAWN_ADVANCE_H;
  70.   }
  71.   else {
  72.     hash_pawns=3;
  73.     pawn_advance[0]=PAWN_ADVANCE_EG_A;
  74.     pawn_advance[1]=PAWN_ADVANCE_EG_B;
  75.     pawn_advance[2]=PAWN_ADVANCE_EG_C;
  76.     pawn_advance[3]=PAWN_ADVANCE_EG_D;
  77.     pawn_advance[4]=PAWN_ADVANCE_EG_E;
  78.     pawn_advance[5]=PAWN_ADVANCE_EG_F;
  79.     pawn_advance[6]=PAWN_ADVANCE_EG_G;
  80.     pawn_advance[7]=PAWN_ADVANCE_EG_H;
  81.   }
  82. /*
  83.  ----------------------------------------------------------
  84. |                                                          |
  85. |   white pawns.                                           |
  86. |                                                          |
  87.  ----------------------------------------------------------
  88. */
  89.   for (i=1;i<7;i++)
  90.     for (j=0;j<8;j++)
  91.       pawn_value_w[i*8+j]=pawn_advance[j]*(i-3);
  92.   for (j=A6;j<A8;j++)
  93.     pawn_value_w[j]=PAWN_JAM;
  94.   if (!end_game) {
  95.     pawn_value_w[E4]+=CENTER_PAWNS;
  96.     pawn_value_w[E5]+=CENTER_PAWNS;
  97.     pawn_value_w[E6]+=CENTER_PAWNS;
  98.     pawn_value_w[D4]+=CENTER_PAWNS;
  99.     pawn_value_w[D5]+=CENTER_PAWNS;
  100.     pawn_value_w[D6]+=CENTER_PAWNS;
  101.   }
  102. /*
  103.  ----------------------------------------------------------
  104. |                                                          |
  105. |   black pawns.                                           |
  106. |                                                          |
  107.  ----------------------------------------------------------
  108. */
  109.   for (i=6;i>0;i--)
  110.     for (j=0;j<8;j++)
  111.       pawn_value_b[i*8+j]=pawn_advance[j]*(4-i);
  112.   for (j=A2;j<A4;j++)
  113.     pawn_value_b[j]=PAWN_JAM;
  114.   if (!end_game) {
  115.     pawn_value_b[E3]+=CENTER_PAWNS;
  116.     pawn_value_b[E4]+=CENTER_PAWNS;
  117.     pawn_value_b[E5]+=CENTER_PAWNS;
  118.     pawn_value_b[D3]+=CENTER_PAWNS;
  119.     pawn_value_b[D4]+=CENTER_PAWNS;
  120.     pawn_value_b[D5]+=CENTER_PAWNS;
  121.   }
  122. /*
  123.  ----------------------------------------------------------
  124. |                                                          |
  125. |   now, if any of the values above were changed, we must  |
  126. |   clear the appropriate hash tables so that the new      |
  127. |   values will be used to compute scores.                 |
  128. |                                                          |
  129.  ----------------------------------------------------------
  130. */
  131.   if (((last_wtm            != wtm) ||
  132.        (hashing_pawns       != hash_pawns) ||
  133.        (hashing_opening     != opening) ||
  134.        (hashing_middle_game != middle_game) ||
  135.        (hashing_end_game    != end_game)) && !test_mode) {
  136. /*
  137.  ------------------------------------------------
  138. |                                                |
  139. |   if anything changed, the transposition table |
  140. |   must be cleared of positional evaluations.   |
  141. |                                                |
  142.  ------------------------------------------------
  143. */
  144.     Print(128,"              clearing hash tables\n");
  145.     ClearHashTables();
  146.   }
  147.   hashing_pawns=hash_pawns;
  148.   hashing_opening=opening;
  149.   hashing_middle_game=middle_game;
  150.   hashing_end_game=end_game;
  151.   last_wtm=wtm;
  152. }
  153.