Refactor evaluation functions
[purplehaze.git] / src / eval.h
blob0efc1560ee366242a352715d0bc5830b440364f0
1 /* Copyright (C) 2007-2011 Vincent Ollivier
3 * Purple Haze is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
8 * Purple Haze is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #ifndef EVAL_H
18 #define EVAL_H
20 #include "common.h"
22 // Specific bonus and malus
23 static const int CASTLE_BONUS = 100;
24 static const int BISHOP_PAIR_BONUS = 40;
25 static const int OPEN_FILE_BONUS = 30;
26 static const int HALF_OPEN_FILE_BONUS = 15;
27 static const int REDUNDANCY_MALUS = -10;
28 static const int BREAKING_CASTLE_MALUS = -40;
29 static const int NO_PAWNS_MALUS = -50;
31 static const int PIECE_VALUE[] = {
32 0, // Empty piece
33 100, // Pawn
34 325, // Knight
35 325, // Bishop
36 500, // Rook
37 965, // Queen (Rook + Minor + Pawn + Bishop Pair)
38 10000, // King
41 // Pieces values adjustments based on the number of pawns
42 static const int PAWNS_ADJUSTEMENT[][9] = {
43 { 0, 0, 0, 0, 0, 0, 0, 0, 0 }, // Empty
44 { 0, 0, 0, 0, 0, 0, 0, 0, 0 }, // Pawns
45 { -30, -24, -18, -12, -6, 0, 6, 12, 18 }, // Knights
46 { -15, -12, -9, -6, -3, 0, 3, 6, 9 }, // Bishops
47 { 60, 48, 36, 24, 12, 0, -12, -24, -36 }, // Rooks
48 { 30, 24, 18, 12, 6, 0, 0, 0, 0 }, // Queens
49 { 0, 0, 0, 0, 0, 0, 0, 0, 0 } // King
52 static const int MULTI_PAWNS_MALUS[] = { // Pawns on the same file
53 0, -5, -50, -75, -100, -100, -100
56 // Game phase used in tapered evaluation
57 enum Phase : unsigned char { OPENING, ENDING };
58 static const Phase PHASES[] = { OPENING, ENDING };
60 // Coefficient of each type of piece to determine the game phase
61 static const int PHASE_COEF[] = { 0, 1, 2, 2, 4, 8, 0 };
63 // Opening number
64 static const int PHASE_MAX = 16 * PHASE_COEF[PAWN] +
65 4 * PHASE_COEF[KNIGHT] +
66 4 * PHASE_COEF[BISHOP] +
67 4 * PHASE_COEF[ROOK] +
68 2 * PHASE_COEF[QUEEN]; // == 64
70 // PST parameters
71 static const int BORDER_MALUS = -5;
72 static const int CENTER_BONUS[] = {
73 0, 0, 1, 2, 2, 1, 0, 0
75 static const int PAWN_FILES_VALUES[] = {
76 -15, -5, 1, 5, 5, 1, -5, -15
78 static const int OPENING_RANKS_BONUS[][8] = {
79 { 0, 0, 0, 0, 0, 0, 0, 0 }, // Dummy for PieceType EMPTY
80 { 0, -10, -5, 5, 4, 3, 0, 0 }, // Pawns
81 { 0, 1, 2, 4, 4, 2, 0, 0 }, // Knights
82 { 0, 1, 2, 3, 3, 2, 0, 0 }, // Bishops
83 { 30, 0, 0, 0, 0, 0, 0, 0 }, // Rooks
84 { -5, 1, 2, 3, 3, 2, 1, 0 }, // Queens
85 { 0, -15, -40, -40, -40, -40, -40, -40,} // King
88 inline static bool has_bishop_pair(const Color c, const Pieces &pieces)
90 assert(pieces.count(c, BISHOP) == 2);
91 const Square fb = pieces.position(c, BISHOP, 0);
92 const Square sb = pieces.position(c, BISHOP, 1);
93 return !Board::is_same_color(fb, sb);
96 #endif /* !EVAL_H */