Implemented 'currline' command in UCI protocol

This commit is contained in:
Kai S. K. Engelbart 2019-10-28 18:24:26 +01:00
parent caff59741c
commit 43d9fec0f2

View File

@ -2,7 +2,9 @@ package dev.kske.chess.uci;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import dev.kske.chess.board.Move; import dev.kske.chess.board.Move;
@ -16,11 +18,12 @@ import dev.kske.chess.board.Move;
*/ */
public class UCIInfo { public class UCIInfo {
private int depth, seldepth, time, nodes, multipv, currmovenumber, hashfull, nps, tbhits, sbhits, cpuload, cpunr; private int depth, seldepth, time, nodes, multipv, currmovenumber, hashfull, nps, tbhits, sbhits, cpuload, cpunr;
private List<Move> pv, refutation, currline; private List<Move> pv = new ArrayList<>(), refutation = new ArrayList<>();
private Move currmove; private Map<Integer, List<Move>> currline = new HashMap<>();
private Score score; private Move currmove;
private String displayString; private Score score;
private String displayString;
/** /**
* Contains every parameter for the UCI info command. Helpful for parsing * Contains every parameter for the UCI info command. Helpful for parsing
@ -45,9 +48,6 @@ public class UCIInfo {
"currline"); "currline");
public UCIInfo(String line) { public UCIInfo(String line) {
pv = new ArrayList<>();
refutation = new ArrayList<>();
currline = new ArrayList<>();
String[] tokens = line.split(" "); String[] tokens = line.split(" ");
for (int i = 0; i < tokens.length; i++) for (int i = 0; i < tokens.length; i++)
@ -104,10 +104,13 @@ public class UCIInfo {
while (++i < tokens.length && !params.contains(tokens[i])) while (++i < tokens.length && !params.contains(tokens[i]))
refutation.add(Move.fromLAN(tokens[i])); refutation.add(Move.fromLAN(tokens[i]));
break; break;
// TODO: currline
case "currline": case "currline":
while (++i < tokens.length && !params.contains(tokens[i])) // A CPU number of 1 can be omitted
; final Integer cpu = tokens[i].matches("\\d+") ? Integer.valueOf(tokens[i++]) : 1;
final ArrayList<Move> moves = new ArrayList<>();
while (i < tokens.length && !params.contains(tokens[i]))
moves.add(Move.fromLAN(tokens[i++]));
currline.put(cpu, moves);
System.err.println("The parameter 'currline' for command 'info' is not yet implemented"); System.err.println("The parameter 'currline' for command 'info' is not yet implemented");
break; break;
default: default:
@ -143,7 +146,7 @@ public class UCIInfo {
public List<Move> getRefutation() { return refutation; } public List<Move> getRefutation() { return refutation; }
public List<Move> getCurrline() { return currline; } public Map<Integer, List<Move>> getCurrline() { return currline; }
public Move getCurrmove() { return currmove; } public Move getCurrmove() { return currmove; }