Skip to content

Commit

Permalink
clean up code
Browse files Browse the repository at this point in the history
  • Loading branch information
tryingsomestuff committed Apr 7, 2020
1 parent 24e4eb0 commit 2c2245b
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 13 deletions.
6 changes: 6 additions & 0 deletions Source/cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,15 +397,21 @@ int cliManagement(std::string cli, int argc, char ** argv){
DepthType d = 5;
if ( argc > 3 ) d = atoi(argv[3]);
PerftAccumulator acc;
auto start = Clock::now();
perft(p,d,acc);
auto elapsed = std::max(1, (int)std::chrono::duration_cast<std::chrono::milliseconds>(Clock::now() - start).count());
Logging::LogIt(Logging::logInfo) << "Perft done in " << elapsed << "ms";
acc.Display();
return 0;
}

if ( cli == "-analyze" ){
DepthType depth = 15;
if ( argc > 3 ) depth = atoi(argv[3]);
auto start = Clock::now();
analyze(p,depth);
auto elapsed = std::max(1, (int)std::chrono::duration_cast<std::chrono::milliseconds>(Clock::now() - start).count());
Logging::LogIt(Logging::logInfo) << "Analysis done in " << elapsed << "ms";
return 0;
}

Expand Down
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.04";
const std::string MinicVersion = "2.05";

