X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fpsqt.cpp;h=41a9b499b4c4611dc1f8bd9ec7cfde46db3d104f;hp=2fd7d1cb02235ecd11c962a8f556c55b3f78dbd9;hb=7ae3c05795e79c9bd945607cdcfb08198f4c4b45;hpb=411e704fdf5afac1bbfa8a28b86751501e0eed95 diff --git a/src/psqt.cpp b/src/psqt.cpp index 2fd7d1cb..41a9b499 100644 --- a/src/psqt.cpp +++ b/src/psqt.cpp @@ -2,6 +2,7 @@ Stockfish, a UCI chess playing engine derived from Glaurung 2.1 Copyright (C) 2004-2008 Tord Romstad (Glaurung author) Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad + Copyright (C) 2015-2016 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad Stockfish is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -17,8 +18,15 @@ along with this program. If not, see . */ +#include + #include "types.h" +Value PieceValue[PHASE_NB][PIECE_NB] = { + { VALUE_ZERO, PawnValueMg, KnightValueMg, BishopValueMg, RookValueMg, QueenValueMg }, + { VALUE_ZERO, PawnValueEg, KnightValueEg, BishopValueEg, RookValueEg, QueenValueEg } +}; + namespace PSQT { #define S(mg, eg) make_score(mg, eg) @@ -31,13 +39,12 @@ const Score Bonus[][RANK_NB][int(FILE_NB) / 2] = { { }, { // Pawn { S( 0, 0), S( 0, 0), S( 0, 0), S( 0, 0) }, - { S(-19, 5), S( 1,-4), S( 7, 8), S( 3,-2) }, - { S(-26,-6), S( -7,-5), S( 19, 5), S(24, 4) }, - { S(-25, 1), S(-14, 3), S( 16,-8), S(31,-3) }, - { S(-14, 6), S( 0, 9), S( -1, 7), S(17,-6) }, - { S(-14, 6), S(-13,-5), S(-10, 2), S(-6, 4) }, - { S(-12, 1), S( 15,-9), S( -8, 1), S(-4,18) }, - { S( 0, 0), S( 0, 0), S( 0, 0), S( 0, 0) } + { S(-16, 7), S( 1,-4), S( 7, 8), S( 3,-2) }, + { S(-23,-4), S( -7,-5), S( 19, 5), S(24, 4) }, + { S(-22, 3), S(-14, 3), S( 20,-8), S(35,-3) }, + { S(-11, 8), S( 0, 9), S( 3, 7), S(21,-6) }, + { S(-11, 8), S(-13,-5), S( -6, 2), S(-2, 4) }, + { S( -9, 3), S( 15,-9), S( -8, 1), S(-4,18) } }, { // Knight { S(-143, -97), S(-96,-82), S(-80,-46), S(-73,-14) }, @@ -93,24 +100,25 @@ const Score Bonus[][RANK_NB][int(FILE_NB) / 2] = { #undef S -Score psq[COLOR_NB][PIECE_TYPE_NB][SQUARE_NB]; +Score psq[PIECE_NB][SQUARE_NB]; -// init() initializes piece square tables: the white halves of the tables are +// init() initializes piece-square tables: the white halves of the tables are // copied from Bonus[] 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) + for (Piece pc = W_PAWN; pc <= W_KING; ++pc) { - PieceValue[MG][make_piece(BLACK, pt)] = PieceValue[MG][pt]; - PieceValue[EG][make_piece(BLACK, pt)] = PieceValue[EG][pt]; + PieceValue[MG][~pc] = PieceValue[MG][pc]; + PieceValue[EG][~pc] = PieceValue[EG][pc]; - Score v = make_score(PieceValue[MG][pt], PieceValue[EG][pt]); + Score v = make_score(PieceValue[MG][pc], PieceValue[EG][pc]); for (Square s = SQ_A1; s <= SQ_H8; ++s) { - int edgeDistance = file_of(s) < FILE_E ? file_of(s) : FILE_H - file_of(s); - psq[BLACK][pt][~s] = -(psq[WHITE][pt][s] = v + Bonus[pt][rank_of(s)][edgeDistance]); + File f = std::min(file_of(s), FILE_H - file_of(s)); + psq[ pc][ s] = v + Bonus[pc][rank_of(s)][f]; + psq[~pc][~s] = -psq[pc][s]; } } }