Skip to content

Commit

Permalink
Bench: 23428536
Browse files Browse the repository at this point in the history
  • Loading branch information
TerjeKir committed Dec 4, 2023
1 parent 1fa36a9 commit 8954879
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
24 changes: 24 additions & 0 deletions src/evaluate.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,13 @@ const int ThreatByRook[8] = {
S(-17, 47), S( 93,-73), S( 0, 0), S( 0, 0)
};

const int Imbalance[4][4] = {
{ S( 0, 14) },
{ S( -3, 12), S( 6,-17) },
{ S( -9, 14), S(-15,-17), S(-17,-25) },
{ S(-16, 42), S(-30, 46), S(-32, 72), S(-151,184) }
};

// KingLineDanger
const int KingLineDanger[28] = {
S( 0, 0), S( 0, 0), S( 15, 0), S( 11, 21),
Expand Down Expand Up @@ -468,6 +475,19 @@ INLINE int EvalThreats(const Position *pos, const EvalInfo *ei, const Color colo
return eval;
}

INLINE int EvalImbalance(const Position *pos, Color color) {
int eval = 0;

for (int us = KNIGHT; us < KING; us++)
for (int them = PAWN; them < us; them++) {
int count = PopCount(colorPieceBB(color, us)) * PopCount(colorPieceBB(!color, them));
eval += Imbalance[us-2][them-1] * count;
TraceCount(Imbalance[us-2][them-1]);
}

return eval;
}

// Initializes the eval info struct
INLINE void InitEvalInfo(const Position *pos, EvalInfo *ei, const Color color) {

Expand Down Expand Up @@ -550,6 +570,10 @@ int EvalPosition(const Position *pos, PawnCache pc) {
eval += EvalThreats(pos, &ei, WHITE)
- EvalThreats(pos, &ei, BLACK);

// Evaluate piece imbalance
eval += EvalImbalance(pos, WHITE)
- EvalImbalance(pos, BLACK);

TraceEval(eval);

// Adjust eval by scale factor
Expand Down
21 changes: 21 additions & 0 deletions src/tuner/tuner.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ extern const int PawnPhalanx[RANK_NB];
extern const int ThreatByMinor[8];
extern const int ThreatByRook[8];


extern const int Imbalance[4][4];

// KingLineDanger
extern const int KingLineDanger[28];

Expand Down Expand Up @@ -201,6 +204,12 @@ static void InitBaseParams(TVector tparams) {
InitBaseArray(ThreatByMinor, 8);
InitBaseArray(ThreatByRook, 8);


InitBaseArray(Imbalance[KNIGHT-2], 1);
InitBaseArray(Imbalance[BISHOP-2], 2);
InitBaseArray(Imbalance[ ROOK-2], 3);
InitBaseArray(Imbalance[ QUEEN-2], 4);

// KingLineDanger
InitBaseArray(KingLineDanger, 28);

Expand Down Expand Up @@ -273,6 +282,12 @@ static void PrintParameters(TVector updates, TVector base) {
PrintArray(ThreatByMinor, 8);
PrintArray(ThreatByRook, 8);


PrintArray(Imbalance[KNIGHT-2], 1);
PrintArray(Imbalance[BISHOP-2], 2);
PrintArray(Imbalance[ ROOK-2], 3);
PrintArray(Imbalance[ QUEEN-2], 4);

puts("\n// KingLineDanger");
PrintArray(KingLineDanger, 28);

Expand Down Expand Up @@ -340,6 +355,12 @@ static void InitCoefficients(TCoeffs coeffs) {
InitCoeffArray(ThreatByMinor, 8);
InitCoeffArray(ThreatByRook, 8);


InitCoeffArray(Imbalance[KNIGHT-2], 1);
InitCoeffArray(Imbalance[BISHOP-2], 2);
InitCoeffArray(Imbalance[ ROOK-2], 3);
InitCoeffArray(Imbalance[ QUEEN-2], 4);

// KingLineDanger
InitCoeffArray(KingLineDanger, 28);

Expand Down
3 changes: 2 additions & 1 deletion src/tuner/tuner.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
// #define NPOSITIONS (14669229) // Total FENS in the book


#define NTERMS ( 552) // Number of terms being tuned
#define NTERMS ( 562) // Number of terms being tuned
#define MAXEPOCHS ( 10000) // Max number of epochs allowed
#define REPORTING ( 50) // How often to print the new parameters
#define NPARTITIONS ( 64) // Total thread partitions
Expand Down Expand Up @@ -97,6 +97,7 @@ typedef struct EvalTrace {
int PawnPhalanx[RANK_NB][COLOR_NB];
int ThreatByMinor[8][COLOR_NB];
int ThreatByRook[8][COLOR_NB];
int Imbalance[4][4][COLOR_NB];
int KingLineDanger[28][COLOR_NB];
int Mobility[4][28][COLOR_NB];

Expand Down

0 comments on commit 8954879

Please sign in to comment.