Add UCI_Elo support to CuckooChess engine in DroidFish.

Same implementation as for CuckooChess Java program.
This commit is contained in:
Peter Osterlund 2020-04-13 10:10:17 +02:00
parent 00c59c0247
commit ed47fc0888

View File

@ -70,6 +70,8 @@ public class DroidEngineControl {
// Reduced strength variables
private int strength = 1000;
private boolean limitStrength = false; // If set, overrides strength, using eloToStrength table
private int elo = Integer.MAX_VALUE;
private int maxNPS = 0;
private long randomSeed = 0;
private Random rndGen = new Random();
@ -225,7 +227,7 @@ public class DroidEngineControl {
sc = new Search(pos, posHashList, posHashListSize, tt, ht);
sc.timeLimit(minTimeLimit, maxTimeLimit);
sc.setListener(new SearchListener(os));
sc.setStrength(strength, randomSeed, maxNPS);
sc.setStrength(getStrength(), randomSeed, maxNPS);
sc.nodesBetweenTimeCheck = Math.min(500, sc.nodesBetweenTimeCheck);
MoveGen.MoveList moves = moveGen.pseudoLegalMoves(pos);
MoveGen.removeIllegal(pos, moves);
@ -371,6 +373,8 @@ public class DroidEngineControl {
os.printLine("option name UCI_EngineAbout type string default %s by Peter Osterlund, see http://hem.bredband.net/petero2b/javachess/index.html",
ComputerPlayer.engineName);
os.printLine("option name Strength type spin default 1000 min 0 max 1000");
os.printLine("option name UCI_LimitStrength type check default false");
os.printLine("option name UCI_Elo type spin default 1500 min -625 max 2400");
os.printLine("option name maxNPS type spin default 0 min 0 max 10000000");
}
@ -387,10 +391,55 @@ public class DroidEngineControl {
analyseMode = Boolean.parseBoolean(optionValue);
} else if (optionName.equals("strength")) {
strength = Integer.parseInt(optionValue);
} else if (optionName.equals("uci_limitstrength")) {
limitStrength = Boolean.parseBoolean(optionValue);
} else if (optionName.equals("uci_elo")) {
elo = Integer.parseInt(optionValue);
} else if (optionName.equals("maxnps")) {
maxNPS = Integer.parseInt(optionValue);
}
} catch (NumberFormatException ignore) {
}
}
private static int[][] eloToStrength = {
{ -625, 0 },
{ -572, 10 },
{ -396, 20 },
{ -145, 30 },
{ 204, 45 },
{ 473, 60 },
{ 679, 75 },
{ 891, 100 },
{ 917, 200 },
{ 1055, 300 },
{ 1321, 375 },
{ 1408, 400 },
{ 1694, 500 },
{ 1938, 600 },
{ 2073, 675 },
{ 2182, 750 },
{ 2294, 875 },
{ 2360, 950 },
{ 2410, 1000 },
};
/** Get strength setting, possibly by interpolating in eloToStrength table. */
private int getStrength() {
if (!limitStrength)
return strength;
if (elo <= eloToStrength[0][0])
return eloToStrength[0][1];
int n = eloToStrength.length;
for (int i = 1; i < n; i++) {
if (elo <= eloToStrength[i][0]) {
double a = eloToStrength[i-1][0];
double b = eloToStrength[i ][0];
double fa = eloToStrength[i-1][1];
double fb = eloToStrength[i ][1];
return (int)Math.round(fa + (elo - a) / (b - a) * (fb - fa));
}
}
return eloToStrength[n-1][1];
}
}