]> git.sesse.net Git - stockfish/blobdiff - src/position.cpp
Rename ei.kingDanger in ei.margin
[stockfish] / src / position.cpp
index 058fab66b13940b2db943aef8548c46b63d1e936..cbc64609641061c77b9f1e6dc34bdcdad1b2e77d 100644 (file)
@@ -71,10 +71,16 @@ struct PieceLetters : std::map<char, Piece> {
     }
 };
 
+
 ////
-//// Variables
+//// Constants and variables
 ////
 
+/// Bonus for having the side to move (modified by Joona Kiiski)
+
+static const Score TempoValue = make_score(48, 22);
+
+
 Key Position::zobrist[2][8][64];
 Key Position::zobEp[64];
 Key Position::zobCastle[16];
@@ -240,6 +246,10 @@ void Position::from_fen(const string& fen) {
   castleRightsMask[make_square(initialQRFile, RANK_1)] ^= WHITE_OOO;
   castleRightsMask[make_square(initialQRFile, RANK_8)] ^= BLACK_OOO;
 
+  isChess960 =   initialKFile  != FILE_E
+              || initialQRFile != FILE_A
+              || initialKRFile != FILE_H;
+
   find_checkers();
 
   st->key = compute_key();
@@ -346,21 +356,17 @@ const string Position::to_fen() const {
 
   if (st->castleRights != CASTLES_NONE)
   {
-      const bool Chess960 =   initialKFile  != FILE_E
-                           || initialQRFile != FILE_A
-                           || initialKRFile != FILE_H;
-
       if (can_castle_kingside(WHITE))
-          fen += Chess960 ? char(toupper(file_to_char(initialKRFile))) : 'K';
+          fen += isChess960 ? char(toupper(file_to_char(initialKRFile))) : 'K';
 
       if (can_castle_queenside(WHITE))
-          fen += Chess960 ? char(toupper(file_to_char(initialQRFile))) : 'Q';
+          fen += isChess960 ? char(toupper(file_to_char(initialQRFile))) : 'Q';
 
       if (can_castle_kingside(BLACK))
-          fen += Chess960 ? file_to_char(initialKRFile) : 'k';
+          fen += isChess960 ? file_to_char(initialKRFile) : 'k';
 
       if (can_castle_queenside(BLACK))
-          fen += Chess960 ? file_to_char(initialQRFile) : 'q';
+          fen += isChess960 ? file_to_char(initialQRFile) : 'q';
   } else
       fen += '-';
 
@@ -839,8 +845,9 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI
       // Reset rule 50 draw counter
       st->rule50 = 0;
 
-      // Update pawn hash key
+      // Update pawn hash key and prefetch in L1/L2 cache
       st->pawnKey ^= zobrist[us][PAWN][from] ^ zobrist[us][PAWN][to];
+      prefetchPawn(st->pawnKey, threadID);
 
       // Set en passant square, only if moved pawn can be captured
       if ((to ^ from) == 16)
@@ -889,7 +896,7 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI
           st->value += pst(us, promotion, to);
 
           // Update material
-          st->npMaterial[us] += piece_value_midgame(promotion);
+          st->npMaterial[us] += PieceValueMidgame[promotion];
       }
   }
 
@@ -962,7 +969,7 @@ void Position::do_capture_move(Key& key, PieceType capture, Color them, Square t
         st->pawnKey ^= zobrist[them][PAWN][capsq];
     }
     else
-        st->npMaterial[them] -= piece_value_midgame(capture);
+        st->npMaterial[them] -= PieceValueMidgame[capture];
 
     // Remove captured piece
     clear_bit(&(byColorBB[them]), capsq);
@@ -1658,7 +1665,7 @@ Key Position::compute_material_key() const {
 /// updated by do_move and undo_move when the program is running in debug mode.
 Score Position::compute_value() const {
 
-  Score result = make_score(0, 0);
+  Score result = SCORE_ZERO;
   Bitboard b;
   Square s;
 
@@ -1694,8 +1701,9 @@ Value Position::compute_non_pawn_material(Color c) const {
       while (b)
       {
           assert(piece_on(first_1(b)) == piece_of_color_and_type(c, pt));
+
           pop_1st_bit(&b);
-          result += piece_value_midgame(pt);
+          result += PieceValueMidgame[pt];
       }
   }
   return result;