Synchronous and asynchronous Java API for the chess UCI interface. For full functionality overview have a look at the interface.
Every method which is waiting for a result from the engine can be executed
synchronously (e.g. goMovetime(int movetime)
) - blocking the current thread until the operation is finished -
or asynchronously (e.g. goMovetimeAsync(int movetime)
) - returning a Future which will complete once the operation is finished.
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
<dependency>
<groupId>com.github.TheTrueRandom</groupId>
<artifactId>JavaChessUCI</artifactId>
<version>master</version>
</dependency>
repositories {
maven { url 'https://jitpack.io' }
}
dependencies {
implementation 'com.github.TheTrueRandom:JavaChessUCI:master'
}
UCIEngine engine = new UCIEngine("/usr/bin/stockfish");
engine.start();
System.out.println("Name: " + engine.getName());
System.out.println("Author: " + engine.getAuthor());
engine.getOptions().entrySet().forEach(System.out::println);
engine.setOption("Threads", 8);
engine.setOption("MultiPV", 2);
engine.uciNewGame();
engine.isReady();
engine.startPos("e2e4", "e7e5");
CalculationResult calculationResult = engine.goMovetime(100);
System.out.println("Bestmove: " + calculationResult.getBestmove());
System.out.println("Ponder: " + calculationResult.getPonder());
System.out.println("Bestmove multipv 1: " + calculationResult.getBestmovePv(1));
System.out.println("Bestmove multipv 2: " + calculationResult.getBestmovePv(2));
System.out.println("Score Information for multipv 1: " + calculationResult.getLastScoreInfo(1));
System.out.println("Score Information for multipv 2: " + calculationResult.getLastScoreInfo(2));
UCIEngine engine = new UCIEngine("/usr/bin/stockfish");
engine.startAsync()
.thenRun(() -> engine.setOption("Threads", 8))
.thenRun(() -> engine.setOption("MultiPV", 2))
.thenRun(engine::uciNewGame)
.thenCompose(aVoid -> engine.isReadyAsync())
.thenRun(() -> engine.startPos("e2e4", "e7e5"))
.thenCompose(aVoid -> engine.goMovetimeAsync(100))
.thenAccept(System.out::println); //CalculationResult(bestmove=g1f3, ponder=b8c6)