Skip to content

Commit

Permalink
Merge pull request #103 from Joachim26/6commits231214
Browse files Browse the repository at this point in the history
Master_NoComprS <-- 6commits231214
  • Loading branch information
Joachim26 authored Dec 14, 2023
2 parents 0a90520 + dd70ef4 commit 94cf31d
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 29 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/stockfish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ jobs:
if: env.COMMIT_SHA != 'null'
with:
tag_name: ${{ env.COMMIT_SHA }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
github_token: ${{ secrets.GITHUB_TOKEN }}

Analyzers:
uses: ./.github/workflows/stockfish_analyzers.yml
Expand Down
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ Vince Negri (cuddlestmonkey)
Viren
windfishballad
xefoci7612
Xiang Wang (KatyushaScarlet)
zz4032

# Additionally, we acknowledge the authors and maintainers of fishtest,
Expand Down
13 changes: 11 additions & 2 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ ifeq ($(ARCH), $(filter $(ARCH), \
x86-64-vnni512 x86-64-vnni256 x86-64-avx512 x86-64-avxvnni x86-64-bmi2 \
x86-64-avx2 x86-64-sse41-popcnt x86-64-modern x86-64-ssse3 x86-64-sse3-popcnt \
x86-64 x86-32-sse41-popcnt x86-32-sse2 x86-32 ppc-64 ppc-32 e2k \
armv7 armv7-neon armv8 armv8-dotprod apple-silicon general-64 general-32 riscv64))
armv7 armv7-neon armv8 armv8-dotprod apple-silicon general-64 general-32 riscv64 loongarch64))
SUPPORTED_ARCH=true
else
SUPPORTED_ARCH=false
Expand Down Expand Up @@ -374,6 +374,10 @@ endif
ifeq ($(ARCH),riscv64)
arch = riscv64
endif

ifeq ($(ARCH),loongarch64)
arch = loongarch64
endif
endif


