
com.fathzer.chess.utils.transposition.GenerationDetector Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of chess-utils Show documentation
Show all versions of chess-utils Show documentation
Some helpful piece of code to implement chess engines.
The newest version!
package com.fathzer.chess.utils.transposition;
import java.util.function.Predicate;
/** An abstract generation detector that triggers a new generation if a pawn is moved or a capture occurred.
*/
public abstract class GenerationDetector implements Predicate {
private long lastHash;
@Override
public boolean test(B t) {
final long hash = getHash(t);
if (hash==lastHash) {
// Seems the position didn't changes
return false;
}
lastHash = hash;
return getHalfMoveCount(t)<2;
}
/** Gets the hash key of a board.
* @param board The board
* @return a long
*/
protected abstract long getHash(B board);
/** Gets the current half moves counter of a board.
* @param board The board
* @return an positive or null int
*/
protected abstract int getHalfMoveCount(B board);
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy