io-chess
UCI chess engine
Loading...
Searching...
No Matches
SimpleEvalContext.h
Go to the documentation of this file.
1#pragma once
2
10
11#include "FeatureExtractor.hpp"
12#include "../Types.h"
13#include "IEvaluator.h"
14#include <algorithm>
15#include <array>
16
23struct EvalScore {
24 int mg;
25 int eg;
26 constexpr EvalScore(int m = 0, int e = 0) : mg(m), eg(e) {}
28 mg += rhs.mg;
29 eg += rhs.eg;
30 return *this;
31 }
33 mg -= rhs.mg;
34 eg -= rhs.eg;
35 return *this;
36 }
37 EvalScore operator+(const EvalScore &rhs) const {
38 return EvalScore(mg + rhs.mg, eg + rhs.eg);
39 }
40 EvalScore operator-(const EvalScore &rhs) const {
41 return EvalScore(mg - rhs.mg, eg - rhs.eg);
42 }
43};
44
54public:
56
57 // Made public so the .cpp can see them easily
58 static constexpr int PHASE_KNIGHT = 1;
59 static constexpr int PHASE_BISHOP = 1;
60 static constexpr int PHASE_ROOK = 2;
61 static constexpr int PHASE_QUEEN = 4;
62 static constexpr int TOTAL_PHASE = 24;
63 static constexpr int TEMPO_BONUS = 15;
64
65 static const Score PIECE_VALUES[6];
66 static const Score PSQT[6][64];
67 static constexpr Score BISHOP_PAIR = {30, 80};
68 static constexpr Score ROOK_OPEN_FILE = {35, 15};
69 static constexpr Score ROOK_SEMI_OPEN = {15, 10};
70 static constexpr Score PAWN_PASSED[8] = {{0, 0}, {10, 10}, {10, 20},
71 {20, 40}, {40, 80}, {80, 160},
72 {150, 250}, {0, 0}};
73 static constexpr Score PAWN_ISOLATED = {-10, -15};
74 static constexpr Score PAWN_DOUBLED = {-15, -20};
75
79 static int mirror(int sq) { return sq ^ 56; }
80
84 Score evalOneSide(const Board &board, Color us, int &phase) const;
85
89 void evalPawns(const Board &board, Color us, const Bitboard &ourPawns,
90 const Bitboard &theirPawns, Score &score) const;
91
95 void evalKingSafety(const Board &board, Color us, const Bitboard &ourPawns,
96 const Bitboard &theirPawns, Score &score) const;
97
98public:
99 SimpleEvalContext() = default;
100
108 float evaluate(const Board &board, int ply = 0) override;
109};
Standard sparse/dense feature extraction logic for chess positions.
Abstract interface for board evaluation algorithms.
static double us(Clock::time_point a, Clock::time_point b)
Definition MoECacheModel.hpp:132
Common type definitions and constants for the chess engine.
chess::Color Color
Alias for chess::Color.
Definition Types.h:17
chess::Bitboard Bitboard
Alias for chess::Bitboard.
Definition Types.h:21
chess::Board Board
Alias for chess::Board.
Definition Types.h:14
Abstract interface for evaluators.
Definition IEvaluator.h:25
static int mirror(int sq)
Mirrors a square index vertically (for black's perspective).
Definition SimpleEvalContext.h:79
static constexpr int PHASE_ROOK
Definition SimpleEvalContext.h:60
Score evalOneSide(const Board &board, Color us, int &phase) const
Evaluates features specific to one side.
static constexpr int PHASE_KNIGHT
Definition SimpleEvalContext.h:58
void evalPawns(const Board &board, Color us, const Bitboard &ourPawns, const Bitboard &theirPawns, Score &score) const
Evaluates pawn structure features.
static const Score PSQT[6][64]
Definition SimpleEvalContext.h:79
static constexpr Score BISHOP_PAIR
Definition SimpleEvalContext.h:67
static constexpr Score ROOK_OPEN_FILE
Definition SimpleEvalContext.h:68
static constexpr int PHASE_BISHOP
Definition SimpleEvalContext.h:59
SimpleEvalContext()=default
static constexpr int TEMPO_BONUS
Definition SimpleEvalContext.h:63
static constexpr int PHASE_QUEEN
Definition SimpleEvalContext.h:61
static const Score PIECE_VALUES[6]
Definition SimpleEvalContext.h:28
static constexpr Score PAWN_DOUBLED
Definition SimpleEvalContext.h:74
static constexpr int TOTAL_PHASE
Definition SimpleEvalContext.h:62
EvalScore Score
Definition SimpleEvalContext.h:55
float evaluate(const Board &board, int ply=0) override
Computes the tapered static evaluation of the board.
Definition SimpleEvalContext.cpp:169
static constexpr Score ROOK_SEMI_OPEN
Definition SimpleEvalContext.h:69
static constexpr Score PAWN_PASSED[8]
Definition SimpleEvalContext.h:70
void evalKingSafety(const Board &board, Color us, const Bitboard &ourPawns, const Bitboard &theirPawns, Score &score) const
Evaluates king safety and pawn shield quality.
static constexpr Score PAWN_ISOLATED
Definition SimpleEvalContext.h:73
Holds separate middle-game (mg) and end-game (eg) scores.
Definition SimpleEvalContext.h:23
EvalScore operator+(const EvalScore &rhs) const
Definition SimpleEvalContext.h:37
int eg
End-game evaluation score.
Definition SimpleEvalContext.h:25
int mg
Middle-game evaluation score.
Definition SimpleEvalContext.h:24
EvalScore operator-(const EvalScore &rhs) const
Definition SimpleEvalContext.h:40
constexpr EvalScore(int m=0, int e=0)
Definition SimpleEvalContext.h:26
EvalScore & operator-=(const EvalScore &rhs)
Definition SimpleEvalContext.h:32
EvalScore & operator+=(const EvalScore &rhs)
Definition SimpleEvalContext.h:27