Skip to content

Commit

Permalink
ShashChess 34.3
Browse files Browse the repository at this point in the history
Fix native build on linux
Eliminated Stockfish handicap mode and replaced with
another better one, based  on an idea of and Michael Byrne
Thanks to
Tomasz Sobczyk official-stockfish/Stockfish#3635
Michael Byrne MichaelB7/Stockfish@18480ca
  • Loading branch information
amchess committed Nov 9, 2023
1 parent 6eeddcf commit 4fc5ad2
Show file tree
Hide file tree
Showing 16 changed files with 111 additions and 187 deletions.
32 changes: 24 additions & 8 deletions src/evaluate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
#include "uci.h"
#include "incbin/incbin.h"
#include "nnue/evaluate_nnue.h"
//from Rodent begin
#include <cmath>
#include <random>
//from Rodent end

// Macro to embed the default efficiently updatable neural network (NNUE) file
// data in the engine binary (using incbin.h, by Dale Weiler).
Expand Down Expand Up @@ -64,7 +68,7 @@ bool useNNUE;
//true handicap mode begin
bool limitStrength, pawnsToEvaluate, winnableToEvaluate, imbalancesToEvaluate,
handicappedAvatarPlayer, handicappedDepth;
int uciElo;
int uciElo, RandomEvalPerturb = 0;
//true handicap mode end

string currentEvalFileName = "None";
Expand All @@ -76,11 +80,11 @@ string currentEvalFileName = "None";
/// network may be embedded in the binary), in the active working directory and
/// in the engine directory. Distro packagers may define the DEFAULT_NNUE_DIRECTORY
/// variable to have the engine search in a special directory in their distro.

