Skip to content

Commit

Permalink
Tune! (#79) bench: 9986537
Browse files Browse the repository at this point in the history
Elo   | 8.73 +- 5.83 (95%)
SPRT  | 60.0+0.60s Threads=1 Hash=64MB
LLR   | 2.53 (-2.94, 2.94) [0.00, 3.00]
Games | N: 6366 W: 1570 L: 1410 D: 3386
Penta | [11, 663, 1680, 813, 16]
https://vast342.pythonanywhere.com/test/151/

not quite done with test but I'm sure it'll be fine lol
  • Loading branch information
Vast342 authored Apr 9, 2024
1 parent a0af318 commit c662fac
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 57 deletions.
20 changes: 20 additions & 0 deletions src/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,26 @@ extern Tunable deiDepth;

extern Tunable lmrDepth;

extern Tunable mvvPawn;
extern Tunable mvvKnight;
extern Tunable mvvBishop;
extern Tunable mvvRook;
extern Tunable mvvQueen;
extern Tunable blank;

extern Tunable seePawn;
extern Tunable seeKnight;
extern Tunable seeBishop;
extern Tunable seeRook;
extern Tunable seeQueen;

extern Tunable tmhDivisor;
extern Tunable tmsNumerator;
extern Tunable tmsDenominator;
extern Tunable tmsMultiplier;

extern std::array<Tunable *, 7> MVV_values;
extern std::array<Tunable *, 7> SEE_values;
extern std::vector<Tunable *> tunables;

void outputTunables();
Expand Down
19 changes: 8 additions & 11 deletions src/search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ int hardNodeCap = 400000;

constexpr int historyCap = 16384;

int MVV_value[7] = {112, 351, 361, 627, 1187, 0, 0};
int SEE_value[7] = {112, 351, 361, 627, 1187, 0, 0};

// Tunable Values
int killerScore = 70000;
int counterScore = 71000;
Expand Down Expand Up @@ -61,18 +58,18 @@ void Engine::resetEngine() {

int Engine::estimateMoveValue(const Board& board, const int end, const int flag) {
// starting with the end square piece
int value = SEE_value[getType(board.pieceAtIndex(end))];
int value = SEE_values[getType(board.pieceAtIndex(end))]->value;
// promotions! pawn--, newpiece++
for(int i = 0; i < 4; i++) {
if(flag == promotions[i]) {
value = SEE_value[i + 1] - SEE_value[Pawn];
value = SEE_values[i + 1]->value - SEE_values[Pawn]->value;
return value;
}
}

// Target square is empty for en passant, but you still capture a pawn
if(flag == EnPassant) {
value = SEE_value[Pawn];
value = SEE_values[Pawn]->value;
}
// castling can't capture and is never encoded as such so we don't care.
return value;
Expand All @@ -99,7 +96,7 @@ bool Engine::see(const Board& board, Move move, int threshold) {
// best case still doesn't beat threshold, not good
if(balance < 0) return false;
// worst case, we lose the piece here
balance -= SEE_value[nextVictim];
balance -= SEE_values[nextVictim]->value;
// if it's still winning in the best case scenario, we can just cut it off
if(balance >= 0) return true;
// make sure occupied bitboard knows we did the first move
Expand Down Expand Up @@ -136,7 +133,7 @@ bool Engine::see(const Board& board, Move move, int threshold) {
attackers &= occupied;
color = 1 - color;
// update balance
balance = -balance - 1 - SEE_value[nextVictim];
balance = -balance - 1 - SEE_values[nextVictim]->value;
// if you are ahead
if(balance >= 0) {
// speedrunning legality check
Expand Down Expand Up @@ -171,7 +168,7 @@ void Engine::scoreMoves(const Board& board, std::array<Move, 256> &moves, std::a
// Captures!
const int victim = getType(board.pieceAtIndex(end));
// Capthist!
values[i] = MVV_value[victim] + noisyHistoryTable[colorToMove][piece][end][victim];
values[i] = MVV_values[victim]->value + noisyHistoryTable[colorToMove][piece][end][victim];
// see!
// if the capture results in a good exchange then we can add a big boost to the score so that it's preferred over the quiet moves.
if(see(board, move, 0)) {
Expand Down Expand Up @@ -208,7 +205,7 @@ void Engine::scoreMovesQS(const Board& board, std::array<Move, 256> &moves, std:
// Captures!
const int victim = getType(board.pieceAtIndex(end));
// Capthist!
values[i] = MVV_value[victim] + qsHistoryTable[colorToMove][piece][end][victim];
values[i] = MVV_values[victim]->value + qsHistoryTable[colorToMove][piece][end][victim];
// see!
// if the capture results in a good exchange then we can add a big boost to the score so that it's preferred over the quiet moves.
if(see(board, move, 0)) {
Expand Down Expand Up @@ -281,7 +278,7 @@ int Engine::qSearch(Board &board, int alpha, int beta, int ply) {
Move move = moves[i];

// this detects bad captures
if(moveValues[i] < MVV_value[Queen] + historyCap) {
if(moveValues[i] < MVV_values[Queen]->value + historyCap) {
break;
}

Expand Down
129 changes: 90 additions & 39 deletions src/tunables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,67 +17,104 @@
*/
#include "globals.h"

Tunable aspBaseDelta("ASP_BaseDelta", 17, 1);
Tunable aspDeltaMultiplier("ASP_DeltaMultiplier", 1.67, 10);
Tunable aspBaseDelta("ASP_BaseDelta", 14, 1);
Tunable aspDeltaMultiplier("ASP_DeltaMultiplier", 1.34, 10);
Tunable aspDepthCondition("ASP_DepthCondition", 4, 1);

Tunable rfpDepthCondition("RFP_DepthCondition", 11, 1);
Tunable rfpMultiplier("RFP_Multiplier", 96, 1);
Tunable rfpDepthCondition("RFP_DepthCondition", 10, 1);
Tunable rfpMultiplier("RFP_Multiplier", 92, 1);

Tunable iirDepthCondition("IIR_DepthCondition", 4, 1);
Tunable iirDepthCondition("IIR_DepthCondition", 2, 1);

Tunable fpDepthCondition("FP_DepthCondition", 1, 1);
Tunable fpBase("FP_Base", 268, 1);
Tunable fpMultiplier("FP_Multiplier", 64, 1);
Tunable fpBase("FP_Base", 327, 1);
Tunable fpMultiplier("FP_Multiplier", 44, 1);

Tunable lmpBase("LMP_Base", 2, 1);// No divisor adjustment
Tunable lmpBase("LMP_Base", 1, 1);// No divisor adjustment

Tunable sprDepthCondition("SPR_DepthCondition", 4, 1);
Tunable sprCaptureThreshold("SPR_CaptureThreshold", -118, -1);
Tunable sprQuietThreshold("SPR_QuietThreshold", -38, -1);
Tunable sprDepthCondition("SPR_DepthCondition", 2, 1);
Tunable sprCaptureThreshold("SPR_CaptureThreshold", -98, -1);
Tunable sprQuietThreshold("SPR_QuietThreshold", -34, -1);

Tunable nmpDivisor("NMP_Divisor", 157, 1);
Tunable nmpSubtractor("NMP_Subtractor", 5, 1);
Tunable nmpDepthCondition("NMP_DepthCondition", 1, 1);
Tunable nmpDivisor("NMP_Divisor", 147, 1);
Tunable nmpSubtractor("NMP_Subtractor", 4, 1);
Tunable nmpDepthCondition("NMP_DepthCondition", 0, 1);

Tunable hmrDivisor("HMR_Divisor", 8000, 1);
Tunable cmrDivisor("CMR_Divisor", 2926, 1);
Tunable hmrDivisor("HMR_Divisor", 7828, 1);
Tunable cmrDivisor("CMR_Divisor", 4506, 1);

Tunable lmrBase("LMR_Base", 0.81, 100);// Adjusted divisor for lmrBase
Tunable lmrMultiplier("LMR_Multiplier", 0.58, 100);// Adjusted divisor for lmrMultiplier
Tunable lmrBase("LMR_Base", 0.82, 100);// Adjusted divisor for lmrBase
Tunable lmrMultiplier("LMR_Multiplier", 0.53, 100);// Adjusted divisor for lmrMultiplier

Tunable hstMaxBonus("HST_MaxBonus", 1884, 1);
Tunable hstMultiplier("HST_Multiplier", 4, 1);
Tunable hstAdder("HST_Adder", 150, 1);
Tunable hstSubtractor("HST_Subtractor", 110, 1);
Tunable hstMaxBonus("HST_MaxBonus", 1642, 1);
Tunable hstMultiplier("HST_Multiplier", 3, 1);
Tunable hstAdder("HST_Adder", 146, 1);
Tunable hstSubtractor("HST_Subtractor", 120, 1);

Tunable sinDepthCondition("SIN_DepthCondition", 8, 1);
Tunable sinDepthCondition("SIN_DepthCondition", 7, 1);
Tunable sinDepthMargin("SIN_DepthMargin", 3, 1);
Tunable sinDepthScale("SIN_DepthScale", 48, 1);
Tunable sinDepthScale("SIN_DepthScale", 33, 1);

Tunable razDepthMultiplier("RAZ_DepthMultiplier", 394, 1);
Tunable razDepthMultiplier("RAZ_DepthMultiplier", 495, 1);

Tunable ntmDepthCondition("NTM_DepthCondition", 8, 1);
Tunable ntmSubtractor("NTM_Subtractor", 1.61, 100);
Tunable ntmMultiplier("NTM_Multiplier", 1.41, 100);
Tunable ntmDefault("NTM_Default", 0.83, 100);
Tunable ntmDepthCondition("NTM_DepthCondition", 10, 1);
Tunable ntmSubtractor("NTM_Subtractor", 1.69, 100);
Tunable ntmMultiplier("NTM_Multiplier", 1.32, 100);
Tunable ntmDefault("NTM_Default", 1.34, 100);

Tunable hipDepthCondition("HIP_DepthCondition", 7, 1);
Tunable hipDepthMultiplier("HIP_DepthMultiplier", -2066, -1);
Tunable hipDepthMultiplier("HIP_DepthMultiplier", -2470, -1);

Tunable qhsMaxBonus("QHS_MaxBonus", 1830, 1);
Tunable qhsMultiplier("QHS_Multiplier", 5, 1);
Tunable qhsAdder("QHS_Adder", 126, 1);
Tunable qhsSubtractor("QHS_Subtractor", 107, 1);
Tunable qhsMaxBonus("QHS_MaxBonus", 1589, 1);
Tunable qhsMultiplier("QHS_Multiplier", 6, 1);
Tunable qhsAdder("QHS_Adder", 72, 1);
Tunable qhsSubtractor("QHS_Subtractor", 105, 1);

Tunable dexMargin("DEX_Margin", 50, 1);
Tunable dexLimit("DEX_Limit", 20, 1);
Tunable dexMargin("DEX_Margin", 32, 1);
Tunable dexLimit("DEX_Limit", 24, 1);

Tunable deiDepth("DEI_Depth", 10, 1);
Tunable deiDepth("DEI_Depth", 13, 1);

Tunable lmrDepth("LMR_Depth", 1, 1);
Tunable lmrDepth("LMR_Depth", 2, 1);

Tunable mvvPawn("MVV_Pawn", 91, 1);
Tunable mvvKnight("MVV_Knight", 401, 1);
Tunable mvvBishop("MVV_Bishop", 502, 1);
Tunable mvvRook("MVV_Rook", 736, 1);
Tunable mvvQueen("MVV_Queen", 1192, 1);
Tunable blank("blank", 0, 1);

Tunable seePawn("SEE_Pawn", 108, 1);
Tunable seeKnight("SEE_Knight", 446, 1);
Tunable seeBishop("SEE_Bishop", 428, 1);
Tunable seeRook("SEE_Rook", 665, 1);
Tunable seeQueen("SEE_Queen", 1110, 1);

Tunable tmhDivisor("TMH_Divisor", 2, 1);
Tunable tmsNumerator("TMS_Numerator", 2, 1);
Tunable tmsDenominator("TMS_Denominator", 4, 1);
Tunable tmsMultiplier("TMS_Multiplier", 0.6, 10);

// Declaration of pointers to tunables
std::array<Tunable *, 7> MVV_values = {
&mvvPawn,
&mvvKnight,
&mvvBishop,
&mvvRook,
&mvvQueen,
&blank,
&blank,
};

std::array<Tunable *, 7> SEE_values = {
&seePawn,
&seeKnight,
&seeBishop,
&seeRook,
&seeQueen,
&blank,
&blank,
};

std::vector<Tunable *> tunables = {
&aspBaseDelta,
Expand Down Expand Up @@ -121,7 +158,21 @@ std::vector<Tunable *> tunables = {
&dexMargin,
&dexLimit,
&deiDepth,
&lmrDepth
&lmrDepth,
&mvvPawn,
&mvvKnight,
&mvvBishop,
&mvvRook,
&mvvQueen,
&seePawn,
&seeKnight,
&seeBishop,
&seeRook,
&seeQueen,
&tmhDivisor,
&tmsNumerator,
&tmsDenominator,
&tmsMultiplier
};


Expand Down
10 changes: 3 additions & 7 deletions src/uci.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ bool useSyzygy = false;
There are things not supported here though, such as go infinite, and quite a few options
*/

int hardBoundDivisor = 2;
int softBoundFractionNumerator = 3;
int softBoundFractionDenominator = 4;
double softBoundMultiplier = 0.6;
int defaultMovesToGo = 20;

Board board("8/8/8/8/8/8/8/8 w - - 0 1");
Expand Down Expand Up @@ -121,7 +117,7 @@ void identify() {
std::cout << "option name Hash type spin default 64 min 1 max 2048" << std::endl;
std::cout << "option name Threads type spin default 1 min 1 max 64" << std::endl;
std::cout << "option name SyzygyPath type string default <empty>" << std::endl;
//outputTunables();
outputTunables();
std::cout << "uciok" << std::endl;
}

Expand Down Expand Up @@ -201,8 +197,8 @@ void go(std::vector<std::string> bits) {
} else {
// go wtime x btime x
// the formulas here are former formulas from Stormphrax
const int softBound = softBoundMultiplier * (time / movestogo + inc * softBoundFractionNumerator / softBoundFractionDenominator);
const int hardBound = time / hardBoundDivisor;
const int softBound = tmsMultiplier.value * (time / movestogo + inc * tmsNumerator.value / tmsDenominator.value);
const int hardBound = time / tmhDivisor.value;
for(int i = 0; i < threadCount; i++) {
threads.emplace_back([i, softBound, hardBound]{
engines[i].think(board, softBound, hardBound, i == 0);
Expand Down

0 comments on commit c662fac

Please sign in to comment.