This repository has been archived on 2021-02-18. You can view files and clone it, but cannot push or open issues or pull requests.
chess/src/dev/kske/chess/uci/UCIHandle.java

87 lines
1.9 KiB
Java
Raw Normal View History

package dev.kske.chess.uci;
import java.io.IOException;
import java.io.PrintWriter;
/**
* Project: <strong>Chess</strong><br>
* File: <strong>UCIHandle.java</strong><br>
* Created: <strong>18.07.2019</strong><br>
* Author: <strong>Kai S. K. Engelbart</strong>
*/
public class UCIHandle {
private final Process process;
private final PrintWriter out;
private final UCIReceiver receiver;
public UCIHandle(String enginePath) throws IOException {
process = new ProcessBuilder(enginePath).start();
out = new PrintWriter(process.getOutputStream(), true);
receiver = new UCIReceiver(process.getInputStream());
}
public void start() {
new Thread(receiver).start();
uci();
}
/**
* Tells the engine to use UCI.
*/
public void uci() {
out.println("uci");
}
/**
* Switches the debug mode of the engine on or off.
*
* @param debug Enables debugging if set to {@code true}, disables it otherwise
*/
public void debug(boolean debug) {
out.println("debug " + (debug ? "on" : "off"));
}
/**
* Synchronized the engine with the GUI
*/
public void isready() {
out.println("isready");
}
/**
* Registers the engine
*
* @param name The name the engine should be registered with
* @param code The code the engine should be registered with
*/
public void register(String name, String code) {
out.printf("register %s %s%n", name, code);
}
/**
* Tells the engine to postpone the registration.
*/
public void registerLater() {
out.println("register later");
}
/**
* Stops calculation as soon as possible.
*/
public void stop() {
out.println("stop");
}
/**
* Quits the engine process as soon as possible.
*/
public void quit() {
out.println("quit");
}
public void setListener(UCIListener listener) {
receiver.setListener(listener);
}
}