Skip to content

TheTrueRandom/JavaChessUCI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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)

About

Java Chess UCI API

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages