Skip to content

Commit

Permalink
2.0
Browse files Browse the repository at this point in the history
Stockfish Patch 08312018
Improve Stats definition
  • Loading branch information
amchess committed Aug 2, 2018
1 parent d186d0e commit 6b6f705
Show file tree
Hide file tree
Showing 16 changed files with 234 additions and 284 deletions.
2 changes: 1 addition & 1 deletion src/bitboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -382,4 +382,4 @@ inline Square pop_lsb(Bitboard* b) {
inline Square frontmost_sq(Color c, Bitboard b) { return c == WHITE ? msb(b) : lsb(b); }
inline Square backmost_sq(Color c, Bitboard b) { return c == WHITE ? lsb(b) : msb(b); }

#endif // #ifndef BITBOARD_H_INCLUDED
#endif // #ifndef BITBOARD_H_INCLUDED
2 changes: 1 addition & 1 deletion src/endgame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -768,4 +768,4 @@ ScaleFactor Endgame<KPKP>::operator()(const Position& pos) const {
// Probe the KPK bitbase with the weakest side's pawn removed. If it's a draw,
// it's probably at least a draw even with the pawn.
return Bitbases::probe(wksq, psq, bksq, us) ? SCALE_FACTOR_NONE : SCALE_FACTOR_DRAW;
}
}
29 changes: 19 additions & 10 deletions src/evaluate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ namespace {

public:
Evaluation() = delete;
explicit Evaluation(Position& p) : pos(p) {}
explicit Evaluation(const Position& p) : pos(p) {}
Evaluation& operator=(const Evaluation&) = delete;
Value value();

Expand All @@ -227,7 +227,7 @@ namespace {
ScaleFactor scale_factor(Value eg) const;
Score initiative(Value eg) const;

Position& pos;
const Position& pos;
Material::Entry* me;
Pawns::Entry* pe;
Bitboard mobilityArea[COLOR_NB];
Expand Down Expand Up @@ -513,7 +513,7 @@ namespace {
- 30;

// Transform the kingDanger units into a Score, and subtract it from the evaluation
int kingSafe = pos.getShashinKingSafe();//Shashin very good tactical patch
int kingSafe = Search::shashinKingSafe;//Shashin very good tactical patch
if (kingDanger > 0)
{
int mobilityDanger = mg_value(mobility[Them] - mobility[Us]);
Expand Down Expand Up @@ -861,7 +861,7 @@ namespace {
Value Evaluation<T>::value() {

assert(!pos.checkers());
setWeightsByShashinValue(pos.getShashinValue()); //from shashin
setWeightsByShashinValue(Search::shashinValue); //from shashin
// Probe the material hash table
me = Material::probe(pos);

Expand Down Expand Up @@ -897,14 +897,23 @@ namespace {
+ pieces<WHITE, QUEEN >() - pieces<BLACK, QUEEN >(),weightsMG[PIECES_POS],weightsEG[PIECES_POS]);
}
//from Sugar
double passed_Junior_scale = 1.0 + (-abs(v / Value(int(1.0 * double(PawnValueMg + PawnValueEg) / 2.0))) + 0.5) * abs(0.2 / (MidgameLimit + EndgameLimit));
double king_Junior_scale = 1.0 - (-abs(v / Value(int(1.0 * double(PawnValueMg + PawnValueEg) / 2.0))) + 0.5) * abs(0.2 / (MidgameLimit + EndgameLimit));
double king_Shashin_scale = 1.0;
double passed_Shashin_scale = 1.0;

if (abs(v) >= double(PawnValueMg + PawnValueEg) / 2.0)
{
king_Shashin_scale = 1.0 - (-abs(v / Value(int(1.0 * double(PawnValueMg + PawnValueEg) / 2.0))) + 0.5) * abs(0.1 / (MidgameLimit + EndgameLimit));
}
else
{
passed_Shashin_scale = 1.0 + (-abs(v / Value(int(1.0 * double(PawnValueMg + PawnValueEg) / 2.0))) + 0.5) * abs(0.1 / (MidgameLimit + EndgameLimit));
}
//end from Sugar

score += apply_weight(mobility[WHITE] - mobility[BLACK],weightsMG[MOBILITY_POS],weightsEG[MOBILITY_POS]);
score += apply_weight(Score(int(double(king< WHITE>() - king< BLACK>()) * king_Junior_scale)),weightsMG[KING_SAFETY_POS],weightsEG[KING_SAFETY_POS]); //from Sugar
score += apply_weight(Score(int(double(king< WHITE>() - king< BLACK>()) * king_Shashin_scale)),weightsMG[KING_SAFETY_POS],weightsEG[KING_SAFETY_POS]); //from Sugar
score += apply_weight(threats<WHITE>() - threats<BLACK>(),weightsMG[THREATS_POS],weightsEG[THREATS_POS]);
score += apply_weight(Score(int(double(passed< WHITE>() - passed< BLACK>()) * passed_Junior_scale)),weightsMG[PASSED_PAWNS_POS],weightsEG[PASSED_PAWNS_POS]); //from Sugar
score += apply_weight(Score(int(double(passed< WHITE>() - passed< BLACK>()) * passed_Shashin_scale)),weightsMG[PASSED_PAWNS_POS],weightsEG[PASSED_PAWNS_POS]); //from Sugar
if(pawnsPiecesSpace)
score += apply_weight(space< WHITE>() - space< BLACK>(),weightsMG[SPACE_POS],weightsEG[SPACE_POS]);
if(initiativeToCalculate)
Expand Down Expand Up @@ -937,7 +946,7 @@ namespace {
/// evaluate() is the evaluator for the outer world. It returns a static
/// evaluation of the position from the point of view of the side to move.

Value Eval::evaluate(Position& pos) {
Value Eval::evaluate(const Position& pos) {
return Evaluation<NO_TRACE>(pos).value();
}

Expand All @@ -946,7 +955,7 @@ Value Eval::evaluate(Position& pos) {
/// a string (suitable for outputting to stdout) that contains the detailed
/// descriptions and values of each evaluation term. Useful for debugging.

std::string Eval::trace(Position& pos) {
std::string Eval::trace(const Position& pos) {

std::memset(scores, 0, sizeof(scores));

Expand Down
4 changes: 2 additions & 2 deletions src/evaluate.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ namespace Eval {

constexpr Value Tempo = Value(20); // Must be visible to search

std::string trace(Position& pos);//from Shashin
std::string trace(const Position& pos);

Value evaluate(Position& pos);//from Shashin
Value evaluate(const Position& pos);
}

#endif // #ifndef EVALUATE_H_INCLUDED
22 changes: 11 additions & 11 deletions src/makeAll.bat
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,42 @@ ren C:\MinGW\mingw32-730-pd mingw32
make clean
mingw32-make profile-build ARCH=x86-64 COMP=mingw CXX=x86_64-w64-mingw32-g++ -j14
strip shashchess.exe
ren shashchess.exe "ShashChess Pro 1.1.1-x86-64.exe"
ren shashchess.exe "ShashChess Pro 2.0-x86-64.exe"
make clean
mingw32-make profile-build ARCH=x86-64-modern COMP=mingw CXX=x86_64-w64-mingw32-g++ -j14
strip shashchess.exe
ren shashchess.exe "ShashChess Pro 1.1.1-x86-64-modern.exe"
ren shashchess.exe "ShashChess Pro 2.0-x86-64-modern.exe"
make clean
mingw32-make profile-build ARCH=x86-64-bmi2 COMP=mingw CXX=x86_64-w64-mingw32-g++ -j14
strip shashchess.exe
ren shashchess.exe "ShashChess Pro 1.1.1-x86-64-bmi2.exe"
ren shashchess.exe "ShashChess Pro 2.0-x86-64-bmi2.exe"
mingw32-make build ARCH=ppc-64 COMP=mingw
strip shashchess.exe
ren shashchess.exe "ShashChess Pro 1.1.1-ppc-64.exe"
ren shashchess.exe "ShashChess Pro 2.0-ppc-64.exe"
make clean
mingw32-make profile-build ARCH=general-64 COMP=mingw CXX=x86_64-w64-mingw32-g++ -j14
strip shashchess.exe
ren shashchess.exe "ShashChess Pro 1.1.1-general-64.exe"
ren shashchess.exe "ShashChess Pro 2.0-general-64.exe"
make clean
mingw32-make build ARCH=ppc-32 COMP=mingw
strip shashchess.exe
ren shashchess.exe "ShashChess Pro 1.1.1-ppc-32.exe"
ren shashchess.exe "ShashChess Pro 2.0-ppc-32.exe"
make clean
mingw32-make profile-build ARCH=armv7 COMP=mingw CXX=x86_64-w64-mingw32-g++ -j14
mingw32-make build ARCH=armv7 COMP=gcc
strip shashchess.exe
ren shashchess.exe "ShashChess Pro 1.1.1-armv7.exe"
ren shashchess.exe "ShashChess Pro 2.0-armv7.exe"
make clean
mingw32-make -f MakeFile profile-build ARCH=general-32 COMP=mingw
strip shashchess.exe
ren shashchess.exe "ShashChess Pro 1.1.1-general-32.exe"
ren shashchess.exe "ShashChess Pro 2.0-general-32.exe"
make clean
mingw32-make -f MakeFile profile-build ARCH=x86-32 COMP=mingw
strip shashchess.exe
ren shashchess.exe "ShashChess Pro 1.1.1-x86-32.exe"
ren shashchess.exe "ShashChess Pro 2.0-x86-32.exe"
make clean
mingw32-make -f MakeFile profile-build ARCH=x86-32-old COMP=mingw
strip shashchess.exe
ren shashchess.exe "ShashChess Pro 1.1.1-x86-32-old.exe"
ren shashchess.exe "ShashChess Pro 2.0-x86-32-old.exe"
make clean
ren C:\MinGW\mingw64 mingw64-730-pse
ren C:\MinGW\mingw32 mingw32-730-pd
Expand Down
40 changes: 20 additions & 20 deletions src/makeAll.sh
Original file line number Diff line number Diff line change
@@ -1,49 +1,49 @@
make profile-build ARCH=x86-64 COMP=gcc COMPCC=gcc-7.3.0
make build ARCH=x86-64 COMPCC=gcc-7.3.0
strip shashchess
mv 'shashchess' 'ShashChess Pro 1.1.1-x86-64'
mv 'shashchess' 'ShashChess Pro 2.0-x86-64'
make clean

make profile-build ARCH=x86-64-modern COMP=gcc COMPCC=gcc-7.3.0
make build ARCH=x86-64-modern COMPCC=gcc-7.3.0
strip shashchess
mv 'shashchess' 'ShashChess Pro 1.1.1-x86-64-modern'
mv 'shashchess' 'ShashChess Pro 2.0-x86-64-modern'
make clean

make profile-build ARCH=x86-64-bmi2 COMP=gcc COMPCC=gcc-7.3.0
make build ARCH=x86-64-bmi2 COMPCC=gcc-7.3.0
strip shashchess
mv 'shashchess' 'ShashChess Pro 1.1.1-x86-64-bmi2'
mv 'shashchess' 'ShashChess Pro 2.0-x86-64-bmi2'
make clean

make profile-build ARCH=x86-32 COMP=gcc COMPCC=gcc-7.3.0
make build ARCH=x86-32 COMPCC=gcc-7.3.0
strip shashchess
mv 'shashchess' 'ShashChess Pro 1.1.1-x86-32'
mv 'shashchess' 'ShashChess Pro 2.0-x86-32'
make clean

make profile-build ARCH=x86-32-old COMP=gcc COMPCC=gcc-7.3.0
make build ARCH=x86-32-old COMPCC=gcc-7.3.0
strip shashchess
mv 'shashchess' 'ShashChess Pro 1.1.1-x86-32-old'
mv 'shashchess' 'ShashChess Pro 2.0-x86-32-old'
make clean

make profile-build ARCH=ppc-64 COMP=gcc COMPCC=gcc-7.3.0
make build ARCH=ppc-64 COMPCC=gcc-7.3.0
strip shashchess
mv 'shashchess' 'ShashChess Pro 1.1.1-ppc-64'
mv 'shashchess' 'ShashChess Pro 2.0-ppc-64'
make clean

make profile-build ARCH=ppc-32 COMP=gcc COMPCC=gcc-7.3.0
make build ARCH=ppc-32 COMPCC=gcc-7.3.0
strip shashchess
mv 'shashchess' 'ShashChess Pro 1.1.1-ppc-32'
mv 'shashchess' 'ShashChess Pro 2.0-ppc-32'
make clean

make profile-build ARCH=armv7 COMP=gcc COMPCC=gcc-7.3.0
make build ARCH=armv7 COMPCC=gcc-7.3.0
strip shashchess
mv 'shashchess' 'ShashChess Pro 1.1.1-armv7'
mv 'shashchess' 'ShashChess Pro 2.0-armv7'
make clean

make profile-build ARCH=general-64 COMP=gcc COMPCC=gcc-7.3.0
make build ARCH=general-64 COMPCC=gcc-7.3.0
strip shashchess
mv 'shashchess' 'ShashChess Pro 1.1.1-general-64'
mv 'shashchess' 'ShashChess Pro 2.0-general-64'
make clean

make profile-build ARCH=general-32 COMP=gcc COMPCC=gcc-7.3.0
make build ARCH=general-32 COMPCC=gcc-7.3.0
strip shashchess
mv 'shashchess' 'ShashChess Pro 1.1.1-general-32'
mv 'shashchess' 'ShashChess Pro 2.0-general-32'
make clean
2 changes: 1 addition & 1 deletion src/misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ namespace {

/// Version number. If Version is left empty, then compile date in the format
/// DD-MM-YY and show in engine_info.
const string Version = "1.1.1";
const string Version = "2.0";

/// 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
25 changes: 13 additions & 12 deletions src/movepick.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,16 @@
template<typename T, int D>
class StatsEntry {

static const bool IsInt = std::is_integral<T>::value;
typedef typename std::conditional<IsInt, int, T>::type TT;

T entry;

public:
T* get() { return &entry; }
void operator=(const T& v) { entry = v; }
operator TT() const { return entry; }
T* operator&() { return &entry; }
T* operator->() { return &entry; }
operator const T&() const { return entry; }

void operator<<(int bonus) {
assert(abs(bonus) <= D); // Ensure range is [-D, D]
assert(abs(bonus) <= D); // Ensure range is [-D, D]
static_assert(D <= std::numeric_limits<T>::max(), "D overflows T");

entry += bonus - entry * abs(bonus) / D;
Expand All @@ -64,18 +62,21 @@ class StatsEntry {
template <typename T, int D, int Size, int... Sizes>
struct Stats : public std::array<Stats<T, D, Sizes...>, Size>
{
T* get() { return this->at(0).get(); }
typedef Stats<T, D, Size, Sizes...> stats;

void fill(const T& v) {
T* p = get();
std::fill(p, p + sizeof(*this) / sizeof(*p), v);

// For standard-layout 'this' points to first struct member
assert(std::is_standard_layout<stats>::value);

typedef StatsEntry<T, D> entry;
entry* p = reinterpret_cast<entry*>(this);
std::fill(p, p + sizeof(*this) / sizeof(entry), v);
}
};

template <typename T, int D, int Size>
struct Stats<T, D, Size> : public std::array<StatsEntry<T, D>, Size> {
T* get() { return this->at(0).get(); }
};
struct Stats<T, D, Size> : public std::array<StatsEntry<T, D>, Size> {};

/// In stats table, D=0 means that the template parameter is not used
enum StatsParams { NOT_USED = 0 };
Expand Down
Loading

0 comments on commit 6b6f705

Please # to comment.