X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fpsqt.cpp;fp=src%2Fpsqtab.h;h=32601c0a56cafbdaddc2f1f2e23f5582c0eb9eae;hp=57fb30b94f842bd1a78bc6376dd6aea11a6fc936;hb=578b21bbeedc41b6e0d1b2df46887b1636a78e2b;hpb=59f64fda4fffe595d53183caae94b1d9a2062f32 diff --git a/src/psqtab.h b/src/psqt.cpp similarity index 84% rename from src/psqtab.h rename to src/psqt.cpp index 57fb30b9..32601c0a 100644 --- a/src/psqtab.h +++ b/src/psqt.cpp @@ -17,19 +17,16 @@ along with this program. If not, see . */ -#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