1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-05-01 09:13:08 +00:00

Convert pieceSquareTable to 3 dimensions

No functional change.
This commit is contained in:
Marco Costalba 2013-06-09 13:05:41 +02:00
parent dd1855eb2f
commit 81e242a96d
3 changed files with 14 additions and 19 deletions

View file

@ -41,7 +41,7 @@ static const string PieceToChar(" PNBRQK pnbrqk");
CACHE_LINE_ALIGNMENT CACHE_LINE_ALIGNMENT
Score pieceSquareTable[PIECE_NB][SQUARE_NB]; Score pieceSquareTable[COLOR_NB][PIECE_TYPE_NB][SQUARE_NB];
Value PieceValue[PHASE_NB][PIECE_NB] = { Value PieceValue[PHASE_NB][PIECE_NB] = {
{ VALUE_ZERO, PawnValueMg, KnightValueMg, BishopValueMg, RookValueMg, QueenValueMg }, { VALUE_ZERO, PawnValueMg, KnightValueMg, BishopValueMg, RookValueMg, QueenValueMg },
{ VALUE_ZERO, PawnValueEg, KnightValueEg, BishopValueEg, RookValueEg, QueenValueEg } }; { VALUE_ZERO, PawnValueEg, KnightValueEg, BishopValueEg, RookValueEg, QueenValueEg } };
@ -85,17 +85,17 @@ void init() {
side = rk.rand<Key>(); side = rk.rand<Key>();
exclusion = rk.rand<Key>(); exclusion = rk.rand<Key>();
for (Piece pc = W_PAWN; pc <= W_KING; pc++) for (PieceType pt = PAWN; pt <= KING; pt++)
{ {
PieceValue[MG][~pc] = PieceValue[MG][pc]; PieceValue[MG][make_piece(BLACK, pt)] = PieceValue[MG][pt];
PieceValue[EG][~pc] = PieceValue[EG][pc]; PieceValue[EG][make_piece(BLACK, pt)] = PieceValue[EG][pt];
Score v = make_score(PieceValue[MG][pc], PieceValue[EG][pc]); Score v = make_score(PieceValue[MG][pt], PieceValue[EG][pt]);
for (Square s = SQ_A1; s <= SQ_H8; s++) for (Square s = SQ_A1; s <= SQ_H8; s++)
{ {
pieceSquareTable[ pc][ s] = (v + PSQT[pc][s]); pieceSquareTable[WHITE][pt][ s] = (v + PSQT[pt][s]);
pieceSquareTable[~pc][~s] = -(v + PSQT[pc][s]); pieceSquareTable[BLACK][pt][~s] = -(v + PSQT[pt][s]);
} }
} }
} }
@ -767,9 +767,8 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI
do_castle(from, to, rfrom, rto); do_castle(from, to, rfrom, rto);
st->psqScore += pieceSquareTable[us][ROOK][rto] - pieceSquareTable[us][ROOK][rfrom];
k ^= Zobrist::psq[us][ROOK][rfrom] ^ Zobrist::psq[us][ROOK][rto]; k ^= Zobrist::psq[us][ROOK][rfrom] ^ Zobrist::psq[us][ROOK][rto];
st->psqScore += pieceSquareTable[make_piece(us, ROOK)][rto]
- pieceSquareTable[make_piece(us, ROOK)][rfrom];
} }
if (capture) if (capture)
@ -821,7 +820,7 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI
prefetch((char*)thisThread->materialTable[st->materialKey]); prefetch((char*)thisThread->materialTable[st->materialKey]);
// Update incremental scores // Update incremental scores
st->psqScore -= pieceSquareTable[make_piece(them, capture)][capsq]; st->psqScore -= pieceSquareTable[them][capture][capsq];
// Reset rule 50 counter // Reset rule 50 counter
st->rule50 = 0; st->rule50 = 0;
@ -904,8 +903,7 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI
^ Zobrist::psq[us][PAWN][pieceCount[us][PAWN]]; ^ Zobrist::psq[us][PAWN][pieceCount[us][PAWN]];
// Update incremental score // Update incremental score
st->psqScore += pieceSquareTable[make_piece(us, promotion)][to] st->psqScore += pieceSquareTable[us][promotion][to] - pieceSquareTable[us][PAWN][to];
- pieceSquareTable[make_piece(us, PAWN)][to];
// Update material // Update material
st->npMaterial[us] += PieceValue[MG][promotion]; st->npMaterial[us] += PieceValue[MG][promotion];
@ -920,7 +918,7 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI
} }
// Update incremental scores // Update incremental scores
st->psqScore += pieceSquareTable[pc][to] - pieceSquareTable[pc][from]; st->psqScore += pieceSquareTable[us][pt][to] - pieceSquareTable[us][pt][from];
// Set capture piece // Set capture piece
st->capturedType = capture; st->capturedType = capture;
@ -1351,7 +1349,8 @@ Score Position::compute_psq_score() const {
for (Bitboard b = pieces(); b; ) for (Bitboard b = pieces(); b; )
{ {
Square s = pop_lsb(&b); Square s = pop_lsb(&b);
score += pieceSquareTable[piece_on(s)][s]; Piece pc = piece_on(s);
score += pieceSquareTable[color_of(pc)][type_of(pc)][s];
} }
return score; return score;

View file

@ -25,7 +25,7 @@
#define S(mg, eg) make_score(mg, eg) #define S(mg, eg) make_score(mg, eg)
/// PSQT[Piece][Square] contains Piece-Square scores. For each piece type on /// PSQT[PieceType][Square] contains Piece-Square scores. For each piece type on
/// a given square a (midgame, endgame) score pair is assigned. PSQT is defined /// a given square a (midgame, endgame) score pair is assigned. PSQT is defined
/// for white side, for black side the tables are symmetric. /// for white side, for black side the tables are symmetric.

View file

@ -359,10 +359,6 @@ inline Square operator~(Square s) {
return Square(s ^ 56); // Vertical flip SQ_A1 -> SQ_A8 return Square(s ^ 56); // Vertical flip SQ_A1 -> SQ_A8
} }
inline Piece operator~(Piece c) {
return Piece(c ^ 8);
}
inline Square operator|(File f, Rank r) { inline Square operator|(File f, Rank r) {
return Square((r << 3) | f); return Square((r << 3) | f);
} }