mirror of
https://github.com/HChaZZY/Stockfish.git
synced 2025-12-20 09:06:45 +08:00
Fix incorrect draw detection
In this position we should have draw for repetition: position fen rnbqkbnr/2pppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1 moves g1f3 g8f6 f3g1 go infinite But latest patch broke it. Actually we had two(!) very subtle bugs, the first is that Position::set() clears the passed state and in particular 'previous' member, so that on passing setupStates, 'previous' pointer was reset. Second bug is even more subtle: SetupStates was based on std::vector as container, but when vector grows, std::vector copies all its contents to a new location invalidating all references to its entries. Because all StateInfo records are linked by 'previous' pointer, this made pointers go stale upon adding more element to setupStates. So revert to use a std::deque that ensures references are preserved when pushing back new elements. No functional change.
This commit is contained in:
@@ -23,6 +23,7 @@
|
||||
|
||||
#include <cassert>
|
||||
#include <cstddef> // For offsetof()
|
||||
#include <deque>
|
||||
#include <memory> // For std::unique_ptr
|
||||
#include <string>
|
||||
#include <vector>
|
||||
@@ -77,7 +78,8 @@ struct StateInfo {
|
||||
StateInfo* previous;
|
||||
};
|
||||
|
||||
typedef std::unique_ptr<std::vector<StateInfo>> StateListPtr;
|
||||
// In a std::deque references to elements are unaffected upon resizing
|
||||
typedef std::unique_ptr<std::deque<StateInfo>> StateListPtr;
|
||||
|
||||
|
||||
/// Position class stores information regarding the board representation as
|
||||
|
||||
Reference in New Issue
Block a user