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