]> git.sesse.net Git - stockfish/blobdiff - src/psqt.cpp
Split PSQT init from Position init
[stockfish] / src / psqt.cpp
similarity index 84%
rename from src/psqtab.h
rename to src/psqt.cpp
index 57fb30b94f842bd1a78bc6376dd6aea11a6fc936..32601c0a56cafbdaddc2f1f2e23f5582c0eb9eae 100644 (file)
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
-#ifndef PSQTAB_H_INCLUDED
-#define PSQTAB_H_INCLUDED
-
 #include "types.h"
 
-#define S(mg, eg) make_score(mg, eg)
-
+namespace PSQT {
 
-/// PSQT[PieceType][Square] contains Piece-Square scores. For each piece type on
-/// a given square a (middlegame, endgame) score pair is assigned. PSQT is defined
-/// for the white side and the tables are symmetric for the black side.
+#define S(mg, eg) make_score(mg, eg)
 
-static const Score PSQT[][SQUARE_NB] = {
+/// BaseTable[PieceType][Square] contains Piece-Square scores. For each piece
+/// type on a given square a (middlegame, endgame) score pair is assigned. Table
+/// is defined just for the white side; it is symmetric for the black side.
+const Score BaseTable[][SQUARE_NB] = {
   { },
   { // Pawn
    S(  0, 0), S(  0, 0), S( 0, 0), S( 0, 0), S( 0, 0), S( 0, 0), S(  0, 0), S(  0, 0),
@@ -95,4 +92,23 @@ static const Score PSQT[][SQUARE_NB] = {
 
 #undef S
 
-#endif // #ifndef PSQTAB_H_INCLUDED
+Score psq[COLOR_NB][PIECE_TYPE_NB][SQUARE_NB];
+
+// init() initializes piece square tables: the white halves of the tables are
+// copied from BaseTable[] adding the piece value, then the black halves of the
+// tables are initialized by flipping and changing the sign of the white scores.
+void init() {
+
+  for (PieceType pt = PAWN; pt <= KING; ++pt)
+  {
+      PieceValue[MG][make_piece(BLACK, pt)] = PieceValue[MG][pt];
+      PieceValue[EG][make_piece(BLACK, pt)] = PieceValue[EG][pt];
+
+      Score v = make_score(PieceValue[MG][pt], PieceValue[EG][pt]);
+
+      for (Square s = SQ_A1; s <= SQ_H8; ++s)
+          psq[BLACK][pt][~s] = -(psq[WHITE][pt][ s] = (v + BaseTable[pt][s]));
+  }
+}
+
+} // namespace PSQT