Skip to content

Commit

Permalink
Bench: 23511787
Browse files Browse the repository at this point in the history
  • Loading branch information
TerjeKir committed Jan 11, 2025
1 parent 8048bb9 commit 60be9fe
Show file tree
Hide file tree
Showing 8 changed files with 555 additions and 63 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();
74 changes: 52 additions & 22 deletions src/history.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,45 @@
#define ContCorrEntry(offset) (&(*(ss-offset)->contCorr)[piece((ss-1)->move)][toSq((ss-1)->move)])
#define NonPawnCorrEntry(color) (&thread->nonPawnCorrHistory[color][thread->pos.stm][NonPawnCorrIndex(&thread->pos, color)])

#define QuietHistoryUpdate(move, bonus) (HistoryBonus(QuietEntry(move), bonus, 5280))
#define PawnHistoryUpdate(move, bonus) (HistoryBonus(PawnEntry(move), bonus, 9275))
#define NoisyHistoryUpdate(move, bonus) (HistoryBonus(NoisyEntry(move), bonus, 16000))
#define ContHistoryUpdate(offset, move, bonus) (HistoryBonus(ContEntry(offset, move), bonus, 21250))
#define PawnCorrHistoryUpdate(bonus) (HistoryBonus(PawnCorrEntry(), bonus, 1662))
#define MinorCorrHistoryUpdate(bonus) (HistoryBonus(MinorCorrEntry(), bonus, 1024))
#define MajorCorrHistoryUpdate(bonus) (HistoryBonus(MajorCorrEntry(), bonus, 1024))
#define ContCorrHistoryUpdate(offset, bonus) (HistoryBonus(ContCorrEntry(offset), bonus, 1220))
#define NonPawnCorrHistoryUpdate(bonus, color) (HistoryBonus(NonPawnCorrEntry(color), bonus, 1024))
#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 MinorCorrHistoryUpdate(bonus) (HistoryBonus(MinorCorrEntry(), bonus, HistMiCDiv))
#define MajorCorrHistoryUpdate(bonus) (HistoryBonus(MajorCorrEntry(), bonus, HistMaCDiv))
#define ContCorrHistoryUpdate(offset, bonus) (HistoryBonus(ContCorrEntry(offset), bonus, HistCCDiv))
#define NonPawnCorrHistoryUpdate(bonus, color) (HistoryBonus(NonPawnCorrEntry(color), bonus, HistNPCHDiv))


extern int HistQDiv;
extern int HistPDiv;
extern int HistCDiv;
extern int HistNDiv;
extern int HistPCDiv;
extern int HistMiCDiv;
extern int HistMaCDiv;
extern int HistCCDiv;
extern int HistNPCHDiv;
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 HistGetMiCDiv;
extern int HistGetMaCDiv;
extern int HistGetCC2Div;
extern int HistGetCC3Div;
extern int HistGetCC4Div;
extern int HistGetCC5Div;
extern int HistGetCC6Div;
extern int HistGetCC7Div;
extern int HistGetNPCDiv;


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

INLINE int Bonus(Depth depth) {
return MIN(2410, 268 * depth - 310);
return MIN(HistBonusMax, HistBonusDepth * depth - HistBonusBase);
}

INLINE int Malus(Depth depth) {
return -MIN(834, 531 * depth - 148);
return -MIN(HistMalusMax, HistMalusDepth * depth - HistMalusBase);
}

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

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

INLINE int GetCorrectionHistory(const Thread *thread, const Stack *ss) {
int c = 6554 * *PawnCorrEntry()
+ 6800 * *MinorCorrEntry()
+ 3700 * *MajorCorrEntry()
+ 7000 * (*NonPawnCorrEntry(WHITE) + *NonPawnCorrEntry(BLACK))
+ 3121 * *ContCorrEntry(2)
+ 2979 * *ContCorrEntry(3)
+ 2849 * *ContCorrEntry(4)
+ 3121 * *ContCorrEntry(5)
+ 2789 * *ContCorrEntry(6)
+ 2979 * *ContCorrEntry(7);
int c = HistGetPCDiv * *PawnCorrEntry()
+ HistGetMiCDiv * *MinorCorrEntry()
+ HistGetMaCDiv * *MajorCorrEntry()
+ HistGetNPCDiv * (*NonPawnCorrEntry(WHITE) + *NonPawnCorrEntry(BLACK))
+ HistGetCC2Div * *ContCorrEntry(2)
+ HistGetCC3Div * *ContCorrEntry(3)
+ HistGetCC4Div * *ContCorrEntry(4)
+ HistGetCC5Div * *ContCorrEntry(5)
+ HistGetCC6Div * *ContCorrEntry(6)
+ HistGetCC7Div * *ContCorrEntry(7);

return c / 131072;
}
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, -1000 * 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 > 11300
|| (mp->list.moves[mp->list.next-1].score > -11100 && 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 60be9fe

Please sign in to comment.