11#include " eval.h"
22
3- // Define enum class for evaluation keys
4- enum class EvalKey {
5- DOUBLED, BACKWARD, BLOCKED, ISLANDED, ISOLATED, DBLISOLATED, WEAK, PAWNRACE,
6- SHIELD, STORM, OUTPOST, LEVER, PAWNRAM, OPENPAWN, HOLES,
7- UNDEV_KNIGHT, UNDEV_BISHOP, UNDEV_ROOK, DEV_QUEEN, OPEN_FILES,
8- SEMI_OPEN_FILES, FIANCHETTO, TRAPPED, KEY_CENTER, SPACE,
9- BADBISHOP, WEAKCOVER, MISSINGPAWN, ATTACK_ENEMY, K_OPENING,
10- K_MIDDLE, K_END, PINNED, SKEWERED, DISCOVERED, FORK,
11- TEMPO_FREEDOM_WEIGHT, TEMPO_OPPONENT_MOBILITY_PENALTY,
12- UNDERPROMOTE, PAWN, KNIGHT, BISHOP, ROOK, QUEEN
13- };
14- // Struct to hold evaluation weights
15- struct EvalWeights {
16- static const std::unordered_map<EvalKey, int > weights;
17-
18- static int getWeight (EvalKey key) {
19- auto it = weights.find (key);
20- return (it != weights.end ()) ? it->second : 0 ; // Default if key not found
21- }
22- };
233// Initialize static weight map
244const std::unordered_map<EvalKey, int > EvalWeights::weights = {
255 {EvalKey::DOUBLED, 10 }, {EvalKey::BACKWARD, 8 }, {EvalKey::BLOCKED, 5 },
@@ -36,9 +16,10 @@ const std::unordered_map<EvalKey, int> EvalWeights::weights = {
3616 {EvalKey::SKEWERED, 12 }, {EvalKey::DISCOVERED, 14 }, {EvalKey::FORK, 16 },
3717 {EvalKey::TEMPO_FREEDOM_WEIGHT, 8 }, {EvalKey::TEMPO_OPPONENT_MOBILITY_PENALTY, 6 },
3818 {EvalKey::UNDERPROMOTE, 5 }, {EvalKey::PAWN, 100 }, {EvalKey::KNIGHT, 300 },
39- {EvalKey::BISHOP, 300 }, {EvalKey::ROOK, 500 }, {EvalKey::QUEEN, 900 }
19+ {EvalKey::BISHOP, 300 }, {EvalKey::ROOK, 500 }, {EvalKey::QUEEN, 900 },
20+ {EvalKey::COUNTER, 10 }
4021};
41- std::unordered_map<U64, int > transposition; // Faster lookup
22+ // std::unordered_map<U64, int> transposition; // Faster lookup
4223
4324// Declare only missing functions
4425int evaluatePawnStructure (const chess::Position&);
@@ -129,6 +110,7 @@ std::vector<Square> scan_reversed(chess::Bitboard bb)
129110 }
130111 return iter;
131112}
113+ #ifdef DBG
132114// **1. Evaluate Bad Bishops**
133115int evaluateBadBishops (const chess::Position& board) {
134116 auto myBishops = board.pieces (chess::PieceType::underlying::BISHOP, board.sideToMove ());
@@ -144,6 +126,7 @@ int evaluateBadBishops(const chess::Position& board) {
144126 }
145127 return score;
146128}
129+ #endif
147130int evaluateKingSafety (const chess::Position& board) {
148131 // 1) One-time fetches
149132 const int side = board.sideToMove ();
@@ -192,7 +175,7 @@ int evaluateKingSafety(const chess::Position& board) {
192175 int p = phase (board); // 1=open, 2=mid, 3=end
193176 return score * phaseWeight[p];
194177}
195-
178+ # ifdef DBG
196179
197180// **4. Evaluate Rooks on Open/Semi-Open Files**
198181int evaluateRooksOnFiles (const chess::Position& board) {
@@ -943,6 +926,7 @@ int underpromote(chess::Position &board) {
943926
944927 return (lastMove.promotionType ().internal () != chess::PieceType::QUEEN) ? reward : 0 ;
945928}
929+ #endif
946930
947931// PAWN
948932const int PAWN_PSQT[2 ][64 ] = {
@@ -1126,12 +1110,15 @@ int psqt_eval(const chess::Position& board) {
11261110 }
11271111 return score; // Negate for Black
11281112}
1129-
1113+ unsigned long long evalhits= 0 ;
11301114int eval (chess::Position &board) {
1131- U64 hash = board.hash ();
1115+ /* U64 hash = board.hash();
11321116 // Faster lookup & insertion
11331117 auto [it, inserted] = transposition.emplace(hash, 0);
1134- if (!inserted) return it->second ; // Already exists, return stored evaluation
1118+ if (!inserted){
1119+ ++evalhits;
1120+ return it->second; // Already exists, return stored evaluation
1121+ }*/
11351122
11361123 // Precompute piece counts (avoid multiple function calls)
11371124 int pieceCount[10 ] = {
@@ -1155,36 +1142,40 @@ int eval(chess::Position &board) {
11551142 (EvalWeights::getWeight (EvalKey::QUEEN) * (pieceCount[4 ] - pieceCount[9 ]));
11561143
11571144 // Evaluate positional aspects
1145+ eval += evaluateKingSafety (board);
1146+ #ifdef DBG
11581147 eval += evaluatePawnStructure (board);
11591148 eval += evaluatePieces (board);
1160- eval += evaluateKingSafety (board);
11611149 eval += evaluateTactics (board);
11621150 eval += piece_activity (board);
11631151 eval += development (board);
11641152 eval += rook_placement (board);
11651153 eval += center_control (board);
11661154 eval += key_center_squares_control (board);
1167- eval += psqt_eval (board);
11681155 eval += evaluatePieceActivity (board);
1156+ #endif
1157+ eval += psqt_eval (board);
11691158 board.makeNullMove ();
11701159 // Evaluate positional aspects
1160+ eval -= evaluateKingSafety (board);
1161+ #ifdef DBG
11711162 eval -= evaluatePawnStructure (board);
11721163 eval -= evaluatePieces (board);
1173- eval -= evaluateKingSafety (board);
11741164 eval -= evaluateTactics (board);
11751165 eval -= piece_activity (board);
11761166 eval -= development (board);
11771167 eval -= rook_placement (board);
11781168 eval -= center_control (board);
11791169 eval -= key_center_squares_control (board);
1180- eval -= psqt_eval (board);
11811170 eval -= evaluatePieceActivity (board);
1171+ #endif
1172+ eval -= psqt_eval (board);
11821173 board.unmakeNullMove ();
11831174
1184- it->second = eval; // Store result
1175+ // it->second = eval; // Store result
11851176 return eval;
11861177}
1187-
1178+ # ifdef DBG
11881179// Use `const chess::Position&` to avoid copies
11891180int evaluatePawnStructure (const chess::Position& board) {
11901181 chess::Position b=board;
@@ -1199,6 +1190,7 @@ int evaluatePieces(const chess::Position& board) {
11991190 return -(evaluateBadBishops (board) + evaluateTrappedPieces (board) + evaluateKnightForks (board)) +
12001191 (evaluateFianchetto (board) + evaluateRooksOnFiles (board));
12011192}
1193+ #endif
12021194int piece_value (chess::PieceType piece) {
12031195 static const int lookup[] = {
12041196 0 , // NONE
0 commit comments