]> git.sesse.net Git - stockfish/commitdiff
Integrate gains table in History
authorMarco Costalba <mcostalba@gmail.com>
Wed, 27 Jan 2010 10:19:56 +0000 (11:19 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Wed, 27 Jan 2010 10:22:38 +0000 (11:22 +0100)
This will be useful to use gains table in move
ordering along with history table.

No functional change and big code remove.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
src/Makefile
src/history.cpp
src/history.h
src/maxgain.cpp [deleted file]
src/maxgain.h [deleted file]
src/search.cpp

index aa7d97f870f3abbb020a534181b89975b6502a42..dafea2ddba2c649d4d8248d5fd6a34ec6223cbf3 100644 (file)
@@ -68,7 +68,7 @@ LDFLAGS  = -lpthread
 OBJS = application.o bitboard.o pawns.o material.o endgame.o evaluate.o main.o \
        misc.o move.o movegen.o history.o movepick.o search.o piece.o \
        position.o direction.o tt.o value.o uci.o ucioption.o \
-       maxgain.o mersenne.o book.o bitbase.o san.o benchmark.o
+       mersenne.o book.o bitbase.o san.o benchmark.o
 
 
 ### General rules. Do not change
index 22116412c863c4e0a5efadbed4abf61931eb7e2b..8c20f7e0578feb521aa54b10bf25da7e2089f7ff 100644 (file)
@@ -42,6 +42,7 @@ History::History() { clear(); }
 
 void History::clear() {
   memset(history, 0, 2 * 8 * 64 * sizeof(int));
+  memset(maxStaticValueDelta, 0, 16 * 64 * 64 * sizeof(int));
 }
 
 
@@ -94,3 +95,21 @@ int History::move_ordering_score(Piece p, Square to) const {
 
   return history[p][to];
 }
+
+
+/// History::set_gain() and History::gain() store and retrieve the
+/// gain of a move given the delta of the static position evaluations
+/// before and after the move.
+
+void History::set_gain(Piece p, Square from, Square to, Value delta)
+{
+  if (delta >= maxStaticValueDelta[p][from][to])
+      maxStaticValueDelta[p][from][to] = delta;
+  else
+      maxStaticValueDelta[p][from][to]--;
+}
+
+Value History::gain(Piece p, Square from, Square to) const
+{
+  return Value(maxStaticValueDelta[p][from][to]);
+}
index ddab6cd09f442b57e139d3e2e146c35711c75cc8..b12169471842a50a6b85be1314082646462f1062 100644 (file)
@@ -28,6 +28,7 @@
 #include "depth.h"
 #include "move.h"
 #include "piece.h"
+#include "value.h"
 
 
 ////
@@ -49,9 +50,12 @@ public:
   void success(Piece p, Square to, Depth d);
   void failure(Piece p, Square to, Depth d);
   int move_ordering_score(Piece p, Square to) const;
+  void set_gain(Piece p, Square from, Square to, Value delta);
+  Value gain(Piece p, Square from, Square to) const;
 
 private:
   int history[16][64];  // [piece][square]
+  int maxStaticValueDelta[16][64][64];  // [piece][from_square][to_square]
 };
 
 
