
com.fathzer.chess.utils.evaluators.WdlPawnsConverter 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.evaluators;
/** Utility class to convert centi pawns evaluations to win probability.
*
This class implements the functions found in Chess programming Wiki
*/
public final class WdlPawnsConverter {
private WdlPawnsConverter() {
super();
}
/** Converts a win probability to a centi pawns evaluation.
* @param wdl The win probability (a double strictly between 0.0 and 1.0)
* @return a centi pawn evaluation
* @throws IllegalArgumentException if wdl is <=0.0 or >=1.0.
*/
public static int toCentiPawns(double wdl) {
if (wdl>=1.0 || wdl<=0.0) {
throw new IllegalArgumentException();
}
return (int)Math.round(400.0*Math.log10(wdl/(1-wdl)));
}
/** Converts a centi pawns evaluation to a win probability.
* @param centiPawns A centi pawn evaluation
* @return The win probability (a double strictly between 0.0 and 1.0).
* 0.5 means both players have equals chances.
*/
public static double toWdl(int centiPawns) {
return 1.0/(1.0+Math.pow(10, -(double)centiPawns/400));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy