Skip to content

Commit

Permalink
Fully comply 3 fold repetition
Browse files Browse the repository at this point in the history
Since many simplification patches are added, we performed a test on them all and passed.
Task: Big Simplification
Book: 3mvs 140-200_150560
TC: 10+0.1
Total/Win/Draw/Lose: 6784 / 1254 / 4341 / 1189
PTNML: 21 / 654 / 1989 / 695 / 33
WinRate: 50.48%
ELO: 2.84[-1.60, 7.23]
LOS: 89.55
LLR: 3.46[-2.94, 2.94]
  • Loading branch information
PikaCat committed Dec 26, 2022
1 parent 97ca8d6 commit 88afc2d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ change them via a chess GUI. This is a list of available UCI options in Pikafish
* #### Rule60
Use 60 move rule in gameplay.

* #### Strict3Fold
Not only use 3 fold repetition at root nodes, but also use 3 fold at non-root nodes. Enable this will help get better analyses results but lose elo.

* #### Debug Log File
Write all communication to and from the engine into a text file.

Expand Down
12 changes: 8 additions & 4 deletions src/position.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -937,6 +937,7 @@ bool Position::rule_judge(Value& result, int ply) const {

if (end >= 4 && filter[st->key])
{
int cnt = 1;
StateInfo* stp = st->previous->previous;
bool perpetualThem = st->checkersBB && stp->checkersBB;
bool perpetualUs = st->previous->checkersBB && stp->previous->checkersBB;
Expand All @@ -946,8 +947,9 @@ bool Position::rule_judge(Value& result, int ply) const {
stp = stp->previous->previous;
perpetualThem &= bool(stp->checkersBB);

// Return a score if a position repeats once earlier.
if (stp->key == st->key)
// Return a score if a position repeats once earlier but strictly
// after the root, or repeats twice before or at the root.
if (stp->key == st->key && ++cnt == (!Strict3Fold && ply > i ? 2 : 3))
{
if (perpetualThem || perpetualUs)
{
Expand All @@ -963,6 +965,7 @@ bool Position::rule_judge(Value& result, int ply) const {
rollback.set_chase_info(i);

// Chasing detection
cnt = 1;
stp = st->previous->previous;
uint16_t chaseThem = st->chased & stp->chased;
uint16_t chaseUs = st->previous->chased & stp->previous->chased;
Expand All @@ -974,8 +977,9 @@ bool Position::rule_judge(Value& result, int ply) const {
chaseThem &= stp->previous->previous->chased;
stp = stp->previous->previous;

// Return a score if a position repeats once earlier.
if (stp->key == st->key)
// Return a score if a position repeats once earlier but strictly
// after the root, or repeats twice before or at the root.
if (stp->key == st->key && ++cnt == (!Strict3Fold && ply > i ? 2 : 3))
{
result = (chaseThem || chaseUs) ? (!chaseUs ? mate_in(ply) : !chaseThem ? mated_in(ply) : VALUE_DRAW) : VALUE_DRAW;
return true;
Expand Down
1 change: 1 addition & 0 deletions src/uci.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ Move to_move(const Position& pos, std::string& str);

extern UCI::OptionsMap Options;
extern bool UseRule60;
extern bool Strict3Fold;

} // namespace Stockfish

Expand Down
3 changes: 3 additions & 0 deletions src/ucioption.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ namespace Stockfish {

UCI::OptionsMap Options; // Global object
bool UseRule60 = true;
bool Strict3Fold = false;

namespace UCI {

Expand All @@ -43,6 +44,7 @@ void on_hash_size(const Option& o) { TT.resize(size_t(o)); }
void on_logger(const Option& o) { start_logger(o); }
void on_threads(const Option& o) { Threads.set(size_t(o)); }
void on_rule60(const Option& o) { UseRule60 = bool(o); }
void on_strict3fold(const Option& o) { Strict3Fold = bool(o); }
void on_eval_file(const Option& ) { Eval::NNUE::init(); }

/// Our case insensitive less() function as required by UCI protocol
Expand Down Expand Up @@ -70,6 +72,7 @@ void init(OptionsMap& o) {
o["Slow Mover"] << Option(100, 10, 1000);
o["nodestime"] << Option(0, 0, 10000);
o["Rule60"] << Option(true, on_rule60);
o["Strict3Fold"] << Option(false, on_strict3fold);
o["UCI_LimitStrength"] << Option(false);
o["UCI_Elo"] << Option(1350, 1350, 2850);
o["UCI_WDLCentipawn"] << Option(true);
Expand Down

0 comments on commit 88afc2d

Please sign in to comment.