Skip to content

Commit

Permalink
Also show 5 variations in the "Position evaluation" button
Browse files Browse the repository at this point in the history
  • Loading branch information
Tellmarch committed Apr 25, 2024
1 parent dd0963f commit 88ec9cd
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class USIConnector {
private PrintWriter output;
private boolean connected = false;
private Process process;
private boolean logOutput = true;
private boolean logOutput = false;

public USIConnector(final EngineConfiguration engineConfiguration) {
this.engineConfiguration = engineConfiguration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,21 +176,22 @@ private void drawEvaluation(KifuEvaluationEvent event) {
boolean mate = false;

for (int i = 0; i < positionEvaluationDetails.length; i++) {
PrincipalVariationDetails[] history = positionEvaluationDetails[i].getPrincipalVariationHistory();
if (history.length > 0) {
PrincipalVariationDetails[] topPrincipalVariations =
positionEvaluationDetails[i].getTopPrincipalVariations();
if (topPrincipalVariations.length > 0) {
dataTable.setValue(i, 0, i);
PrincipalVariationDetails latest = history[history.length - 1];
PrincipalVariationDetails best = topPrincipalVariations[0];

int toolTipValue = i % 2 == 0 ? latest.getEvaluationCP() : -latest.getEvaluationCP();
int toolTipValue = i % 2 == 0 ? best.getEvaluationCP() : -best.getEvaluationCP();
int graphValue = Math.min(2000, Math.max(-2000, toolTipValue));

String toolTip = "Move " + i + "\n" + "Evaluation: " + toolTipValue;
String annotation = null;

if (latest.isForcedMate()) {
if (best.isForcedMate()) {
mate = true;
graphValue = (latest.getNumMovesBeforeMate() <= 0) == (i % 2 == 0) ? -2000 : 2000;
toolTip = "Move " + i + "\n" + "Mate in " + Math.abs(latest.getNumMovesBeforeMate());
graphValue = (best.getNumMovesBeforeMate() <= 0) == (i % 2 == 0) ? -2000 : 2000;
toolTip = "Move " + i + "\n" + "Mate in " + Math.abs(best.getNumMovesBeforeMate());
} else {
if (mate) {
annotation = "Missed mate";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,11 +359,11 @@ public PositionEvaluationDetails analysePosition(final String sessionId, final S
private PositionEvaluationDetails analyseNormalPosition(final String sessionId, final String sfen) {
LoginResult loginResult = authenticator.checkSession(sessionId);
if (loginResult != null && loginResult.isLoggedIn()) {
USIConnector usiConnector = new USIConnector(EngineConfiguration.NORMAL_ENGINE);
USIConnector usiConnector = new USIConnector(EngineConfiguration.INSIGHTS_ENGINE);
usiConnector.connect();
PositionEvaluation evaluation = usiConnector.analysePosition(sfen, 5000);
usiConnector.disconnect();
LOGGER.log(Level.INFO, "Position analysis: " + evaluation);
//LOGGER.log(Level.INFO, "Position analysis: " + evaluation);

return convertPositionEvaluation(evaluation);
} else {
Expand Down Expand Up @@ -407,7 +407,7 @@ private PositionEvaluationDetails analyseTsumePosition(final String sessionId, f
variationDetails.setPrincipalVariation(result.getTsumeVariationUsf());
variationDetails.setForcedMate(true);
variationDetails.setNumMovesBeforeMate(result.getTsumeNumMoves());
details.setPrincipalVariationHistory(new PrincipalVariationDetails[]{variationDetails});
details.setTopPrincipalVariations(new PrincipalVariationDetails[]{variationDetails});
}
details.setTsumeAnalysis(tsumeDetails);
details.setSfen(sfen);
Expand All @@ -420,8 +420,6 @@ private PositionEvaluationDetails convertPositionEvaluation(final PositionEvalua
details.setSfen(evaluation.getSfen());
details.setBestMove(evaluation.getBestMove());
details.setPonderMove(evaluation.getPonderMove());
details.setPrincipalVariationHistory(evaluation.getPrincipalVariationsHistory().stream().map(
this::convertPrincipalVariation).toArray(PrincipalVariationDetails[]::new));
details.setTopPrincipalVariations(evaluation.getMultiVariations().getVariations().stream().map(
this::convertPrincipalVariation).toArray(PrincipalVariationDetails[]::new));
return details;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
public class PositionEvaluationDetails implements Serializable {

private String sfen;
private PrincipalVariationDetails[] principalVariationHistory; // Index 0 is oldest (least accurate) eval
private PrincipalVariationDetails[] topPrincipalVariations; // Index 0 is the best line
private String bestMove;
private String ponderMove;
Expand All @@ -23,14 +22,6 @@ public void setSfen(final String sfen) {
this.sfen = sfen;
}

public PrincipalVariationDetails[] getPrincipalVariationHistory() {
return principalVariationHistory;
}

public void setPrincipalVariationHistory(PrincipalVariationDetails[] principalVariationHistory) {
this.principalVariationHistory = principalVariationHistory;
}

public PrincipalVariationDetails[] getTopPrincipalVariations() {
return topPrincipalVariations;
}
Expand Down Expand Up @@ -67,7 +58,6 @@ public void setTsumeAnalysis(TsumeAnalysisDetails tsumeAnalysis) {
public String toString() {
return "PositionEvaluationDetails{" +
"sfen='" + sfen + '\'' +
", principalVariationHistory=" + Arrays.toString(principalVariationHistory) +
", topPrincipalVariations=" + Arrays.toString(topPrincipalVariations) +
", bestMove='" + bestMove + '\'' +
", ponderMove='" + ponderMove + '\'' +
Expand Down

0 comments on commit 88ec9cd

Please sign in to comment.