- // Check for 3 repetitions (position + flags + turn)
- checkRepetition()
- {
- if (!this.hashStates)
- this.hashStates = {};
- const startIndex =
- Object.values(this.hashStates).reduce((a,b) => { return a+b; }, 0)
- // Update this.hashStates with last move (or all moves if continuation)
- // NOTE: redundant storage, but faster and moderate size
- for (let i=startIndex; i<this.moves.length; i++)
- {
- const move = this.moves[i];
- if (!this.hashStates[move.hash])
- this.hashStates[move.hash] = 1;
- else
- this.hashStates[move.hash]++;
- }
- return Object.values(this.hashStates).some(elt => { return (elt >= 3); });
- }
-