]> git.sesse.net Git - stockfish/commitdiff
Move Tempo to evaluation
authorMarco Costalba <mcostalba@gmail.com>
Mon, 9 Apr 2012 09:34:17 +0000 (10:34 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Mon, 9 Apr 2012 10:14:00 +0000 (11:14 +0100)
Apart from the semplification it is now more clear that
the actual Tempo added was half of the indicated score.
This is becuase at start compute_psq_score() added half
Tempo unit and in do_move() white/black were respectively
adding/subtracting one Tempo unit.

Now we have directly halved Tempo constant and everything
is more clear.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
src/evaluate.cpp
src/position.cpp

index 849185b67e497246048fdf508e040b1cf58b48b4..d090f4042177a04cc9975552959930a75f183d9a 100644 (file)
@@ -150,6 +150,9 @@ namespace {
 
   #undef S
 
 
   #undef S
 
+  // Bonus for having the side to move (modified by Joona Kiiski)
+  const Score Tempo = make_score(24, 11);
+
   // Rooks and queens on the 7th rank (modified by Joona Kiiski)
   const Score RookOn7thBonus  = make_score(47, 98);
   const Score QueenOn7thBonus = make_score(27, 54);
   // Rooks and queens on the 7th rank (modified by Joona Kiiski)
   const Score RookOn7thBonus  = make_score(47, 98);
   const Score QueenOn7thBonus = make_score(27, 54);
@@ -362,14 +365,15 @@ Value do_evaluate(const Position& pos, Value& margin) {
   Value margins[2];
   Score score, mobilityWhite, mobilityBlack;
 
   Value margins[2];
   Score score, mobilityWhite, mobilityBlack;
 
-  // Initialize score by reading the incrementally updated scores included
-  // in the position object (material + piece square tables).
-  score = pos.psq_score();
-
   // margins[] store the uncertainty estimation of position's evaluation
   // that typically is used by the search for pruning decisions.
   margins[WHITE] = margins[BLACK] = VALUE_ZERO;
 
   // margins[] store the uncertainty estimation of position's evaluation
   // that typically is used by the search for pruning decisions.
   margins[WHITE] = margins[BLACK] = VALUE_ZERO;
 
+  // Initialize score by reading the incrementally updated scores included
+  // in the position object (material + piece square tables) and adding
+  // Tempo bonus. Score is computed from the point of view of white.
+  score = pos.psq_score() + (pos.side_to_move() == WHITE ? Tempo : -Tempo);
+
   // Probe the material hash table
   ei.mi = pos.this_thread()->materialTable.probe(pos);
   score += ei.mi->material_value();
   // Probe the material hash table
   ei.mi = pos.this_thread()->materialTable.probe(pos);
   score += ei.mi->material_value();
index 9af42558867b52aeec7c5e525dbb8c21ed2407ee..e89477ea534d654658244d890c53d9ead3e87b07 100644 (file)
@@ -62,15 +62,8 @@ const Value PieceValueEndgame[17] = {
   RookValueEndgame, QueenValueEndgame
 };
 
   RookValueEndgame, QueenValueEndgame
 };
 
-
-namespace {
-
-  // Bonus for having the side to move (modified by Joona Kiiski)
-  const Score Tempo = make_score(48, 22);
-
-  // To convert a Piece to and from a FEN char
-  const string PieceToChar(" PNBRQK  pnbrqk  .");
-}
+// To convert a Piece to and from a FEN char
+static const string PieceToChar(" PNBRQK  pnbrqk  .");
 
 
 /// CheckInfo c'tor
 
 
 /// CheckInfo c'tor
@@ -934,9 +927,7 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI
       }
   }
 
       }
   }
 
-  // Finish
   sideToMove = ~sideToMove;
   sideToMove = ~sideToMove;
-  st->psqScore += (sideToMove == WHITE ?  Tempo : -Tempo);
 
   assert(pos_is_ok());
 }
 
   assert(pos_is_ok());
 }
@@ -1127,9 +1118,7 @@ void Position::do_castle_move(Move m) {
       // Update checkers BB
       st->checkersBB = attackers_to(king_square(~us)) & pieces(us);
 
       // Update checkers BB
       st->checkersBB = attackers_to(king_square(~us)) & pieces(us);
 
-      // Finish
       sideToMove = ~sideToMove;
       sideToMove = ~sideToMove;
-      st->psqScore += (sideToMove == WHITE ?  Tempo : -Tempo);
   }
   else
       // Undo: point our state pointer back to the previous state
   }
   else
       // Undo: point our state pointer back to the previous state
@@ -1172,7 +1161,6 @@ void Position::do_null_move(StateInfo& backupSt) {
       st->epSquare = SQ_NONE;
       st->rule50++;
       st->pliesFromNull = 0;
       st->epSquare = SQ_NONE;
       st->rule50++;
       st->pliesFromNull = 0;
-      st->psqScore += (sideToMove == WHITE ?  Tempo : -Tempo);
   }
 
   assert(pos_is_ok());
   }
 
   assert(pos_is_ok());
@@ -1406,18 +1394,15 @@ Key Position::compute_material_key() const {
 /// updated by do_move and undo_move when the program is running in debug mode.
 Score Position::compute_psq_score() const {
 
 /// updated by do_move and undo_move when the program is running in debug mode.
 Score Position::compute_psq_score() const {
 
-  Bitboard b;
   Score result = SCORE_ZERO;
   Score result = SCORE_ZERO;
+  Bitboard b = pieces();
 
 
-  for (Color c = WHITE; c <= BLACK; c++)
-      for (PieceType pt = PAWN; pt <= KING; pt++)
-      {
-          b = pieces(pt, c);
-          while (b)
-              result += pieceSquareTable[make_piece(c, pt)][pop_1st_bit(&b)];
-      }
+  while (b)
+  {
+      Square s = pop_1st_bit(&b);
+      result += pieceSquareTable[piece_on(s)][s];
+  }
 
 
-  result += (sideToMove == WHITE ? Tempo / 2 : -Tempo / 2);
   return result;
 }
 
   return result;
 }