![]() |
Cinnamon
1.0
chess engine
|
00001 #ifndef GENMOVES_H_ 00002 #define GENMOVES_H_ 00003 00004 #include "ChessBoard.h" 00005 using namespace _eval; 00006 class GenMoves: public ChessBoard { 00007 public: 00008 00009 GenMoves(); 00010 virtual ~GenMoves(); 00011 static const int MAX_PLY = 64; 00012 void setPerft(bool b); 00013 bool generateCaptures(const int side,u64,u64,u64*key); 00014 void generateMoves(const int side,u64); 00015 template <int side> bool generateCaptures(u64,u64,u64*key); 00016 template <int side> void generateMoves(u64); 00017 int getMoveFromSan(const string fenStr,_Tmove* move); 00018 void init(); 00019 virtual int loadFen(); 00020 virtual int loadFen(string fen); 00021 void makemove(_Tmove * move) ; 00022 void setRepetitionMapCount(int i); 00023 bool performKingShiftCapture(int side, const u64 enemies) ; 00024 bool performKnightShiftCapture( const int piece, const u64 enemies, const int side); 00025 bool performBishopCapture( const int piece, const u64 enemies, const int side, const u64 allpieces); 00026 bool performRookQueenCapture( const int piece, const u64 enemies, const int side, const u64 allpieces); 00027 template <int side> bool performPawnCapture( const u64 enemies,u64*key); 00028 template <int side> void performPawnShift( const u64 xallpieces) ; 00029 void performBishopShift( const int piece, const int side, const u64 allpieces); 00030 void performRookQueenShift( const int piece, const int side, const u64 allpieces); 00031 00032 void incListId() { 00033 listId++; 00034 ASSERT(listId < MAX_PLY && listId>=0); 00035 } 00036 00037 void decListId() { 00038 listId--; 00039 } 00040 00041 int getListCount() { 00042 return gen_list[listId].size; 00043 } 00044 00045 void pushStackMove() { 00046 pushStackMove(zobristKey); 00047 } 00048 00049 _Tmove * getMove(int i) { 00050 return &gen_list[listId].moveList[i]; 00051 } 00052 00053 void resetList() { 00054 gen_list[listId].size = 0; 00055 } 00056 00057 void makemove(_Tmove * move, u64* key,bool rep) ; 00058 bool isPinned(const int side, const uchar Position, const uchar piece); 00059 protected: 00060 static const u64 RANK_1= 0xff00ULL; 00061 static const u64 RANK_3 =0xff000000ULL; 00062 static const u64 RANK_4 =0xff00000000ULL; 00063 static const u64 RANK_6= 0xff000000000000ULL; 00064 static const uchar STANDARD_MOVE_MASK = 0b00000011; 00065 static const uchar ENPASSANT_MOVE_MASK =0b00000001; 00066 static const uchar PROMOTION_MOVE_MASK =0b00000010; 00067 static const int MAX_REP_COUNT=512; 00068 int repetitionMapCount; 00069 u64* repetitionMap; 00070 int currentPly; 00071 bool perftMode; 00072 u64 numMoves, numMovesq; 00073 int listId; 00074 _TmoveP* gen_list; 00075 _Tmove* getNextMove(_TmoveP*); 00076 u64 getKingAttackers(const int side) ; 00077 00078 void clearKillerHeuristic(); 00079 u64 getTotMoves(); 00080 template <int side> bool attackSquare(const uchar Position); 00081 void initKillerHeuristic(); 00082 #ifdef DEBUG_MODE 00083 int nCutAB, nNullMoveCut, nCutFp, nCutRazor; 00084 double betaEfficencyCumulative, betaEfficency; 00085 #endif 00086 void pushRepetition(u64); 00087 int killerHeuristic[64][64]; 00088 template <int side> bool inCheck(const int from, const int to, const uchar type, const int pieceFrom, const int pieceTo, int promotionPiece); 00089 void performCastle(const int side, const uchar type, u64*key); 00090 void unPerformCastle(const int side, const uchar type); 00091 void tryAllCastle(const int side, const u64 allpieces); 00092 void setKillerHeuristic(int from, int to, int value) ; 00093 void incKillerHeuristic(int from, int to, int value) ; 00094 void takeback(_Tmove * move, u64* key, const u64 oldkey,bool rep) ; 00095 template <uchar type> bool pushmove( const int from, const int to, const int side, int promotionPiece, int pieceFrom) ; 00096 00097 template <int side> bool inCheck() { 00098 return attackSquare<side>(BITScanForward (chessboard[KING_BLACK+side])); 00099 } 00100 00101 private: 00102 00103 static const int NO_PROMOTION =-1; 00104 static const int MAX_MOVE = 130; 00105 static const u64 TABJUMPPAWN = 0xFF00000000FF00ULL; 00106 static const u64 TABCAPTUREPAWN_RIGHT = 0xFEFEFEFEFEFEFEFEULL; 00107 static const u64 TABCAPTUREPAWN_LEFT = 0x7F7F7F7F7F7F7F7FULL; 00108 00109 template <int side> void checkJumpPawn(u64 x, const u64 xallpieces); 00110 00111 void popStackMove() { 00112 ASSERT(repetitionMapCount>0); 00113 if(--repetitionMapCount && repetitionMap[repetitionMapCount-1]==0) 00114 repetitionMapCount--; 00115 } 00116 00117 void pushStackMove( u64 key) { 00118 ASSERT(repetitionMapCount<MAX_REP_COUNT-1); 00119 repetitionMap[repetitionMapCount++]= key; 00120 } 00121 }; 00122 #endif