Skip to content

Commit

Permalink
fun with fawn
Browse files Browse the repository at this point in the history
  • Loading branch information
tryingsomestuff committed Apr 30, 2020
1 parent b5ad433 commit 5327ad4
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 24 deletions.
2 changes: 1 addition & 1 deletion Source/definition.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ typedef uint64_t u_int64_t;
#include <unistd.h>
#endif

const std::string MinicVersion = "2.15";
const std::string MinicVersion = "2.16";

// *** options
#define WITH_UCI
Expand Down
5 changes: 5 additions & 0 deletions Source/eval.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,11 @@ inline ScoreType eval(const Position & p, EvalData & data, Searcher &context){
pe.danger[Co_Black] += EvalConfig::kingAttOpenfile * countBit(kingFlank[bkf] & pe.openFiles )/8;
pe.danger[Co_Black] += EvalConfig::kingAttSemiOpenfileOpp * countBit(kingFlank[bkf] & pe.semiOpenFiles[Co_Black])/8;
pe.danger[Co_Black] += EvalConfig::kingAttSemiOpenfileOur * countBit(kingFlank[bkf] & pe.semiOpenFiles[Co_White])/8;
// Fawn
pe.score -= EvalConfig::pawnFawnMalusKS * countBit((pawns[Co_White] & (BBSq_h2 | BBSq_g3)) | (pawns[Co_Black] & BBSq_h3) | (p.king[Co_White] & kingSide))/4;
pe.score += EvalConfig::pawnFawnMalusKS * countBit((pawns[Co_Black] & (BBSq_h7 | BBSq_g6)) | (pawns[Co_White] & BBSq_h6) | (p.king[Co_Black] & kingSide))/4;
pe.score -= EvalConfig::pawnFawnMalusQS * countBit((pawns[Co_White] & (BBSq_a2 | BBSq_b3)) | (pawns[Co_Black] & BBSq_a3) | (p.king[Co_White] & queenSide))/4;
pe.score += EvalConfig::pawnFawnMalusQS * countBit((pawns[Co_Black] & (BBSq_a7 | BBSq_b6)) | (pawns[Co_White] & BBSq_a6) | (p.king[Co_Black] & queenSide))/4;

++context.stats.counters[Stats::sid_ttPawnInsert];
pe.h = Hash64to32(computePHash(p)); // set the pawn entry
Expand Down
24 changes: 13 additions & 11 deletions Source/evalConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ CONST_TEXEL_TUNING EvalScore imbalance_theirs[5][5] = {

CONST_TEXEL_TUNING EvalScore PST[6][64] = {
{
{ 0, 0},{ 0, 0},{ 0, 0},{ 0, 0},{ 0, 0},{ 0, 0},{ 0, 0},{ 0, 0},
{ 98, 83},{ 133, 71},{ 60, 78},{ 95, 53},{ 68, 91},{ 126, 65},{ 34, 129},{ -11, 135},
{ -4, 68},{ 7, 45},{ 23, 24},{ 28, -6},{ 65, -32},{ 56, 10},{ 25, 35},{ -20, 44},
{ 8, 52},{ 11, 34},{ 6, 22},{ 22, -2},{ 19, 13},{ 20, 25},{ 16, 30},{ 2, 39},
{ -6, 32},{ -13, 30},{ 5, 5},{ 24, -10},{ 27, -6},{ 32, -7},{ 6, 11},{ -1, 9},
{ -2, 20},{ -21, 25},{ 9, 4},{ 4, 5},{ 15, 6},{ 31, -1},{ 33, -2},{ 15, -4},
{ -15, 28},{ -12, 20},{ -3, 18},{ -4, 10},{ -2, 17},{ 42, -1},{ 40, -3},{ 2, -11},
{ 0, 0},{ 0, 0},{ 0, 0},{ 0, 0},{ 0, 0},{ 0, 0},{ 0, 0},{ 0, 0},
{ 0, 0},{ 0, 0},{ 0, 0},{ 0, 0},{ 0, 0},{ 0, 0},{ 0, 0},{ 0, 0},
{ 98, 88},{ 133, 73},{ 60, 78},{ 95, 53},{ 68, 91},{ 126, 65},{ 34, 129},{ -11, 137},
{ -4, 73},{ 7, 44},{ 23, 21},{ 28, -7},{ 65, -30},{ 56, 9},{ 25, 41},{ -20, 45},
{ 10, 51},{ 13, 33},{ 7, 23},{ 21, 0},{ 17, 11},{ 20, 25},{ 17, 30},{ -3, 38},
{ -8, 31},{ -13, 29},{ 8, 6},{ 25, -12},{ 28, -6},{ 30, -6},{ 8, 9},{ -1, 8},
{ 1, 19},{ -17, 24},{ 9, 5},{ 5, 6},{ 17, 6},{ 29, 2},{ 41, -5},{ 15, -5},
{ -16, 27},{ -7, 18},{ -2, 19},{ -4, 7},{ 0, 17},{ 42, 2},{ 44, -4},{ 4, -13},
{ 0, 0},{ 0, 0},{ 0, 0},{ 0, 0},{ 0, 0},{ 0, 0},{ 0, 0},{ 0, 0},
},
{
{-167, -58},{ -89, -38},{ -34, -13},{ -49, -28},{ 61, -31},{ -97, -27},{ -15, -63},{-107, -99},
Expand Down Expand Up @@ -86,16 +86,18 @@ CONST_TEXEL_TUNING EvalScore PST[6][64] = {
///@todo make more things depend on rank/file ???

CONST_TEXEL_TUNING EvalScore pawnShieldBonus = {5, -2};
CONST_TEXEL_TUNING EvalScore pawnFawnMalusKS = {15, -5};
CONST_TEXEL_TUNING EvalScore pawnFawnMalusQS = {-5, 0};
// this depends on rank
CONST_TEXEL_TUNING EvalScore passerBonus[8] = { { 0, 0 }, {16, -33} , { 2, -9}, {-6, 20}, {7, 40}, {31, 40}, {51, 61}, {0, 0}};

CONST_TEXEL_TUNING EvalScore rookBehindPassed = {-10,53};
CONST_TEXEL_TUNING EvalScore kingNearPassedPawn = { -9,16};

// this depends on rank (shall try file also ??)
CONST_TEXEL_TUNING EvalScore doublePawnMalus[8][2] = { {{ 0, 0},{ 0, 0}}, {{ 0, 0},{ 0, 0}}, {{ 31, 16},{ 7, 37}}, {{ 19, 24},{-14, 33}}, {{ 27, 15},{ 3, 24}}, {{ -6, -3},{ -3, 26}}, {{ 23, 13},{ 22, 16}}, {{ 0, 0},{ 0, 0}} }; // close semiopenfile
CONST_TEXEL_TUNING EvalScore isolatedPawnMalus[8][2] = { {{ 0, 0},{ 0, 0}}, {{ -8, 7},{ 10, 5}}, {{ 13, 4},{ 21, 15}}, {{ -4, 8},{ 14, 16}}, {{ 8, 20},{ 4, 22}}, {{ 6, 16},{-34, 12}}, {{ 9, 7},{ 10, 17}}, {{ 0, 0},{ 0, 0}} }; // close semiopenfile
CONST_TEXEL_TUNING EvalScore backwardPawnMalus[8][2] = { {{ 0, 0},{ 0, 0}}, {{ 4, -7},{ 22, 9}}, {{ 10, 0},{ 30, 1}}, {{ 15, 6},{ 27, 1}}, {{ -8, 6},{ 11, -2}}, {{ 0, 0},{ 0, 0}}, {{ 0, 0},{ 0, 0}}, {{ 0, 0},{ 0, 0}} }; // close semiopenfile
CONST_TEXEL_TUNING EvalScore doublePawnMalus[8][2] = { {{ 0, 0},{ 0, 0}}, {{ 0, 0},{ 0, 0}}, {{ 34, 12},{ 7, 40}}, {{ 24, 24},{-11, 35}}, {{ 23, 12},{ 5, 20}}, {{ -8, -1},{ -4, 26}}, {{ 23, 13},{ 22, 18}}, {{ 0, 0},{ 0, 0}} }; // close semiopenfile
CONST_TEXEL_TUNING EvalScore isolatedPawnMalus[8][2] = { {{ 0, 0},{ 0, 0}}, {{ -9, 8},{ 4, 4}}, {{ 12, 6},{ 16, 11}}, {{ -8, 11},{ 8, 14}}, {{ 3, 23},{ -3, 18}}, {{ 6, 18},{-36, 14}}, {{ 9, 7},{ 10, 18}}, {{ 0, 0},{ 0, 0}} }; // close semiopenfile
CONST_TEXEL_TUNING EvalScore backwardPawnMalus[8][2] = { {{ 0, 0},{ 0, 0}}, {{ 2, -7},{ 24, 6}}, {{ 9, 1},{ 28, 5}}, {{ 17, 5},{ 29, -2}}, {{ -9, 4},{ 15, 0}}, {{ 0, 0},{ 0, 0}}, {{ 0, 0},{ 0, 0}}, {{ 0, 0},{ 0, 0}} }; // close semiopenfile

CONST_TEXEL_TUNING EvalScore detachedPawnMalus[2] = { { -15, 2}, { -15, -5} };

Expand Down
2 changes: 2 additions & 0 deletions Source/evalConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ extern CONST_TEXEL_TUNING EvalScore imbalance_theirs[5][5];
extern CONST_TEXEL_TUNING EvalScore PST[6][64];

extern CONST_TEXEL_TUNING EvalScore pawnShieldBonus ;
extern CONST_TEXEL_TUNING EvalScore pawnFawnMalusKS ;
extern CONST_TEXEL_TUNING EvalScore pawnFawnMalusQS ;
extern CONST_TEXEL_TUNING EvalScore passerBonus[8] ;
extern CONST_TEXEL_TUNING EvalScore rookBehindPassed ;
extern CONST_TEXEL_TUNING EvalScore kingNearPassedPawn ;
Expand Down
33 changes: 22 additions & 11 deletions Source/texelTuning.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ struct TexelInput {
template < typename T >
struct TexelParam {
public:
TexelParam(T & accessor, const T& inf, const T& sup, const std::string & name, const std::function<void(const T&)> & hook = [](const T&){}) :accessor(&accessor), inf(inf), sup(sup), name(name), hook(hook) {}
TexelParam(T & _accessor, const T& _inf, const T& _sup, const std::string & _name, const std::function<void(const T&)> & _hook = [](const T&){})
:accessor(&_accessor), inf(_inf), sup(_sup), name(_name), hook(_hook) {}
T * accessor;
T inf;
T sup;
Expand Down Expand Up @@ -79,7 +80,7 @@ double E(const std::vector<Texel::TexelInput> &data, size_t miniBatchSize) {
const bool progress = miniBatchSize > 100000;
std::chrono::time_point<Clock> startTime = Clock::now();

auto worker = [&] (size_t begin, size_t end, std::atomic<double> & acc, int t) {
auto worker = [&] (size_t begin, size_t end, std::atomic<double> & acc, int /*t*/) {
double ee = 0;
for(auto k = begin; k != end; ++k) {
ee += std::pow((data[k].result+1)*0.5 - Sigmoid(data[k].p),2);
Expand Down Expand Up @@ -113,7 +114,9 @@ double E(const std::vector<Texel::TexelInput> &data, size_t miniBatchSize) {
return e/miniBatchSize;
}

void Randomize(std::vector<Texel::TexelInput> & data, size_t miniBatchSize){ std::shuffle(data.begin(), data.end(), std::default_random_engine(0)); }
void Randomize(std::vector<Texel::TexelInput> & data){
std::shuffle(data.begin(), data.end(), std::default_random_engine(0));
}

double computeOptimalK(const std::vector<Texel::TexelInput> & data) {
double Kstart = 0.05, Kend = 3.0, Kdelta = 0.15;
Expand Down Expand Up @@ -180,7 +183,7 @@ void displayTexel(const std::string prefixe, const std::vector<TexelParam<ScoreT
std::vector<TexelParam<ScoreType> > TexelOptimizeGD(const std::vector<TexelParam<ScoreType> >& initialGuess, std::vector<Texel::TexelInput> &data, const size_t batchSize, const int loops, const std::string & prefix) {
DynamicConfig::disableTT = true;
int it = 0;
Randomize(data, batchSize);
Randomize(data);
std::vector<TexelParam<ScoreType> > bestParam = initialGuess;
std::vector<ScoreType> previousUpdate(batchSize,0);
while (it < loops ) {
Expand Down Expand Up @@ -213,7 +216,7 @@ std::vector<TexelParam<ScoreType> > TexelOptimizeGD(const std::vector<TexelParam
double curE = E(data, batchSize);
Logging::LogIt(Logging::logInfo) << "-> " << curE;
// randomize for next iteration
Randomize(data, batchSize);
Randomize(data);
displayTexel(prefix,bestParam,it,curE);
++it;
}
Expand All @@ -228,13 +231,13 @@ std::vector<TexelParam<ScoreType> > TexelOptimizeNaive(const std::vector<TexelPa
int step = 0;
for (int loop = 0; loop < 5000; ++loop) {
for (size_t k = 0; k < bestParam.size(); ++k) {
Randomize(data, batchSize);
Randomize(data);
double initE = E(data, batchSize);
double curE = -1;
step = 0;
while ( step < stepMax ) {
step++;
const ScoreType oldValue = bestParam[k];
ScoreType oldValue = bestParam[k];
bestParam[k] = ScoreType(oldValue - 1);
if (bestParam[k] == oldValue) break;
curE = E(data, batchSize);
Expand All @@ -243,7 +246,7 @@ std::vector<TexelParam<ScoreType> > TexelOptimizeNaive(const std::vector<TexelPa
initE = curE;
}
else{
ScoreType oldValue = bestParam[k];
oldValue = bestParam[k];
bestParam[k] = ScoreType(oldValue + 1);
//curE = E(data, batchSize);
break;
Expand All @@ -252,7 +255,7 @@ std::vector<TexelParam<ScoreType> > TexelOptimizeNaive(const std::vector<TexelPa
step = 0;
while ( step < stepMax ) {
step++;
const ScoreType oldValue = bestParam[k];
ScoreType oldValue = bestParam[k];
bestParam[k] = ScoreType(oldValue + 1);
if (bestParam[k] == oldValue) break;
curE = E(data, batchSize);
Expand All @@ -261,15 +264,15 @@ std::vector<TexelParam<ScoreType> > TexelOptimizeNaive(const std::vector<TexelPa
initE = curE;
}
else{
ScoreType oldValue = bestParam[k];
oldValue = bestParam[k];
bestParam[k] = ScoreType(oldValue - 1);
//curE = E(data, batchSize);
break;
}
}
// write
str << loop << ";" << k << ";";
for (size_t k = 0; k < bestParam.size(); ++k) str << bestParam[k] << ";";
for (size_t kk = 0; kk < bestParam.size(); ++kk) str << bestParam[kk] << ";";
str << curE << std::endl;
}
}
Expand Down Expand Up @@ -384,6 +387,12 @@ void TexelTuning(const std::string & filename) {
guess["freePasser"].push_back(Texel::TexelParam<ScoreType>(EvalConfig::freePasserBonus[6][MG] , -150, 150,"freePasserBonus"));
guess["freePasser"].push_back(Texel::TexelParam<ScoreType>(EvalConfig::freePasserBonus[6][EG] , -150, 150,"freePasserBonusEG"));

guess["Fawn"].push_back(Texel::TexelParam<ScoreType>(EvalConfig::pawnFawnMalusKS[MG] , -150, 150,"pawnFawnMalusKS"));
guess["Fawn"].push_back(Texel::TexelParam<ScoreType>(EvalConfig::pawnFawnMalusKS[EG] , -150, 150,"pawnFawnMalusKSEG"));
guess["Fawn"].push_back(Texel::TexelParam<ScoreType>(EvalConfig::pawnFawnMalusQS[MG] , -150, 150,"pawnFawnMalusQS"));
guess["Fawn"].push_back(Texel::TexelParam<ScoreType>(EvalConfig::pawnFawnMalusQS[EG] , -150, 150,"pawnFawnMalusQSEG"));


for (int k = 0 ; k < 9 ; ++k ){
guess["adjustN"].push_back(Texel::TexelParam<ScoreType>(EvalConfig::adjKnight[k][MG] , -150, 150,"adjKnightMG"+std::to_string(k)));
guess["adjustN"].push_back(Texel::TexelParam<ScoreType>(EvalConfig::adjKnight[k][EG] , -150, 150,"adjKnightEG"+std::to_string(k)));
Expand Down Expand Up @@ -689,6 +698,8 @@ void TexelTuning(const std::string & filename) {
"pawnStructure3",
"pawnStructure4",
"PST0",
"Fawn",
"storm",
//"knightTooFar",
//"PST1",
//"PST2",
Expand Down
2 changes: 1 addition & 1 deletion Tools/run_xboard_self
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

dir=$(readlink -f $(dirname $0)/..)

/usr/games/xboard -fcp "$dir/Dist/Minic2/minic_dev_linux_x64 -xboard -quiet 0" -fd "$dir/Dist/" -scp "$dir/Dist/Minic2/minic_dev_linux_x64 -xboard -quiet 0" -sd "$dir/Dist/" -tc 0:20 -mps 40 -xponder -debug
/usr/games/xboard -fcp "$dir/Dist/Minic2/minic_dev_linux_x64 -xboard -quiet 0" -fd "$dir/Dist/" -scp "$dir/Dist/Minic2/minic_${1}_linux_x64_avx2_bmi2 -xboard -quiet 0" -sd "$dir/Dist/" -tc 0:20 -mps 40 -xponder -debug

0 comments on commit 5327ad4

Please sign in to comment.