Implemented option setting, added UCIOption class
This commit is contained in:
parent
d34244b1c3
commit
660d33d3b3
@ -1,9 +1,11 @@
|
||||
package dev.kske.chess.game;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import dev.kske.chess.uci.UCIListener;
|
||||
import dev.kske.chess.uci.UCIOption;
|
||||
|
||||
/**
|
||||
* Project: <strong>Chess</strong><br>
|
||||
@ -14,6 +16,11 @@ import dev.kske.chess.uci.UCIListener;
|
||||
class UCIPlayerListener implements UCIListener {
|
||||
|
||||
private String name, author;
|
||||
private List<UCIOption> options;
|
||||
|
||||
public UCIPlayerListener() {
|
||||
options = new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onIdName(String name) {
|
||||
@ -27,12 +34,12 @@ class UCIPlayerListener implements UCIListener {
|
||||
|
||||
@Override
|
||||
public void onUCIOk() {
|
||||
// TODO Auto-generated method stub
|
||||
System.out.println("UCI ok");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReadyOk() {
|
||||
// TODO Auto-generated method stub
|
||||
System.out.println("Ready ok");
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -82,8 +89,8 @@ class UCIPlayerListener implements UCIListener {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOption(String name, GUIType type, String defaultVal, String minVal, String maxVal, List<String> var) {
|
||||
System.out.printf("Option %s of type %s, min %s, max %s, default %s%n", name, type, minVal, maxVal, defaultVal);
|
||||
public void onOption(UCIOption option) {
|
||||
options.add(option);
|
||||
}
|
||||
|
||||
public String getName() { return name; };
|
||||
|
@ -49,6 +49,25 @@ public class UCIHandle {
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes an internal parameter of the engine.
|
||||
*
|
||||
* @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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the engine
|
||||
*
|
||||
@ -66,6 +85,16 @@ public class UCIHandle {
|
||||
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
|
||||
// TODO: go
|
||||
|
||||
/**
|
||||
* Stops calculation as soon as possible.
|
||||
*/
|
||||
@ -73,6 +102,13 @@ public class UCIHandle {
|
||||
out.println("stop");
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells the engine that the user has played the expected move.
|
||||
*/
|
||||
public void ponderHit() {
|
||||
out.println("ponderhit");
|
||||
}
|
||||
|
||||
/**
|
||||
* Quits the engine process as soon as possible.
|
||||
*/
|
||||
|
@ -1,6 +1,5 @@
|
||||
package dev.kske.chess.uci;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@ -90,16 +89,7 @@ public interface UCIListener {
|
||||
/**
|
||||
* Tells the GUI which parameters can be changed in the engine.
|
||||
*
|
||||
* @param name The name of the option
|
||||
* @param type The GUI component through which the option should be set
|
||||
* @param defaultVal The default value of this parameter
|
||||
* @param minVal The minimum value of this parameter
|
||||
* @param maxVal The maximum value of this parameter
|
||||
* @param var A predefined value of this parameter
|
||||
* @param option Option object describing the parameter
|
||||
*/
|
||||
void onOption(String name, GUIType type, String defaultVal, String minVal, String maxVal, List<String> var);
|
||||
|
||||
public static enum GUIType {
|
||||
CHECK, SPIN, COMBO, BUTTON, STRING
|
||||
}
|
||||
void onOption(UCIOption option);
|
||||
}
|
||||
|
25
src/dev/kske/chess/uci/UCIOption.java
Normal file
25
src/dev/kske/chess/uci/UCIOption.java
Normal file
@ -0,0 +1,25 @@
|
||||
package dev.kske.chess.uci;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Project: <strong>Chess</strong><br>
|
||||
* File: <strong>UCIOption.java</strong><br>
|
||||
* Created: <strong>22.07.2019</strong><br>
|
||||
* Author: <strong>Kai S. K. Engelbart</strong>
|
||||
*/
|
||||
public class UCIOption {
|
||||
|
||||
public String name, defaultVal, minVal, maxVal;
|
||||
public GUIType type;
|
||||
public List<String> varList;
|
||||
|
||||
public UCIOption() {
|
||||
varList = new ArrayList<>();
|
||||
}
|
||||
|
||||
public static enum GUIType {
|
||||
CHECK, SPIN, COMBO, BUTTON, STRING
|
||||
}
|
||||
}
|
@ -4,14 +4,12 @@ import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.StringJoiner;
|
||||
|
||||
import dev.kske.chess.uci.UCIListener.GUIType;
|
||||
import dev.kske.chess.uci.UCIOption.GUIType;
|
||||
|
||||
/**
|
||||
* Project: <strong>Chess</strong><br>
|
||||
@ -155,40 +153,36 @@ public class UCIReceiver implements Runnable {
|
||||
|
||||
private void parseOption(String line) {
|
||||
String[] tokens = line.split(" ");
|
||||
|
||||
StringJoiner name = new StringJoiner(" ");
|
||||
GUIType type = null;
|
||||
String defaultVal = null;
|
||||
String minVal = null;
|
||||
String maxVal = null;
|
||||
List<String> var = new ArrayList<>();
|
||||
UCIOption option = new UCIOption();
|
||||
|
||||
for (int i = 0; i < tokens.length; i++)
|
||||
switch (tokens[i]) {
|
||||
case "name":
|
||||
StringJoiner name = new StringJoiner(" ");
|
||||
while (!Arrays.asList("type", "default", "min", "max", "var").contains(tokens[i + 1]))
|
||||
name.add(tokens[++i]);
|
||||
option.name = name.toString();
|
||||
break;
|
||||
case "type":
|
||||
type = GUIType.valueOf(tokens[++i].toUpperCase());
|
||||
option.type = GUIType.valueOf(tokens[++i].toUpperCase());
|
||||
break;
|
||||
case "default":
|
||||
// Default string may be empty
|
||||
defaultVal = i == tokens.length - 1 ? "" : tokens[++i];
|
||||
option.defaultVal = i == tokens.length - 1 ? "" : tokens[++i];
|
||||
break;
|
||||
case "min":
|
||||
minVal = tokens[++i];
|
||||
option.minVal = tokens[++i];
|
||||
break;
|
||||
case "max":
|
||||
maxVal = tokens[++i];
|
||||
option.maxVal = tokens[++i];
|
||||
break;
|
||||
case "var":
|
||||
var.add(tokens[++i]);
|
||||
option.varList.add(tokens[++i]);
|
||||
break;
|
||||
default:
|
||||
System.err.printf("Unknown parameter '%s' for command 'option' found!%n", tokens[i]);
|
||||
}
|
||||
listener.onOption(name.toString(), type, defaultVal, minVal, maxVal, var);
|
||||
listener.onOption(option);
|
||||
}
|
||||
|
||||
public void setListener(UCIListener listener) { this.listener = listener; }
|
||||
|
Reference in New Issue
Block a user