Skip to content

Commit c662fac

Browse files
authored
Tune! (#79) bench: 9986537
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
1 parent a0af318 commit c662fac

File tree

4 files changed

+121
-57
lines changed

4 files changed

+121
-57
lines changed

src/globals.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,26 @@ extern Tunable deiDepth;
257257

258258
extern Tunable lmrDepth;
259259

260+
extern Tunable mvvPawn;
261+
extern Tunable mvvKnight;
262+
extern Tunable mvvBishop;
263+
extern Tunable mvvRook;
264+
extern Tunable mvvQueen;
265+
extern Tunable blank;
266+
267+
extern Tunable seePawn;
268+
extern Tunable seeKnight;
269+
extern Tunable seeBishop;
270+
extern Tunable seeRook;
271+
extern Tunable seeQueen;
272+
273+
extern Tunable tmhDivisor;
274+
extern Tunable tmsNumerator;
275+
extern Tunable tmsDenominator;
276+
extern Tunable tmsMultiplier;
277+
278+
extern std::array<Tunable *, 7> MVV_values;
279+
extern std::array<Tunable *, 7> SEE_values;
260280
extern std::vector<Tunable *> tunables;
261281

262282
void outputTunables();

src/search.cpp

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ int hardNodeCap = 400000;
2929

3030
constexpr int historyCap = 16384;
3131

32-
int MVV_value[7] = {112, 351, 361, 627, 1187, 0, 0};
33-
int SEE_value[7] = {112, 351, 361, 627, 1187, 0, 0};
34-
3532
// Tunable Values
3633
int killerScore = 70000;
3734
int counterScore = 71000;
@@ -61,18 +58,18 @@ void Engine::resetEngine() {
6158

6259
int Engine::estimateMoveValue(const Board& board, const int end, const int flag) {
6360
// starting with the end square piece
64-
int value = SEE_value[getType(board.pieceAtIndex(end))];
61+
int value = SEE_values[getType(board.pieceAtIndex(end))]->value;
6562
// promotions! pawn--, newpiece++
6663
for(int i = 0; i < 4; i++) {
6764
if(flag == promotions[i]) {
68-
value = SEE_value[i + 1] - SEE_value[Pawn];
65+
value = SEE_values[i + 1]->value - SEE_values[Pawn]->value;
6966
return value;
7067
}
7168
}
7269

7370
// Target square is empty for en passant, but you still capture a pawn
7471
if(flag == EnPassant) {
75-
value = SEE_value[Pawn];
72+
value = SEE_values[Pawn]->value;
7673
}
7774
// castling can't capture and is never encoded as such so we don't care.
7875
return value;
@@ -99,7 +96,7 @@ bool Engine::see(const Board& board, Move move, int threshold) {
9996
// best case still doesn't beat threshold, not good
10097
if(balance < 0) return false;
10198
// worst case, we lose the piece here
102-
balance -= SEE_value[nextVictim];
99+
balance -= SEE_values[nextVictim]->value;
103100
// if it's still winning in the best case scenario, we can just cut it off
104101
if(balance >= 0) return true;
105102
// make sure occupied bitboard knows we did the first move
@@ -136,7 +133,7 @@ bool Engine::see(const Board& board, Move move, int threshold) {
136133
attackers &= occupied;
137134
color = 1 - color;
138135
// update balance
139-
balance = -balance - 1 - SEE_value[nextVictim];
136+
balance = -balance - 1 - SEE_values[nextVictim]->value;
140137
// if you are ahead
141138
if(balance >= 0) {
142139
// speedrunning legality check
@@ -171,7 +168,7 @@ void Engine::scoreMoves(const Board& board, std::array<Move, 256> &moves, std::a
171168
// Captures!
172169
const int victim = getType(board.pieceAtIndex(end));
173170
// Capthist!
174-
values[i] = MVV_value[victim] + noisyHistoryTable[colorToMove][piece][end][victim];
171+
values[i] = MVV_values[victim]->value + noisyHistoryTable[colorToMove][piece][end][victim];
175172
// see!
176173
// 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.
177174
if(see(board, move, 0)) {
@@ -208,7 +205,7 @@ void Engine::scoreMovesQS(const Board& board, std::array<Move, 256> &moves, std:
208205
// Captures!
209206
const int victim = getType(board.pieceAtIndex(end));
210207
// Capthist!
211-
values[i] = MVV_value[victim] + qsHistoryTable[colorToMove][piece][end][victim];
208+
values[i] = MVV_values[victim]->value + qsHistoryTable[colorToMove][piece][end][victim];
212209
// see!
213210
// 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.
214211
if(see(board, move, 0)) {
@@ -281,7 +278,7 @@ int Engine::qSearch(Board &board, int alpha, int beta, int ply) {
281278
Move move = moves[i];
282279

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

src/tunables.cpp

Lines changed: 90 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -17,67 +17,104 @@
1717
*/
1818
#include "globals.h"
1919

20-
Tunable aspBaseDelta("ASP_BaseDelta", 17, 1);
21-
Tunable aspDeltaMultiplier("ASP_DeltaMultiplier", 1.67, 10);
20+
Tunable aspBaseDelta("ASP_BaseDelta", 14, 1);
21+
Tunable aspDeltaMultiplier("ASP_DeltaMultiplier", 1.34, 10);
2222
Tunable aspDepthCondition("ASP_DepthCondition", 4, 1);
2323

24-
Tunable rfpDepthCondition("RFP_DepthCondition", 11, 1);
25-
Tunable rfpMultiplier("RFP_Multiplier", 96, 1);
24+
Tunable rfpDepthCondition("RFP_DepthCondition", 10, 1);
25+
Tunable rfpMultiplier("RFP_Multiplier", 92, 1);
2626

27-
Tunable iirDepthCondition("IIR_DepthCondition", 4, 1);
27+
Tunable iirDepthCondition("IIR_DepthCondition", 2, 1);
2828

2929
Tunable fpDepthCondition("FP_DepthCondition", 1, 1);
30-
Tunable fpBase("FP_Base", 268, 1);
31-
Tunable fpMultiplier("FP_Multiplier", 64, 1);
30+
Tunable fpBase("FP_Base", 327, 1);
31+
Tunable fpMultiplier("FP_Multiplier", 44, 1);
3232

33-
Tunable lmpBase("LMP_Base", 2, 1);// No divisor adjustment
33+
Tunable lmpBase("LMP_Base", 1, 1);// No divisor adjustment
3434

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

39-
Tunable nmpDivisor("NMP_Divisor", 157, 1);
40-
Tunable nmpSubtractor("NMP_Subtractor", 5, 1);
41-
Tunable nmpDepthCondition("NMP_DepthCondition", 1, 1);
39+
Tunable nmpDivisor("NMP_Divisor", 147, 1);
40+
Tunable nmpSubtractor("NMP_Subtractor", 4, 1);
41+
Tunable nmpDepthCondition("NMP_DepthCondition", 0, 1);
4242

43-
Tunable hmrDivisor("HMR_Divisor", 8000, 1);
44-
Tunable cmrDivisor("CMR_Divisor", 2926, 1);
43+
Tunable hmrDivisor("HMR_Divisor", 7828, 1);
44+
Tunable cmrDivisor("CMR_Divisor", 4506, 1);
4545

46-
Tunable lmrBase("LMR_Base", 0.81, 100);// Adjusted divisor for lmrBase
47-
Tunable lmrMultiplier("LMR_Multiplier", 0.58, 100);// Adjusted divisor for lmrMultiplier
46+
Tunable lmrBase("LMR_Base", 0.82, 100);// Adjusted divisor for lmrBase
47+
Tunable lmrMultiplier("LMR_Multiplier", 0.53, 100);// Adjusted divisor for lmrMultiplier
4848

49-
Tunable hstMaxBonus("HST_MaxBonus", 1884, 1);
50-
Tunable hstMultiplier("HST_Multiplier", 4, 1);
51-
Tunable hstAdder("HST_Adder", 150, 1);
52-
Tunable hstSubtractor("HST_Subtractor", 110, 1);
49+
Tunable hstMaxBonus("HST_MaxBonus", 1642, 1);
50+
Tunable hstMultiplier("HST_Multiplier", 3, 1);
51+
Tunable hstAdder("HST_Adder", 146, 1);
52+
Tunable hstSubtractor("HST_Subtractor", 120, 1);
5353

54-
Tunable sinDepthCondition("SIN_DepthCondition", 8, 1);
54+
Tunable sinDepthCondition("SIN_DepthCondition", 7, 1);
5555
Tunable sinDepthMargin("SIN_DepthMargin", 3, 1);
56-
Tunable sinDepthScale("SIN_DepthScale", 48, 1);
56+
Tunable sinDepthScale("SIN_DepthScale", 33, 1);
5757

58-
Tunable razDepthMultiplier("RAZ_DepthMultiplier", 394, 1);
58+
Tunable razDepthMultiplier("RAZ_DepthMultiplier", 495, 1);
5959

60-
Tunable ntmDepthCondition("NTM_DepthCondition", 8, 1);
61-
Tunable ntmSubtractor("NTM_Subtractor", 1.61, 100);
62-
Tunable ntmMultiplier("NTM_Multiplier", 1.41, 100);
63-
Tunable ntmDefault("NTM_Default", 0.83, 100);
60+
Tunable ntmDepthCondition("NTM_DepthCondition", 10, 1);
61+
Tunable ntmSubtractor("NTM_Subtractor", 1.69, 100);
62+
Tunable ntmMultiplier("NTM_Multiplier", 1.32, 100);
63+
Tunable ntmDefault("NTM_Default", 1.34, 100);
6464

6565
Tunable hipDepthCondition("HIP_DepthCondition", 7, 1);
66-
Tunable hipDepthMultiplier("HIP_DepthMultiplier", -2066, -1);
66+
Tunable hipDepthMultiplier("HIP_DepthMultiplier", -2470, -1);
6767

68-
Tunable qhsMaxBonus("QHS_MaxBonus", 1830, 1);
69-
Tunable qhsMultiplier("QHS_Multiplier", 5, 1);
70-
Tunable qhsAdder("QHS_Adder", 126, 1);
71-
Tunable qhsSubtractor("QHS_Subtractor", 107, 1);
68+
Tunable qhsMaxBonus("QHS_MaxBonus", 1589, 1);
69+
Tunable qhsMultiplier("QHS_Multiplier", 6, 1);
70+
Tunable qhsAdder("QHS_Adder", 72, 1);
71+
Tunable qhsSubtractor("QHS_Subtractor", 105, 1);
7272

73-
Tunable dexMargin("DEX_Margin", 50, 1);
74-
Tunable dexLimit("DEX_Limit", 20, 1);
73+
Tunable dexMargin("DEX_Margin", 32, 1);
74+
Tunable dexLimit("DEX_Limit", 24, 1);
7575

76-
Tunable deiDepth("DEI_Depth", 10, 1);
76+
Tunable deiDepth("DEI_Depth", 13, 1);
7777

78-
Tunable lmrDepth("LMR_Depth", 1, 1);
78+
Tunable lmrDepth("LMR_Depth", 2, 1);
79+
80+
Tunable mvvPawn("MVV_Pawn", 91, 1);
81+
Tunable mvvKnight("MVV_Knight", 401, 1);
82+
Tunable mvvBishop("MVV_Bishop", 502, 1);
83+
Tunable mvvRook("MVV_Rook", 736, 1);
84+
Tunable mvvQueen("MVV_Queen", 1192, 1);
85+
Tunable blank("blank", 0, 1);
86+
87+
Tunable seePawn("SEE_Pawn", 108, 1);
88+
Tunable seeKnight("SEE_Knight", 446, 1);
89+
Tunable seeBishop("SEE_Bishop", 428, 1);
90+
Tunable seeRook("SEE_Rook", 665, 1);
91+
Tunable seeQueen("SEE_Queen", 1110, 1);
92+
93+
Tunable tmhDivisor("TMH_Divisor", 2, 1);
94+
Tunable tmsNumerator("TMS_Numerator", 2, 1);
95+
Tunable tmsDenominator("TMS_Denominator", 4, 1);
96+
Tunable tmsMultiplier("TMS_Multiplier", 0.6, 10);
7997

8098
// Declaration of pointers to tunables
99+
std::array<Tunable *, 7> MVV_values = {
100+
&mvvPawn,
101+
&mvvKnight,
102+
&mvvBishop,
103+
&mvvRook,
104+
&mvvQueen,
105+
&blank,
106+
&blank,
107+
};
108+
109+
std::array<Tunable *, 7> SEE_values = {
110+
&seePawn,
111+
&seeKnight,
112+
&seeBishop,
113+
&seeRook,
114+
&seeQueen,
115+
&blank,
116+
&blank,
117+
};
81118

82119
std::vector<Tunable *> tunables = {
83120
&aspBaseDelta,
@@ -121,7 +158,21 @@ std::vector<Tunable *> tunables = {
121158
&dexMargin,
122159
&dexLimit,
123160
&deiDepth,
124-
&lmrDepth
161+
&lmrDepth,
162+
&mvvPawn,
163+
&mvvKnight,
164+
&mvvBishop,
165+
&mvvRook,
166+
&mvvQueen,
167+
&seePawn,
168+
&seeKnight,
169+
&seeBishop,
170+
&seeRook,
171+
&seeQueen,
172+
&tmhDivisor,
173+
&tmsNumerator,
174+
&tmsDenominator,
175+
&tmsMultiplier
125176
};
126177

127178

src/uci.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ bool useSyzygy = false;
2929
There are things not supported here though, such as go infinite, and quite a few options
3030
*/
3131

32-
int hardBoundDivisor = 2;
33-
int softBoundFractionNumerator = 3;
34-
int softBoundFractionDenominator = 4;
35-
double softBoundMultiplier = 0.6;
3632
int defaultMovesToGo = 20;
3733

3834
Board board("8/8/8/8/8/8/8/8 w - - 0 1");
@@ -121,7 +117,7 @@ void identify() {
121117
std::cout << "option name Hash type spin default 64 min 1 max 2048" << std::endl;
122118
std::cout << "option name Threads type spin default 1 min 1 max 64" << std::endl;
123119
std::cout << "option name SyzygyPath type string default <empty>" << std::endl;
124-
//outputTunables();
120+
outputTunables();
125121
std::cout << "uciok" << std::endl;
126122
}
127123

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

0 commit comments

Comments
 (0)