Subversion Repositories Games.Chess Giants

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. /*
  2.     Protector -- a UCI chess engine
  3.  
  4.     Copyright (C) 2009-2010 Raimund Heid (Raimund_Heid@yahoo.com)
  5.  
  6.     This program is free software: you can redistribute it and/or modify
  7.     it under the terms of the GNU General Public License as published by
  8.     the Free Software Foundation, either version 3 of the License, or
  9.     (at your option) any later version.
  10.  
  11.     This program is distributed in the hope that it will be useful,
  12.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.     GNU General Public License for more details.
  15.  
  16.     You should have received a copy of the GNU General Public License
  17.     along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18.  
  19. */
  20.  
  21. #ifndef _movegeneration_h_
  22. #define _movegeneration_h_
  23.  
  24. #define CONTINUE 0
  25. #define ABORT 1
  26.  
  27. #include "protector.h"
  28. #include "position.h"
  29. #include <stdlib.h>
  30.  
  31. extern const Move NO_MOVE;
  32. extern const Move NULLMOVE;
  33.  
  34. typedef enum
  35. {
  36.    MGS_INITIALIZE,
  37.    MGS_FINISHED,
  38.    MGS_GOOD_CAPTURES_AND_PROMOTIONS,
  39.    MGS_GOOD_CAPTURES_AND_PROMOTIONS_PURE,
  40.    MGS_GOOD_CAPTURES,
  41.    MGS_KILLER_MOVES,
  42.    MGS_REST,
  43.    MGS_BAD_CAPTURES,
  44.    MGS_ESCAPES,
  45.    MGS_CHECKS,
  46.    MGS_SAFE_CHECKS,
  47.    MGS_DANGEROUS_PAWN_ADVANCES
  48. }
  49. MovegenerationStage;
  50.  
  51. extern int MG_SCHEME_STANDARD, MG_SCHEME_ESCAPE, MG_SCHEME_CHECKS,
  52.    MG_SCHEME_QUIESCENCE_WITH_CHECKS, MG_SCHEME_QUIESCENCE, MG_SCHEME_CAPTURES;
  53.  
  54. extern MovegenerationStage moveGenerationStage[100];
  55.  
  56. /**
  57.  * Check if the specified move is pseudo-legal.
  58.  */
  59. bool moveIsPseudoLegal(const Position * position, const Move move);
  60.  
  61. /**
  62.  * Check if the specified move is legal.
  63.  */
  64. bool moveIsLegal(const Position * position, const Move move);
  65.  
  66. /**
  67.  * Get the number of the available pieces moves.
  68.  */
  69. int getNumberOfPieceMoves(const Position * position, const Color color,
  70.                           const int sufficientNumberOfMoves);
  71.  
  72. /**
  73.  * Get the static exchange eval of the specified move.
  74.  */
  75. int seeMoveRec(Position * position, const Move,
  76.                Bitboard attackers[2], const int minValue);
  77.  
  78. /**
  79.  * Check if the king can escape a check situation.
  80.  */
  81. bool kingCanEscape(Position * position);
  82.  
  83. /**
  84.  * Generate moves leading out of check.
  85.  */
  86. void generateEscapes(Movelist * movelist);
  87.  
  88. /**
  89.  * Generate only check moves.
  90.  */
  91. void generateChecks(Movelist * movelist, bool allChecks);
  92.  
  93. /**
  94.  * Generate all moves except captures and promotions and the hashmove.
  95.  */
  96. void generateRestMoves(Movelist * movelist);
  97.  
  98. /**
  99.  * Generate captures and promotions.
  100.  */
  101. void generateSpecialMoves(Movelist * movelist);
  102.  
  103. /**
  104.  * Generate captures and promotions.
  105.  */
  106. void generateSpecialMovesPure(Movelist * movelist);
  107.  
  108. /**
  109.  * Generate captures.
  110.  */
  111. void generateCaptures(Movelist * movelist);
  112.  
  113. /**
  114.  * Generate pawn advances to the seventh rank.
  115.  */
  116. void generateDangerousPawnAdvances(Movelist * movelist);
  117.  
  118. /**
  119.  * Initialize this module.
  120.  *
  121.  * @return 0 if no errors occurred.
  122.  */
  123. int initializeModuleMovegeneration(void);
  124.  
  125. /**
  126.  * Test this module.
  127.  *
  128.  * @return 0 if all tests succeed.
  129.  */
  130. int testModuleMovegeneration(void);
  131.  
  132. /**
  133.  * Get the legal moves of the specified variation.
  134.  */
  135. void getLegalMoves(Variation * variation, Movelist * movelist);
  136.  
  137. /**
  138.  * Get the result of the current position.
  139.  */
  140. Gameresult getGameresult(Variation * variation);
  141.  
  142. /**
  143.  * Preset the moves of the specified movelist in order to ensure a stable
  144.  * sort process.
  145.  */
  146. void initializeMoveValues(Movelist * movelist);
  147.  
  148. /**
  149.  * Check if a movelist contains a specific move.
  150.  */
  151. bool listContainsMove(const Movelist * movelist, const Move move);
  152.  
  153. /**
  154.  * Check if a movelist contains a specific move.
  155.  */
  156. bool listContainsSimpleMove(Movelist * movelist, Square from, Square to);
  157.  
  158. /**
  159.  * Add a move at the specified position.
  160.  */
  161. void addMoveAtPosition(Movelist * movelist, const Move move,
  162.                        const int insertPosition);
  163.  
  164. /**
  165.  * Delete the move at the specified position.
  166.  */
  167. void deleteMoveAtPosition(Movelist * movelist, const int position);
  168.  
  169. /**
  170.  * Check if the given simple move (no capture, no promotion, no castling)
  171.  * is a check.
  172.  */
  173. bool simpleMoveIsCheck(const Position * position, const Move move);
  174.  
  175. void registerKillerMove(PlyInfo * plyInfo, Move killerMove);
  176. bool passiveKingIsSafe(Position * position);
  177. bool activeKingIsSafe(Position * position);
  178. int seeMove(Position * position, const Move move);
  179. int compareMoves(const void *move1, const void *move2);
  180. void sortMoves(Movelist * movelist);
  181. void initQuiescenceMovelist(Movelist * movelist,
  182.                             Position * position, PlyInfo * plyInfo,
  183.                             UINT16 * historyValue, const Move hashMove,
  184.                             const int restDepth, const bool check);
  185. void initStandardMovelist(Movelist * movelist, Position * position,
  186.                           PlyInfo * plyInfo, UINT16 * historyValue,
  187.                           const Move hashMove, const bool check);
  188. void initPreQuiescenceMovelist(Movelist * movelist,
  189.                                Position * position,
  190.                                PlyInfo * plyInfo,
  191.                                UINT16 * historyValue,
  192.                                const Move hashMove, const bool check);
  193. void initCaptureMovelist(Movelist * movelist,
  194.                          Position * position, PlyInfo * plyInfo,
  195.                          UINT16 * historyValue, const Move hashMove,
  196.                          const bool check);
  197. void initCheckMovelist(Movelist * movelist, Position * position,
  198.                        UINT16 * historyValue);
  199. void initMovelist(Movelist * movelist, Position * position);
  200. Move getNextMove(Movelist * movelist);
  201. void deferMove(Movelist * movelist, Move move);
  202.  
  203. #endif
  204.