Expand Down Expand Up @@ -409,6 +413,8 @@ ifeq ($(COMP),gcc)
ifeq ($(ARCH),riscv64)
CXXFLAGS += -latomic
endif
else ifeq ($(ARCH),loongarch64)
CXXFLAGS += -latomic
else
CXXFLAGS += -m$(bits)
LDFLAGS += -m$(bits)
Expand Down Expand Up @@ -479,6 +485,8 @@ ifeq ($(COMP),clang)
ifeq ($(ARCH),riscv64)
CXXFLAGS += -latomic
endif
else ifeq ($(ARCH),loongarch64)
CXXFLAGS += -latomic
else
CXXFLAGS += -m$(bits)
LDFLAGS += -m$(bits)
Expand Down Expand Up @@ -828,6 +836,7 @@ help:
@echo "general-64 > unspecified 64-bit"
@echo "general-32 > unspecified 32-bit"
@echo "riscv64 > RISC-V 64-bit"
@echo "loongarch64 > LoongArch 64-bit"
@echo ""
@echo "Supported compilers:"
@echo ""
Expand Down Expand Up @@ -1009,7 +1018,7 @@ config-sanity: net
@test "$(SUPPORTED_ARCH)" = "true"
@test "$(arch)" = "any" || test "$(arch)" = "x86_64" || test "$(arch)" = "i386" || \
test "$(arch)" = "ppc64" || test "$(arch)" = "ppc" || test "$(arch)" = "e2k" || \
test "$(arch)" = "armv7" || test "$(arch)" = "armv8" || test "$(arch)" = "arm64" || test "$(arch)" = "riscv64"
test "$(arch)" = "armv7" || test "$(arch)" = "armv8" || test "$(arch)" = "arm64" || test "$(arch)" = "riscv64" || test "$(arch)" = "loongarch64"
@test "$(bits)" = "32" || test "$(bits)" = "64"
@test "$(prefetch)" = "yes" || test "$(prefetch)" = "no"
@test "$(popcnt)" = "yes" || test "$(popcnt)" = "no"
Expand Down
43 changes: 31 additions & 12 deletions src/search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -687,9 +687,11 @@ Value search(Position& pos, Stack* ss, Value alpha, Value beta, Depth depth, boo

int drawScore = TB::UseRule50 ? 1 : 0;

// use the range VALUE_MATE_IN_MAX_PLY to VALUE_TB_WIN_IN_MAX_PLY to score
value = wdl < -drawScore ? VALUE_MATED_IN_MAX_PLY + ss->ply + 1
: wdl > drawScore ? VALUE_MATE_IN_MAX_PLY - ss->ply - 1
Value tbValue = VALUE_TB - ss->ply;

// use the range VALUE_TB to VALUE_TB_WIN_IN_MAX_PLY to score
value = wdl < -drawScore ? -tbValue
: wdl > drawScore ? tbValue
: VALUE_DRAW + 2 * wdl * drawScore;

Bound b = wdl < -drawScore ? BOUND_UPPER
Expand Down Expand Up @@ -1428,6 +1430,10 @@ Value qsearch(Position& pos, Stack* ss, Value alpha, Value beta, Depth depth) {
ss->inCheck = pos.checkers();
moveCount = 0;

// Used to send selDepth info to GUI (selDepth counts from 1, ply from 0)
if (PvNode && thisThread->selDepth < ss->ply + 1)
thisThread->selDepth = ss->ply + 1;

// Step 2. Check for an immediate draw or maximum ply reached
if (pos.is_draw(ss->ply) || ss->ply >= MAX_PLY)
return (ss->ply >= MAX_PLY && !ss->inCheck) ? evaluate(pos) : VALUE_DRAW;
Expand Down Expand Up @@ -1640,25 +1646,38 @@ Value value_to_tt(Value v, int ply) {
// Inverse of value_to_tt(): it adjusts a mate or TB score
// from the transposition table (which refers to the plies to mate/be mated from
// current position) to "plies to mate/be mated (TB win/loss) from the root".
// However, to avoid potentially false mate scores related to the 50 moves rule
// and the graph history interaction problem, we return an optimal TB score instead.
// However, to avoid potentially false mate or TB scores related to the 50 moves rule
// and the graph history interaction, we return highest non-TB score instead.

Value value_from_tt(Value v, int ply, int r50c) {

if (v == VALUE_NONE)
return VALUE_NONE;

if (v >= VALUE_TB_WIN_IN_MAX_PLY) // TB win or better
// handle TB win or better
if (v >= VALUE_TB_WIN_IN_MAX_PLY)
{
if (v >= VALUE_MATE_IN_MAX_PLY && VALUE_MATE - v > 99 - r50c)
return VALUE_MATE_IN_MAX_PLY - 1; // do not return a potentially false mate score
// Downgrade a potentially false mate score
if (v >= VALUE_MATE_IN_MAX_PLY && VALUE_MATE - v > 100 - r50c)
return VALUE_TB_WIN_IN_MAX_PLY - 1;

// Downgrade a potentially false TB score.
if (VALUE_TB - v > 100 - r50c)
return VALUE_TB_WIN_IN_MAX_PLY - 1;

return v - ply;
}

if (v <= VALUE_TB_LOSS_IN_MAX_PLY) // TB loss or worse
// handle TB loss or worse
if (v <= VALUE_TB_LOSS_IN_MAX_PLY)
{
if (v <= VALUE_MATED_IN_MAX_PLY && VALUE_MATE + v > 99 - r50c)
return VALUE_MATED_IN_MAX_PLY + 1; // do not return a potentially false mate score
// Downgrade a potentially false mate score.
if (v <= VALUE_MATED_IN_MAX_PLY && VALUE_MATE + v > 100 - r50c)
return VALUE_TB_LOSS_IN_MAX_PLY + 1;

// Downgrade a potentially false TB score.
if (VALUE_TB + v > 100 - r50c)
return VALUE_TB_LOSS_IN_MAX_PLY + 1;

return v + ply;
}
Expand Down Expand Up @@ -1875,7 +1894,7 @@ string UCI::pv(const Position& pos, Depth depth) {
if (v == -VALUE_INFINITE)
v = VALUE_ZERO;

bool tb = TB::RootInTB && abs(v) < VALUE_MATE_IN_MAX_PLY;
bool tb = TB::RootInTB && abs(v) <= VALUE_TB;
v = tb ? rootMoves[i].tbScore : v;

if (ss.rdbuf()->in_avail()) // Not at first line
Expand Down
5 changes: 0 additions & 5 deletions src/timeman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ void TimeManagement::init(Search::LimitsType& limits, Color us, int ply) {
return;

TimePoint moveOverhead = TimePoint(Options["Move Overhead"]);
TimePoint slowMover = TimePoint(Options["Slow Mover"]);
TimePoint npmsec = TimePoint(Options["nodestime"]);

// optScale is a percentage of available time to use for the current move.
Expand Down Expand Up @@ -78,10 +77,6 @@ void TimeManagement::init(Search::LimitsType& limits, Color us, int ply) {
double optConstant = std::min(0.00335 + 0.0003 * std::log10(limits.time[us] / 1000.0), 0.0048);
double maxConstant = std::max(3.6 + 3.0 * std::log10(limits.time[us] / 1000.0), 2.7);

// A user may scale time usage by setting UCI option "Slow Mover"
// Default is 100 and changing this value will probably lose elo.
timeLeft = slowMover * timeLeft / 100;

// x basetime (+ z increment)
// If there is a healthy increment, timeLeft can exceed actual available
// game time for the current move, so also cap to 20% of available game time.
Expand Down
12 changes: 7 additions & 5 deletions src/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,16 @@ enum Bound {
enum Value : int {
VALUE_ZERO = 0,
VALUE_DRAW = 0,
VALUE_MATE = 32000,
VALUE_INFINITE = 32001,
VALUE_NONE = 32002,
VALUE_INFINITE = 32001,

VALUE_MATE = 32000,
VALUE_MATE_IN_MAX_PLY = VALUE_MATE - MAX_PLY,
VALUE_MATED_IN_MAX_PLY = -VALUE_MATE_IN_MAX_PLY,

VALUE_TB_WIN_IN_MAX_PLY = VALUE_MATE - 2 * MAX_PLY,
VALUE_TB = VALUE_MATE_IN_MAX_PLY - 1,
VALUE_TB_WIN_IN_MAX_PLY = VALUE_TB - MAX_PLY,
VALUE_TB_LOSS_IN_MAX_PLY = -VALUE_TB_WIN_IN_MAX_PLY,
VALUE_MATE_IN_MAX_PLY = VALUE_MATE - MAX_PLY,
VALUE_MATED_IN_MAX_PLY = -VALUE_MATE_IN_MAX_PLY,

// In the code, we make the assumption that these values
// are such that non_pawn_material() can be used to uniquely
Expand Down
4 changes: 2 additions & 2 deletions src/uci.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,9 +372,9 @@ std::string UCI::value(Value v) {

if (abs(v) < VALUE_TB_WIN_IN_MAX_PLY)
ss << "cp " << UCI::to_cp(v);
else if (abs(v) < VALUE_MATE_IN_MAX_PLY)
else if (abs(v) <= VALUE_TB)
{
const int ply = VALUE_MATE_IN_MAX_PLY - 1 - std::abs(v); // recompute ss->ply
const int ply = VALUE_TB - std::abs(v); // recompute ss->ply
ss << "cp " << (v > 0 ? 20000 - ply : -20000 + ply);
}
else
Expand Down
1 change: 0 additions & 1 deletion src/ucioption.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ void init(OptionsMap& o) {
o["MultiPV"] << Option(1, 1, 500);
o["Skill Level"] << Option(20, 0, 20);
o["Move Overhead"] << Option(10, 0, 5000);
o["Slow Mover"] << Option(100, 10, 1000);
o["nodestime"] << Option(0, 0, 10000);
o["UCI_Chess960"] << Option(false);
o["UCI_AnalyseMode"] << Option(false);
Expand Down

0 comments on commit 94cf31d

Please sign in to comment.