Bugfix of Position::has_repeated()
authorjoergoster <osterj165@googlemail.com>
Fri, 1 Jun 2018 20:35:23 +0000 (22:35 +0200)
committerStéphane Nicolet <cassio@free.fr>
Mon, 4 Jun 2018 05:45:12 +0000 (07:45 +0200)
The function Position::has_repeated() is used by Tablebases::root_probe()
to determine whether we can rank all winning moves with the same value, or
if we need to strictly rank by dtz in case the position has already been
repeated once, and we are risking to run into the 50-move rule and thus
losing the win (especially critical in some very complicated endgames).

To check whether the current position or one of the previous positions
after the last zeroing move has already been occured once, we start looking
for a repetition of the current position, and if that is not the case, we
step one position back and repeat the check for that position, and so on.

If you now look at how this was done before the new root ranking patch was
merged two months ago, it seems quite obvious that it is a simple oversight:
https://github.com/official-stockfish/Stockfish/commit/108f0da4d7f993732aa2e854b8f3fa8ca6d3b46c

More specifically, after we stepped one position back with

```
stc = stc->previous;
```

we now have to start checking for a repetition with

```
StateInfo* stp = stc->previous->previous;
```

and not with

```
StateInfo* stp = st->previous->previous;
```

Closes https://github.com/official-stockfish/Stockfish/pull/1625

No functional change

src/position.cpp

index 8dedce4..2573fe8 100644 (file)
@@ -1153,7 +1153,7 @@ bool Position::has_repeated() const {
         if (end < i)
             return false;
 
         if (end < i)
             return false;
 
-        StateInfo* stp = st->previous->previous;
+        StateInfo* stp = stc->previous->previous;
 
         do {
             stp = stp->previous->previous;
 
         do {
             stp = stp->previous->previous;