void NNUE::init() {
limitStrength = Options["UCI_LimitStrength"] || Options["LimitStrength_CB"];
useNNUE = Options["Use NNUE"] && (!limitStrength); //true handicap mode
uciElo = limitStrength ? Options["UCI_Elo"] : Options["ELO_CB"];
limitStrength = Options["UCI_LimitStrength"] || Options["LimitStrength_CB"];
useNNUE = Options["Use NNUE"] && (!limitStrength); //true handicap mode
uciElo = limitStrength ? std::min((int) (Options["UCI_Elo"]), (int) (Options["ELO_CB"]))
: (int) (3190);
pawnsToEvaluate = limitStrength ? (uciElo >= 2000) : 1;
winnableToEvaluate = limitStrength ? (uciElo >= 2200) : 1;
imbalancesToEvaluate = limitStrength ? (uciElo >= 2400) : 1;
Expand Down Expand Up @@ -1144,10 +1148,12 @@ Value Evaluation<T>::value() {
Value Eval::evaluate(const Position& pos) {

assert(!pos.checkers());
//from Rodent handicap mode begin
static thread_local std::mt19937_64 tls_rng = []() { return std::mt19937_64(std::time(0)); }();
//from Rodent handicap mode end

Value v;
Value psq = pos.psq_eg_stm();

// We use the much less accurate but faster Classical eval when the NNUE
// option is set to false. Otherwise we use the NNUE eval unless the
// PSQ advantage is decisive. (~4 Elo at STC, 1 Elo at LTC)
Expand All @@ -1172,7 +1178,16 @@ Value Eval::evaluate(const Position& pos) {

// Damp down the evaluation linearly when shuffling
v = v * (200 - pos.rule50_count()) / 214;

//from handicap mode Michael Byrne begin
if (limitStrength && handicappedAvatarPlayer)
{
RandomEvalPerturb = (-10 * uciElo + 31900) / 319;
std::normal_distribution<float> d(0.0, RandomValue);
float r = d(tls_rng);
r = std::clamp<float>(r, VALUE_TB_LOSS_IN_MAX_PLY + 1, VALUE_TB_WIN_IN_MAX_PLY - 1);
v = (RandomEvalPerturb * Value(r) + (100 - RandomEvalPerturb) * v) / 100;
}
//from handicap mode Michael Byrne end
// Guarantee evaluation does not hit the tablebase range
v = std::clamp(v, VALUE_TB_LOSS_IN_MAX_PLY + 1, VALUE_TB_WIN_IN_MAX_PLY - 1);

Expand Down Expand Up @@ -1290,7 +1305,8 @@ void loadAvatar(const std::string& fname) {
}

file.close();
if(!fname.empty()){
if (!fname.empty())
{
sync_cout << "info string Avatar file " << fname << " loaded successfully" << sync_endl;
}
//Assign to Weights array
Expand Down
4 changes: 2 additions & 2 deletions src/evaluate.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ Value evaluate(const Position& pos);
extern bool useNNUE;
//true handicap mode begin
extern bool limitStrength, pawnsToEvaluate, winnableToEvaluate, imbalancesToEvaluate,
handicappedAvatarPlayer,handicappedDepth;
extern int uciElo;
handicappedAvatarPlayer, handicappedDepth;
extern int uciElo, RandomEvalPerturb;
//true handicap mode end
extern std::string currentEvalFileName;
void loadAvatar(const std::string& fname); //avatar
Expand Down
2 changes: 1 addition & 1 deletion src/makeAVX2.bat
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ Title "x86-64-avx2"
make clean
mingw32-make profile-build ARCH=x86-64-avx2 COMP=mingw CXX=x86_64-w64-mingw32-g++ -j %Number_Of_Processors%
strip shashchess.exe
ren shashchess.exe "ShashChess34.2-x86-64-avx2.exe"
ren shashchess.exe "ShashChess34.3-x86-64-avx2.exe"
make clean
pause
26 changes: 13 additions & 13 deletions src/makeAll.sh
Original file line number Diff line number Diff line change
@@ -1,65 +1,65 @@
make profile-build ARCH=x86-64-vnni COMP=gcc
strip shashchess
mv 'shashchess' 'ShashChess34.2-x86-64-vnni'
mv 'shashchess' 'ShashChess34.3-x86-64-vnni'
make clean

make profile-build ARCH=x86-64-avx512 COMP=gcc
strip shashchess
mv 'shashchess' 'ShashChess34.2-x86-64-avx512'
mv 'shashchess' 'ShashChess34.3-x86-64-avx512'
make clean

make profile-build ARCH=x86-64-bmi2 COMP=gcc
strip shashchess
mv 'shashchess' 'ShashChess34.2-x86-64-bmi2'
mv 'shashchess' 'ShashChess34.3-x86-64-bmi2'
make clean

make profile-build ARCH=x86-64-avx2 COMP=gcc
strip shashchess
mv 'shashchess' 'ShashChess34.2-x86-64-avx2'
mv 'shashchess' 'ShashChess34.3-x86-64-avx2'
make clean

make profile-build ARCH=x86-64-modern COMP=gcc
strip shashchess
mv 'shashchess' 'ShashChess34.2-x86-64-modern'
mv 'shashchess' 'ShashChess34.3-x86-64-modern'
make clean

make profile-build ARCH=x86-64-sse41-popcnt COMP=gcc
strip shashchess
mv 'shashchess' 'ShashChess34.2-x86-64-sse41-popcnt'
mv 'shashchess' 'ShashChess34.3-x86-64-sse41-popcnt'
make clean

make profile-build ARCH=x86-64-ssse3 COMP=gcc
strip shashchess
mv 'shashchess' 'ShashChess34.2-x86-64-ssse3'
mv 'shashchess' 'ShashChess34.3-x86-64-ssse3'
make clean

make profile-build ARCH=x86-64-sse3-popcnt COMP=gcc
strip shashchess
mv 'shashchess' 'ShashChess34.2-x86-64-sse3-popcnt'
mv 'shashchess' 'ShashChess34.3-x86-64-sse3-popcnt'
make clean

make profile-build ARCH=x86-64 COMP=gcc
strip shashchess
mv 'shashchess' 'ShashChess34.2-x86-64'
mv 'shashchess' 'ShashChess34.3-x86-64'
make clean

make profile-build ARCH=general-64 COMP=gcc
strip shashchess
mv 'shashchess' 'ShashChess34.2-general-64'
mv 'shashchess' 'ShashChess34.3-general-64'
make clean

make profile-build ARCH=x86-32 COMPCC=gcc
strip shashchess
mv 'shashchess' 'ShashChess34.2-x86-32'
mv 'shashchess' 'ShashChess34.3-x86-32'
make clean

make profile-build ARCH=x86-32-old COMPCC=gcc
strip shashchess
mv 'shashchess' 'ShashChess34.2-x86-32-old'
mv 'shashchess' 'ShashChess34.3-x86-32-old'
make clean

make profile-build ARCH=general-32 COMPCC=gcc
strip shashchess
mv 'shashchess' 'ShashChess34.2-general-32'
mv 'shashchess' 'ShashChess34.3-general-32'
make clean

6 changes: 3 additions & 3 deletions src/makeAll32.bat
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ Title "x86-32"
make clean
mingw32-make -f MakeFile profile-build ARCH=x86-32 COMP=mingw
strip shashchess.exe
ren shashchess.exe "ShashChess34.2-x86-32.exe"
ren shashchess.exe "ShashChess34.3-x86-32.exe"

Title "x86-32-old"
make clean
mingw32-make -f MakeFile profile-build ARCH=x86-32-old COMP=mingw
strip shashchess.exe
ren shashchess.exe "ShashChess34.2-x86-32-old.exe"
ren shashchess.exe "ShashChess34.3-x86-32-old.exe"

Title "general-32"
make clean
mingw32-make -f MakeFile profile-build ARCH=general-32 COMP=mingw
strip shashchess.exe
ren shashchess.exe "ShashChess34.2-general-32.exe"
ren shashchess.exe "ShashChess34.3-general-32.exe"

make clean
REM x32 builds end
Expand Down
20 changes: 10 additions & 10 deletions src/makeAll64.bat
Original file line number Diff line number Diff line change
Expand Up @@ -6,61 +6,61 @@ Title "x86-64-vnni"
make clean
mingw32-make profile-build ARCH=x86-64-vnni COMP=mingw CXX=x86_64-w64-mingw32-g++ -j %Number_Of_Processors%
strip shashchess.exe
ren shashchess.exe "ShashChess34.2-x86-64-vnni.exe"
ren shashchess.exe "ShashChess34.3-x86-64-vnni.exe"

Title "x86-64-avx512"
make clean
mingw32-make profile-build ARCH=x86-64-avx512 COMP=mingw CXX=x86_64-w64-mingw32-g++ -j %Number_Of_Processors%
strip shashchess.exe
ren shashchess.exe "ShashChess34.2-x86-64-avx512.exe"
ren shashchess.exe "ShashChess34.3-x86-64-avx512.exe"

Title "x86-64-bmi2"
make clean
mingw32-make profile-build ARCH=x86-64-bmi2 COMP=mingw CXX=x86_64-w64-mingw32-g++ -j %Number_Of_Processors%
strip shashchess.exe
ren shashchess.exe "ShashChess34.2-x86-64-bmi2.exe"
ren shashchess.exe "ShashChess34.3-x86-64-bmi2.exe"

Title "x86-64-avx2"
make clean
mingw32-make profile-build ARCH=x86-64-avx2 COMP=mingw CXX=x86_64-w64-mingw32-g++ -j %Number_Of_Processors%
strip shashchess.exe
ren shashchess.exe "ShashChess34.2-x86-64-avx2.exe"
ren shashchess.exe "ShashChess34.3-x86-64-avx2.exe"

Title "x86-64-modern"
make clean
mingw32-make profile-build ARCH=x86-64-modern COMP=mingw CXX=x86_64-w64-mingw32-g++ -j %Number_Of_Processors%
strip shashchess.exe
ren shashchess.exe "ShashChess34.2-x86-64-modern.exe"
ren shashchess.exe "ShashChess34.3-x86-64-modern.exe"

Title "x86-64-sse41-popcnt"
make clean
mingw32-make profile-build ARCH=x86-64-sse41-popcnt COMP=mingw CXX=x86_64-w64-mingw32-g++ -j %Number_Of_Processors%
strip shashchess.exe
ren shashchess.exe "ShashChess34.2-x86-64-sse41-popcnt.exe"
ren shashchess.exe "ShashChess34.3-x86-64-sse41-popcnt.exe"

Title "x86-64-ssse3"
make clean
mingw32-make profile-build ARCH=x86-64-ssse3 COMP=mingw CXX=x86_64-w64-mingw32-g++ -j %Number_Of_Processors%
strip shashchess.exe
ren shashchess.exe "ShashChess34.2-x86-64-ssse3.exe"
ren shashchess.exe "ShashChess34.3-x86-64-ssse3.exe"

Title "x86-64-sse3-popcnt"
make clean
mingw32-make profile-build ARCH=x86-64-sse3-popcnt COMP=mingw CXX=x86_64-w64-mingw32-g++ -j %Number_Of_Processors%
strip shashchess.exe
ren shashchess.exe "ShashChess34.2-x86-64-sse3-popcnt.exe"
ren shashchess.exe "ShashChess34.3-x86-64-sse3-popcnt.exe"

Title "x86-64"
make clean
mingw32-make profile-build ARCH=x86-64 COMP=mingw CXX=x86_64-w64-mingw32-g++ -j %Number_Of_Processors%
strip shashchess.exe
ren shashchess.exe "ShashChess34.2-x86-64.exe"
ren shashchess.exe "ShashChess34.3-x86-64.exe"

Title "general-64"
make clean
mingw32-make profile-build ARCH=general-64 COMP=mingw CXX=x86_64-w64-mingw32-g++ -j %Number_Of_Processors%
strip shashchess.exe
ren shashchess.exe "ShashChess34.2-general-64.exe"
ren shashchess.exe "ShashChess34.3-general-64.exe"
make clean
REM x64 builds end
pause
Expand Down
2 changes: 1 addition & 1 deletion src/makeBMI2.bat
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ Title "x86-64-bmi2"
make clean
mingw32-make profile-build ARCH=x86-64-bmi2 COMP=mingw CXX=x86_64-w64-mingw32-g++ -j %Number_Of_Processors%
strip shashchess.exe
ren shashchess.exe "ShashChess34.2-x86-64-bmi2.exe"
ren shashchess.exe "ShashChess34.3-x86-64-bmi2.exe"
make clean
pause
2 changes: 1 addition & 1 deletion src/makeModern.bat
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ Title "x86-64-modern"
make clean
mingw32-make profile-build ARCH=x86-64-modern COMP=mingw CXX=x86_64-w64-mingw32-g++ -j %Number_Of_Processors%
strip shashchess.exe
ren shashchess.exe "ShashChess34.2-x86-64-modern.exe"
ren shashchess.exe "ShashChess34.3-x86-64-modern.exe"
make clean
pause
9 changes: 4 additions & 5 deletions src/mcts/montecarlo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,13 @@ void MonteCarlo::search() {
else
reward = playout_policy(node);

if(Utility::is_game_decided(pos, backup(reward, AB_Rollout)))
if (Utility::is_game_decided(pos, backup(reward, AB_Rollout)))
{
pos.this_thread()->isMCTS = false;
break;
}
}
//if (should_output_result())
//emit_principal_variation();
//emit_principal_variation();
}
}

Expand Down Expand Up @@ -237,7 +237,7 @@ bool MonteCarlo::computational_budget() {
assert(is_root(current_node()));
Threads.main()->check_time();
//if (pos.this_thread() == Threads.main())
//dynamic_cast<MainThread*>(pos.this_thread())->check_time();
//dynamic_cast<MainThread*>(pos.this_thread())->check_time();

return descentCnt < MAX_DESCENTS && !is_interrupted();
}
Expand Down Expand Up @@ -407,7 +407,6 @@ Value MonteCarlo::backup(Reward r, bool AB_Mode) {

assert(is_root(current_node()));
return reward_to_value(r);

}


Expand Down
2 changes: 1 addition & 1 deletion src/mcts/montecarlo.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ class MonteCarlo {
bool computational_budget();
mctsNodeInfo* tree_policy();
Reward playout_policy(mctsNodeInfo* node);
Value backup(Reward r, bool AB_Mode);
Value backup(Reward r, bool AB_Mode);
Edge* best_child(mctsNodeInfo* node, EdgeStatistic statistic);

// The UCB formula
Expand Down
2 changes: 1 addition & 1 deletion src/misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ namespace Stockfish {
namespace {

/// Version number or dev.
constexpr string_view version = "34.2";
constexpr string_view version = "34.3";

/// Our fancy logging facility. The trick here is to replace cin.rdbuf() and
/// cout.rdbuf() with two Tie objects that tie cin and cout to a file stream. We
Expand Down
2 changes: 1 addition & 1 deletion src/native.bat
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ REM x64 builds begin
SET PATH=C:\msys64\mingw64\bin;C:\msys64\usr\bin;%PATH%
REM make -j profile-build
mingw32-make profile-build ARCH=native COMP=mingw -j %Number_Of_Processors%
ren shashchess.exe ShashChess34.2-native.exe
ren shashchess.exe ShashChess34.3-native.exe
make clean
pause
7 changes: 2 additions & 5 deletions src/native.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
@echo off
REM make -j profile-build
make profile-build ARCH=native COMP=gcc
ren shashchess.exe ShashChess34.2-native.exe
make clean
pause
mv shashchess.exe ShashChess34.3-native.exe
make clean
Loading

0 comments on commit 4fc5ad2

Please sign in to comment.