Implemented 'position moves' command in UCI protocol

This commit is contained in:
Kai S. K. Engelbart 2019-10-28 18:31:18 +01:00
parent 43d9fec0f2
commit 4e64e16fa7

View File

@ -2,6 +2,10 @@ package dev.kske.chess.uci;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import java.util.StringJoiner;
import dev.kske.chess.board.Move;
/**
* Project: <strong>Chess</strong><br>
@ -31,34 +35,26 @@ public class UCIHandle {
/**
* Tells the engine to use UCI.
*/
public void uci() {
out.println("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"));
}
public void debug(boolean debug) { out.println("debug " + (debug ? "on" : "off")); }
/**
* Synchronized the engine with the GUI
*/
public void isready() {
out.println("isready");
}
public void isready() { out.println("isready"); }
/**
* Signifies a button press to the engine.
*
* @param name The name of the button
*/
public void setOption(String name) {
out.println("setoption name " + name);
}
public void setOption(String name) { out.println("setoption name " + name); }
/**
* Changes an internal parameter of the engine.
@ -66,9 +62,7 @@ public class UCIHandle {
* @param name The name of the parameter
* @param value The value of the parameter
*/
public void setOption(String name, String value) {
out.printf("setoption name %s value %s%n", name, value);
}
public void setOption(String name, String value) { out.printf("setoption name %s value %s%n", name, value); }
/**
* Registers the engine
@ -76,70 +70,60 @@ public class UCIHandle {
* @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);
}
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");
}
public void registerLater() { out.println("register later"); }
/**
* Tells the engine that the next search will be from a different game.
*/
public void uciNewGame() {
out.println("ucinewgame");
}
// TODO: position
public void uciNewGame() { out.println("ucinewgame"); }
/**
* Sets up the position in its initial state.
*/
public void startPosition() {
out.println("position startpos");
}
public void positionStartpos() { out.println("position startpos"); }
/**
* Sets up the position described in the FEN string.
*
* @param fen FEN representation of the current board
*/
public void positionFEN(String fen) {
out.println("position fen " + fen);
public void positionFEN(String fen) { out.println("position fen " + fen); }
/**
* Sets up the position described by a list of moves.
*
* @param moves the moves to execute from the starting position to reach the
* desired position
*/
public void positionMoves(List<Move> moves) {
StringJoiner joiner = new StringJoiner(" ");
moves.forEach(m -> joiner.add(m.toLAN()));
out.println("position moves " + joiner.toString());
}
// TODO: go with parameters
public void go() {
out.println("go");
}
public void go() { out.println("go"); }
/**
* Stops calculation as soon as possible.
*/
public void stop() {
out.println("stop");
}
public void stop() { out.println("stop"); }
/**
* Tells the engine that the user has played the expected move.
*/
public void ponderHit() {
out.println("ponderhit");
}
public void ponderHit() { out.println("ponderhit"); }
/**
* Quits the engine process as soon as possible.
*/
public void quit() {
out.println("quit");
}
public void quit() { out.println("quit"); }
public void setListener(UCIListener listener) {
receiver.addListener(listener);
}
public void setListener(UCIListener listener) { receiver.addListener(listener); }
}