// *** options
#define WITH_UCI
Expand Down
2 changes: 1 addition & 1 deletion Source/eval.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ inline ScoreType eval(const Position & p, EvalData & data, Searcher &context){
pe.danger[Co_Black] += EvalConfig::kingAttSemiOpenfileOur * countBit(kingFlank[bkf] & pe.semiOpenFiles[Co_White])/8;

++context.stats.counters[Stats::sid_ttPawnInsert];
pe.h = Hash64to32(computePHash(p)); // set the pawn entry
pe.h = Hash64to32(computePHash(p)) /*^ Zobrist::ZT[pe.score[MG]%64][13] ^ Zobrist::ZT[pe.score[EG]%64][13]*/; // set the pawn entry
}
assert(pePtr);
const Searcher::PawnEntry & pe = *pePtr;
Expand Down
2 changes: 1 addition & 1 deletion Source/searcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ bool Searcher::getPawnEntry(Hash h, PawnEntry *& pe){
assert(h > 0);
PawnEntry & _e = tablePawn[h&(ttSizePawn-1)];
pe = &_e;
if ( _e.h != Hash64to32(h) ) return false;
if ( (_e.h /*^ Zobrist::ZT[_e.score[MG]%64][13] ^ Zobrist::ZT[_e.score[EG]%64][13]*/) != Hash64to32(h) ) return false;
++stats.counters[Stats::sid_ttPawnhits];
return true;
}
Expand Down
6 changes: 4 additions & 2 deletions Source/searcher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,10 @@ struct Searcher{
ScoreType danger[2] = {0,0};
MiniHash h = 0;
inline void reset(){
score[MG] = 0; score[EG] = 0;
danger[0] = 0; danger[1] = 0;
score[MG] = 0;
score[EG] = 0;
danger[Co_White] = 0;
danger[Co_Black] = 0;
}
};
#pragma pack(pop)
Expand Down
12 changes: 10 additions & 2 deletions Source/searcherDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,16 @@ PVList Searcher::search(const Position & p, Move & m, DepthType & d, ScoreType &
bestScore = score;
if ( isMainThread() ){
displayGUI(depth,seldepth,bestScore,pv,multi+1);
if (TimeMan::isDynamic && depth > MoveDifficultyUtil::emergencyMinDepth && bestScore < depthScores[depth - 1] - MoveDifficultyUtil::emergencyMargin) { moveDifficulty = MoveDifficultyUtil::MD_hardDefense; Logging::LogIt(Logging::logInfo) << "Emergency mode activated : " << bestScore << " < " << depthScores[depth - 1] - MoveDifficultyUtil::emergencyMargin; }
if (TimeMan::isDynamic && (TimeType)std::max(1, int(std::chrono::duration_cast<std::chrono::milliseconds>(Clock::now() - TimeMan::startTime).count()*1.8)) > getCurrentMoveMs()) { stopFlag = true; Logging::LogIt(Logging::logInfo) << "stopflag triggered, not enough time for next depth"; break; } // not enought time
if (TimeMan::isDynamic && depth > MoveDifficultyUtil::emergencyMinDepth
&& bestScore < depthScores[depth - 1] - MoveDifficultyUtil::emergencyMargin) {
moveDifficulty = MoveDifficultyUtil::MD_hardDefense;
Logging::LogIt(Logging::logInfo) << "Emergency mode activated : " << bestScore << " < " << depthScores[depth - 1] - MoveDifficultyUtil::emergencyMargin;
}
if (TimeMan::isDynamic
&& (TimeType)std::max(1, int(std::chrono::duration_cast<std::chrono::milliseconds>(Clock::now() - TimeMan::startTime).count()*1.8)) > getCurrentMoveMs()) {
stopFlag = true;
Logging::LogIt(Logging::logInfo) << "stopflag triggered, not enough time for next depth"; break;
} // not enought time
depthScores[depth] = bestScore;
}
if ( !pv.empty() ){
Expand Down
4 changes: 3 additions & 1 deletion Source/searcherPVS.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ ScoreType Searcher::pvs(ScoreType alpha, ScoreType beta, const Position & p, Dep
const bool noCheck = !isInCheck && !isCheck;
const bool isPrunableStd = isPrunable && isQuiet;
const bool isPrunableStdNoCheck = isPrunableStd && noCheck;
//const bool isEmergency = moveDifficulty == MoveDifficultyUtil::MD_hardDefense; ///@todo try this
const bool isPrunableCap = isPrunable && Move2Type(*it) == T_capture && isBadCap(*it) && noCheck ;
const bool isDangerPrune = data.danger[p.c] > SearchConfig::dangerLimitPruning[0] || data.danger[~p.c] > SearchConfig::dangerLimitPruning[1];
const bool isDangerRed = data.danger[p.c] > SearchConfig::dangerLimitReduction[0] || data.danger[~p.c] > SearchConfig::dangerLimitReduction[1];
Expand All @@ -367,7 +368,7 @@ ScoreType Searcher::pvs(ScoreType alpha, ScoreType beta, const Position & p, Dep
// futility
if (futility && isPrunableStdNoCheck) {++stats.counters[Stats::sid_futility]; continue;}
// LMP
if (lmp && isPrunableStdNoCheck && validMoveCount > (1/*+dangerPruneFactor*/)*SearchConfig::lmpLimit[improving][depth] ) {++stats.counters[Stats::sid_lmp]; continue;}
if (lmp && isPrunableStdNoCheck && validMoveCount > (1/*+dangerPruneFactor*/)*SearchConfig::lmpLimit[improving][depth] /*+ 2*isEmergency*/ ) {++stats.counters[Stats::sid_lmp]; continue;}
// History pruning (with CMH)
if (historyPruning && isPrunableStdNoCheck && Move2Score(*it) < SearchConfig::historyPruningThresholdInit + depth*SearchConfig::historyPruningThresholdDepth) {++stats.counters[Stats::sid_historyPruning]; continue;}
// CMH pruning alone
Expand All @@ -393,6 +394,7 @@ ScoreType Searcher::pvs(ScoreType alpha, ScoreType beta, const Position & p, Dep
else if ( isDangerRed ) --reduction;
else if ( !noCheck ) --reduction;
//else if ( ttMoveSingularExt) --reduction;
//if ( isEmergency ) --reduction;
}
if ( extension - reduction > 0 ) reduction = extension;
if ( reduction >= depth - 1 + extension ) reduction = depth - 1 + extension - 1;
Expand Down
9 changes: 5 additions & 4 deletions Source/searcherSee.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ ScoreType Searcher::SEE(const Position & p, const Move & m) const {

attackers &= ~SquareToBitboard(from);
occupation_mask &= ~SquareToBitboard(from);
const BitBoard occupancy = p.occupancy();

attackers |= BBTools::attack<P_wr>(to, p.whiteQueen() | p.blackQueen() | p.whiteRook() | p.blackRook(), p.occupancy() & occupation_mask, c) |
BBTools::attack<P_wb>(to, p.whiteQueen() | p.blackQueen() | p.whiteBishop() | p.blackBishop(), p.occupancy() & occupation_mask, c) ;
attackers |= BBTools::attack<P_wr>(to, p.whiteQueen() | p.blackQueen() | p.whiteRook() | p.blackRook(), occupancy & occupation_mask, c) |
BBTools::attack<P_wb>(to, p.whiteQueen() | p.blackQueen() | p.whiteBishop() | p.blackBishop(), occupancy & occupation_mask, c) ;
attackers &= occupation_mask;
c = ~c;

Expand All @@ -64,8 +65,8 @@ ScoreType Searcher::SEE(const Position & p, const Move & m) const {
attackers &= ~SquareToBitboard(from);
occupation_mask &= ~SquareToBitboard(from);

attackers |= BBTools::attack<P_wr>(to, p.whiteQueen() | p.blackQueen() | p.whiteRook() | p.blackRook(), p.occupancy() & occupation_mask, c) |
BBTools::attack<P_wb>(to, p.whiteQueen() | p.blackQueen() | p.whiteBishop() | p.blackBishop(), p.occupancy() & occupation_mask, c) ;
attackers |= BBTools::attack<P_wr>(to, p.whiteQueen() | p.blackQueen() | p.whiteRook() | p.blackRook(), occupancy & occupation_mask, c) |
BBTools::attack<P_wb>(to, p.whiteQueen() | p.blackQueen() | p.whiteBishop() | p.blackBishop(), occupancy & occupation_mask, c) ;
attackers &= occupation_mask;

c = ~c;
Expand Down
2 changes: 1 addition & 1 deletion Source/transposition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void initTable(){

void clearTT() {
TT::curGen = 0;
for (unsigned int k = 0; k < ttSize; ++k) table[k] = { 0, INVALIDMINIMOVE, 0, 0, B_alpha, 0 };
for (unsigned int k = 0; k < ttSize; ++k) table[k] = { 0, 0, 0, INVALIDMINIMOVE, B_none, -1 };
}

int hashFull(){
Expand Down

0 comments on commit 2c2245b

Please sign in to comment.