Skip to content

Commit

Permalink
Bench: 26587524
Browse files Browse the repository at this point in the history
  • Loading branch information
TerjeKir committed Dec 18, 2024
1 parent 1401211 commit 781b182
Show file tree
Hide file tree
Showing 8 changed files with 521 additions and 59 deletions.
52 changes: 46 additions & 6 deletions src/evaluate.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const int PieceValue[2][PIECE_NB] = {
};

// Bonus for being the side to move
const int Tempo = 18;
extern int Tempo;

// Misc bonuses and maluses
const int PawnDoubled = S(-11,-48);
Expand Down Expand Up @@ -136,11 +136,49 @@ const int Mobility[4][28] = {
S(122,221), S(135,193), S(146,166), S(125,162) }
};

// KingSafety [pt-2]
const int AttackPower[4] = { 36, 22, 23, 78 };
const int CheckPower[4] = { 68, 44, 88, 92 };
const int CountModifier[8] = { 0, 0, 63, 126, 96, 124, 124, 128 };
extern int BasePower;
extern int NPower;
extern int BPower;
extern int RPower;
extern int QPower;
extern int NCPower;
extern int BCPower;
extern int RCPower;
extern int QCPower;
extern int Modifier1;
extern int Modifier2;
extern int Modifier3;
extern int Modifier4;
extern int Modifier5;
extern int Modifier6;
extern int Modifier7;
extern int Modifier8;

// KingSafety [pt-2]
int AttackPower[4] = { 0 };
int CheckPower[4] = { 0 };
int CountModifier[8] = { 0 };

void InitSafety() {
AttackPower[KNIGHT-2] = NPower;
AttackPower[BISHOP-2] = BPower;
AttackPower[ROOK -2] = RPower;
AttackPower[QUEEN -2] = QPower;

CheckPower[KNIGHT-2] = NCPower;
CheckPower[BISHOP-2] = BCPower;
CheckPower[ROOK -2] = RCPower;
CheckPower[QUEEN -2] = QCPower;

CountModifier[0] = Modifier1;
CountModifier[1] = Modifier2;
CountModifier[2] = Modifier3;
CountModifier[3] = Modifier4;
CountModifier[4] = Modifier5;
CountModifier[5] = Modifier6;
CountModifier[6] = Modifier7;
CountModifier[7] = Modifier8;
}