diff --git a/src/maxgain.cpp b/src/maxgain.cpp
deleted file mode 100644 (file)
index 394cc22..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
-  Stockfish, a UCI chess playing engine derived from Glaurung 2.1
-  Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
-  Copyright (C) 2008-2009 Marco Costalba
-
-  Stockfish is free software: you can redistribute it and/or modify
-  it under the terms of the GNU General Public License as published by
-  the Free Software Foundation, either version 3 of the License, or
-  (at your option) any later version.
-
-  Stockfish is distributed in the hope that it will be useful,
-  but WITHOUT ANY WARRANTY; without even the implied warranty of
-  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-  GNU General Public License for more details.
-
-  You should have received a copy of the GNU General Public License
-  along with this program.  If not, see <http://www.gnu.org/licenses/>.
-*/
-
-
-////
-//// Includes
-////
-
-#include <cassert>
-#include <cstring>
-
-#include "maxgain.h"
-#include "value.h"
-
-////
-//// Functions
-////
-
-
-/// Constructor
-
-MaxGain::MaxGain() { clear(); }
-
-
-/// MaxGain::clear() clears the table
-
-void MaxGain::clear() {
-  memset(maxStaticValueDelta, 0, 16 * 64 * 64 * sizeof(int));
-}
-
-
-/// MaxGain::store
-
-void MaxGain::store(Piece p, Square from, Square to, Value delta)
-{
-  if (delta >= maxStaticValueDelta[p][from][to])
-    maxStaticValueDelta[p][from][to] = delta;
-  else
-    maxStaticValueDelta[p][from][to]--;
-}
-
-// MaxGain::retrieve
-
-Value MaxGain::retrieve(Piece p, Square from, Square to)
-{
-  return (Value) maxStaticValueDelta[p][from][to];
-}
diff --git a/src/maxgain.h b/src/maxgain.h
deleted file mode 100644 (file)
index 2b7777b..0000000
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
-  Stockfish, a UCI chess playing engine derived from Glaurung 2.1
-  Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
-  Copyright (C) 2008-2009 Marco Costalba
-
-  Stockfish is free software: you can redistribute it and/or modify
-  it under the terms of the GNU General Public License as published by
-  the Free Software Foundation, either version 3 of the License, or
-  (at your option) any later version.
-
-  Stockfish is distributed in the hope that it will be useful,
-  but WITHOUT ANY WARRANTY; without even the implied warranty of
-  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-  GNU General Public License for more details.
-
-  You should have received a copy of the GNU General Public License
-  along with this program.  If not, see <http://www.gnu.org/licenses/>.
-*/
-
-
-#if !defined(MAXGAIN_H_INCLUDED)
-#define MAXGAIN_H_INCLUDED
-
-////
-//// Includes
-////
-
-#include "move.h"
-#include "piece.h"
-#include "value.h"
-
-
-////
-//// Types
-////
-
-class MaxGain {
-
-public:
-  MaxGain();
-  void clear();
-  void store(Piece p, Square from, Square to, Value delta);
-  Value retrieve(Piece p, Square from, Square to);
-
-private:
-  int maxStaticValueDelta[16][64][64];  // [piece][from_square][to_square]
-};
-
-
-#endif // !defined(MAXGAIN_H_INCLUDED)
-
index defe00d6f16fde3353b1cdf9c99840d796b8b166..2fece7cee10cf9e3891db8afe3641d845e09ed78 100644 (file)
@@ -32,7 +32,6 @@
 #include "book.h"
 #include "evaluate.h"
 #include "history.h"
-#include "maxgain.h"
 #include "misc.h"
 #include "movegen.h"
 #include "movepick.h"
@@ -264,9 +263,6 @@ namespace {
   // History table
   History H;
 
-  // MaxGain table
-  MaxGain MG;
-
   /// Functions
 
   Value id_loop(const Position& pos, Move searchMoves[]);
@@ -704,7 +700,6 @@ namespace {
     // Initialize
     TT.new_search();
     H.clear();
-    MG.clear();
     init_ss_array(ss);
     IterationInfo[1] = IterationInfoType(rml.get_move_score(0), rml.get_move_score(0));
     Iteration = 1;
@@ -1592,7 +1587,7 @@ namespace {
               if (predictedDepth >= OnePly)
                   preFutilityValueMargin = 112 * bitScanReverse32(int(predictedDepth) * int(predictedDepth) / 2);
 
-              preFutilityValueMargin += MG.retrieve(pos.piece_on(move_from(move)), move_from(move), move_to(move)) + 45;
+              preFutilityValueMargin += H.gain(pos.piece_on(move_from(move)), move_from(move), move_to(move)) + 45;
 
               futilityValueScaled = ss[ply].eval + preFutilityValueMargin - moveCount * IncrementalFutilityMargin;
 
@@ -2646,7 +2641,7 @@ namespace {
         && pos.captured_piece() == NO_PIECE_TYPE
         && !move_is_castle(m)
         && !move_is_promotion(m))
-        MG.store(pos.piece_on(move_to(m)), move_from(m), move_to(m), -(before + after));
+        H.set_gain(pos.piece_on(move_to(m)), move_from(m), move_to(m), -(before + after));
   }