Skip to content

Latest commit

 

History

History
81 lines (64 loc) · 3.06 KB

README.md

File metadata and controls

81 lines (64 loc) · 3.06 KB

Java Chess UCI API Build Status Codacy Badge codecov

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.

Installation

Maven

<repository>
    <id>jitpack.io</id>
    <url>https://jitpack.io</url>
</repository>
<dependency>
    <groupId>com.github.TheTrueRandom</groupId>
    <artifactId>JavaChessUCI</artifactId>
    <version>master</version>
</dependency>

Gradle

repositories {
    maven { url 'https://jitpack.io' }
}
dependencies {
    implementation 'com.github.TheTrueRandom:JavaChessUCI:master'
}

Usage

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));

Asynchronous

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)