// Evaluates pawns
INLINE int EvalPawns(const Position *pos, EvalInfo *ei, const Color color) {
Expand Down Expand Up @@ -484,7 +522,7 @@ INLINE void InitEvalInfo(const Position *pos, EvalInfo *ei, const Color color) {
// King Safety
ei->kingZone[color] = AttackBB(KING, kingSq(color), 0);

ei->attackPower[color] = -30;
ei->attackPower[color] = BasePower;
ei->attackCount[color] = 0;

// Clear passed pawns, filled in during pawn eval
Expand All @@ -510,6 +548,8 @@ static int ScaleFactor(const Position *pos, const int eval) {
if (!(strongPawns & QueenSideBB) || !(strongPawns & KingSideBB))
pawnScale -= 20;

pawnScale = MIN(pawnScale, 128);

// Opposite-colored bishop
if ( pos->nonPawnCount[WHITE] <= 2
&& pos->nonPawnCount[BLACK] <= 2
Expand Down
3 changes: 2 additions & 1 deletion src/evaluate.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ typedef struct PawnEntry {
typedef PawnEntry PawnCache[PAWN_CACHE_SIZE];


extern const int Tempo;
extern int Tempo;
extern const int PieceValue[COLOR_NB][PIECE_NB];


Expand All @@ -60,3 +60,4 @@ INLINE int EvalPositionWhitePov(const Position *pos, PawnCache pc) {
int score = EvalPosition(pos, pc);
return sideToMove == WHITE ? score : -score;
}
void InitSafety();
62 changes: 44 additions & 18 deletions src/history.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,39 @@
#define MatCorrEntry() (&thread->matCorrHistory[thread->pos.stm][MatCorrIndex(&thread->pos)])
#define ContCorrEntry(offset) (&(*(ss-offset)->contCorr)[piece((ss-1)->move)][toSq((ss-1)->move)])

#define QuietHistoryUpdate(move, bonus) (HistoryBonus(QuietEntry(move), bonus, 5425))
#define PawnHistoryUpdate(move, bonus) (HistoryBonus(PawnEntry(move), bonus, 8325))
#define NoisyHistoryUpdate(move, bonus) (HistoryBonus(NoisyEntry(move), bonus, 14750))
#define ContHistoryUpdate(offset, move, bonus) (HistoryBonus(ContEntry(offset, move), bonus, 23000))
#define PawnCorrHistoryUpdate(bonus) (HistoryBonus(PawnCorrEntry(), bonus, 1475))
#define MatCorrHistoryUpdate(bonus) (HistoryBonus(MatCorrEntry(), bonus, 1060))
#define ContCorrHistoryUpdate(offset, bonus) (HistoryBonus(ContCorrEntry(offset), bonus, 1150))
#define QuietHistoryUpdate(move, bonus) (HistoryBonus(QuietEntry(move), bonus, HistQDiv))
#define PawnHistoryUpdate(move, bonus) (HistoryBonus(PawnEntry(move), bonus, HistPDiv))
#define NoisyHistoryUpdate(move, bonus) (HistoryBonus(NoisyEntry(move), bonus, HistNDiv))
#define ContHistoryUpdate(offset, move, bonus) (HistoryBonus(ContEntry(offset, move), bonus, HistCDiv))
#define PawnCorrHistoryUpdate(bonus) (HistoryBonus(PawnCorrEntry(), bonus, HistPCDiv))
#define MatCorrHistoryUpdate(bonus) (HistoryBonus(MatCorrEntry(), bonus, HistMCDiv))
#define ContCorrHistoryUpdate(offset, bonus) (HistoryBonus(ContCorrEntry(offset), bonus, HistCCDiv))


extern int HistQDiv;
extern int HistPDiv;
extern int HistCDiv;
extern int HistNDiv;
extern int HistPCDiv;
extern int HistMCDiv;
extern int HistCCDiv;
extern int HistBonusMax;
extern int HistBonusBase;
extern int HistBonusDepth;
extern int HistMalusMax;
extern int HistMalusBase;
extern int HistMalusDepth;
extern int HistCBonusDepthDiv;
extern int HistCBonusMin;
extern int HistCBonusMax;
extern int HistGetPCDiv;
extern int HistGetMCDiv;
extern int HistGetCC2Div;
extern int HistGetCC3Div;
extern int HistGetCC4Div;
extern int HistGetCC5Div;
extern int HistGetCC6Div;
extern int HistGetCC7Div;


INLINE int PawnStructure(const Position *pos) { return pos->pawnKey & (PAWN_HISTORY_SIZE - 1); }
Expand All @@ -53,15 +79,15 @@ INLINE void HistoryBonus(int16_t *cur, int bonus, int div) {
}

INLINE int Bonus(Depth depth) {
return MIN(2535, 275 * depth - 318);
return MIN(HistBonusMax, HistBonusDepth * depth - HistBonusBase);
}

INLINE int Malus(Depth depth) {
return -MIN(890, 538 * depth - 159);
return -MIN(HistMalusMax, HistMalusDepth * depth - HistMalusBase);
}

INLINE int CorrectionBonus(int score, int eval, Depth depth) {
return CLAMP((score - eval) * depth / 4, -197, 240);
return CLAMP((score - eval) * depth / HistCBonusDepthDiv, -HistCBonusMin, HistCBonusMax);
}

INLINE void UpdateContHistories(Stack *ss, Move move, int bonus) {
Expand Down Expand Up @@ -142,12 +168,12 @@ INLINE int GetHistory(const Thread *thread, Stack *ss, Move move) {
}

INLINE int GetCorrectionHistory(const Thread *thread, const Stack *ss) {
return *PawnCorrEntry() / 26
+ *MatCorrEntry() / 25
+ *ContCorrEntry(2) / 50
+ *ContCorrEntry(3) / 44
+ *ContCorrEntry(4) / 47
+ *ContCorrEntry(5) / 48
+ *ContCorrEntry(6) / 48
+ *ContCorrEntry(7) / 48;
return *PawnCorrEntry() / HistGetPCDiv
+ *MatCorrEntry() / HistGetMCDiv
+ *ContCorrEntry(2) / HistGetCC2Div
+ *ContCorrEntry(3) / HistGetCC3Div
+ *ContCorrEntry(4) / HistGetCC4Div
+ *ContCorrEntry(5) / HistGetCC5Div
+ *ContCorrEntry(6) / HistGetCC6Div
+ *ContCorrEntry(7) / HistGetCC7Div;
}
13 changes: 10 additions & 3 deletions src/movepicker.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@
#include "movepicker.h"


extern int ScoreMovesLimit;
extern int MPGood;
extern int MPGoodDepth;
extern int MPBad;
extern int MPBadDepth;


// Return the next best move
static Move PickNextMove(MovePicker *mp) {

Expand Down Expand Up @@ -69,7 +76,7 @@ static void ScoreMoves(MovePicker *mp, const int stage) {
: GetCaptureHistory(thread, move) + PieceValue[MG][capturing(move)];
}

SortMoves(list, -750 * mp->depth);
SortMoves(list, -ScoreMovesLimit * mp->depth);
}

// Returns the next move to try in a position
Expand All @@ -96,8 +103,8 @@ Move NextMove(MovePicker *mp) {
case NOISY_GOOD:
// Save seemingly bad noisy moves for later
while ((move = PickNextMove(mp)))
if ( mp->list.moves[mp->list.next-1].score > 12000
|| (mp->list.moves[mp->list.next-1].score > -11000 && SEE(pos, move, mp->threshold)))
if ( mp->list.moves[mp->list.next-1].score > MPGood
|| (mp->list.moves[mp->list.next-1].score > -MPBad && SEE(pos, move, mp->threshold)))
return move;
else
mp->list.moves[mp->bads++].move = move;
Expand Down
Loading

0 comments on commit 781b182

Please sign in to comment.