107 lines
2.4 KiB
Java
107 lines
2.4 KiB
Java
package dev.kske.chess.game;
|
|
|
|
import java.io.IOException;
|
|
|
|
import dev.kske.chess.board.FENString;
|
|
import dev.kske.chess.board.Move;
|
|
import dev.kske.chess.board.Piece.Color;
|
|
import dev.kske.chess.uci.UCIHandle;
|
|
import dev.kske.chess.uci.UCIListener;
|
|
|
|
/**
|
|
* Acts as the interface between the {@link Game} class and the
|
|
* {@link dev.kske.chess.uci} package enabling an engine to make moves in a
|
|
* game.<br>
|
|
* <br>
|
|
* Project: <strong>Chess</strong><br>
|
|
* File: <strong>UCIPlayer.java</strong><br>
|
|
* Created: <strong>18.07.2019</strong><br>
|
|
*
|
|
* @since Chess v0.3-alpha
|
|
* @author Kai S. K. Engelbart
|
|
*/
|
|
public class UCIPlayer extends Player implements UCIListener {
|
|
|
|
private UCIHandle handle;
|
|
|
|
/**
|
|
* Creates an instance of {@link UCIPlayer}.
|
|
*
|
|
* @param game the game in which this player will be used
|
|
* @param color the piece color that this player will control
|
|
* @param enginePath the path to the engine executable
|
|
*/
|
|
public UCIPlayer(Game game, Color color, String enginePath) {
|
|
super(game, color);
|
|
try {
|
|
handle = new UCIHandle(enginePath);
|
|
handle.registerListener(this);
|
|
handle.start();
|
|
} catch (IOException ex) {
|
|
ex.printStackTrace();
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void requestMove() {
|
|
handle.positionFEN(new FENString(board).toString());
|
|
handle.go();
|
|
}
|
|
|
|
@Override
|
|
public void cancelMove() {
|
|
handle.stop();
|
|
}
|
|
|
|
@Override
|
|
public void disconnect() {
|
|
handle.quit();
|
|
}
|
|
|
|
@Override
|
|
public void onIdName(String name) {
|
|
this.name = name;
|
|
}
|
|
|
|
@Override
|
|
public void onBestMove(String move) {
|
|
Move moveObj = Move.fromLAN(move);
|
|
game.onMove(this, moveObj);
|
|
}
|
|
|
|
@Override
|
|
public void onBestMove(String move, Move ponderMove) {
|
|
onBestMove(move);
|
|
}
|
|
|
|
@Override
|
|
public void onCopyProtectionChecking() {
|
|
System.out.println("Copy protection checking...");
|
|
}
|
|
|
|
@Override
|
|
public void onCopyProtectionOk() {
|
|
System.out.println("Copy protection ok");
|
|
}
|
|
|
|
@Override
|
|
public void onCopyProtectionError() {
|
|
System.err.println("Copy protection error!");
|
|
}
|
|
|
|
@Override
|
|
public void onRegistrationChecking() {
|
|
System.out.println("Registration checking...");
|
|
}
|
|
|
|
@Override
|
|
public void onRegistrationOk() {
|
|
System.out.println("Registration ok");
|
|
}
|
|
|
|
@Override
|
|
public void onRegistrationError() {
|
|
System.err.println("Registration error!");
|
|
}
|
|
}
|