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

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include "chess.h"
  4. #include "data.h"
  5.  
  6. /* last modified 03/14/96 */
  7. /*
  8. ********************************************************************************
  9. *                                                                              *
  10. *   Phase() is use to determine the phase of the game: opening, middlegame or  *
  11. *   endgame.  the three phases are identified by the following criteria:       *
  12. *                                                                              *
  13. *   (a) opening:  if any minor pieces are still on their original squares, or  *
  14. *       the king has not yet castled nor given up the right to castle, then    *
  15. *       opening development rules still apply.                                 *
  16. *   (b) middle-game:  if the opening criteria are not met, and the end-game    *
  17. *       criteria are not met, then all that's left is a middle-game.           *
  18. *   (c) end-game:  if both sides have less than 17 points of material, not     *
  19. *       counting pawns, (Q=9, R=5, BN=3) then we are in an end-game.           *
  20. *                                                                              *
  21. ********************************************************************************
  22. */
  23. void Phase(void)
  24. {
  25.   int t_opening, t_middle_game, t_end_game;
  26.   TREE *tree=local[0];
  27.  
  28. /*
  29.  ----------------------------------------------------------
  30. |                                                          |
  31. |   if the side-to-move has not yet lost the right to      |
  32. |   castle, then this is still an opening position.        |
  33. |                                                          |
  34.  ----------------------------------------------------------
  35. */
  36.   t_opening=opening;
  37.   t_middle_game=middle_game;
  38.   t_end_game=end_game;
  39.   if (opening) {
  40.     do {
  41.       if (move_number < 26) {
  42.         if (root_wtm) {
  43.           if (WhiteCastle(1)>0) break;
  44.           if (And(WhiteBishops,white_minor_pieces)) break;
  45.           if (And(WhiteKnights,white_minor_pieces)) break;
  46.         }
  47.         else {
  48.           if (BlackCastle(1)>0) break;
  49.           if (And(BlackBishops,black_minor_pieces)) break;
  50.           if (And(BlackKnights,black_minor_pieces)) break;
  51.         }
  52.       }
  53.       opening=0;
  54.       middle_game=1;
  55.       end_game=0;
  56.     } while (0);
  57.   }
  58. /*
  59.  ----------------------------------------------------------
  60. |                                                          |
  61. |   if the piece point count drops below 17 (two rooks and |
  62. |   two minor pieces) then this is an end-game.            |
  63. |                                                          |
  64.  ----------------------------------------------------------
  65. */
  66.   if (TotalWhitePieces < 14 && TotalBlackPieces < 14) {
  67.     opening=0;
  68.     middle_game=0;
  69.     end_game=1;
  70.   }
  71.   if (opening && opening != t_opening)
  72.     Print(128,"opening phase\n");
  73.   else if (middle_game && middle_game != t_middle_game)
  74.     Print(128,"middle-game phase\n");
  75.   else if (end_game != t_end_game)
  76.     Print(128,"end-game phase\n");
  77. }
  78.