Skip to content

Commit

Permalink
Fixes a bug in position command
Browse files Browse the repository at this point in the history
  • Loading branch information
fathzer committed Mar 29, 2024
1 parent c144201 commit 571d8cc
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/main/java/com/fathzer/jchess/uci/UCI.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ protected void doNewGame(Deque<String> tokens) {
}

protected void doPosition(Deque<String> tokens) {
if (tokens.isEmpty()) {
debug("missing position definition");
return;
}
final String first = tokens.pop();
final String fen;
if ("fen".equals(first)) {
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/com/fathzer/jchess/uci/UCITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ void clear() {

@Test
void test() {
// assertFalse(uci.post("cjhjhl",500));
// assertFalse(uci.getDebug().isEmpty());
assertFalse(uci.post("cjhjhl",500));
assertFalse(uci.getDebug().isEmpty());

clear();
assertTrue(uci.post("position", 60000));
System.out.println(uci.getOutput());
assertFalse(uci.getDebug().isEmpty());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ private UnknownCommandException(String command) {
private final BlockingQueue<String> input;
private final BlockingQueue<String> output;
private final BlockingQueue<String> debug;
private final Map<String, Exception> exceptions;
private final Map<String, Throwable> exceptions;

public InstrumentedUCI(Engine defaultEngine) {
super(defaultEngine);
Expand All @@ -47,6 +47,11 @@ protected void out(CharSequence message) {
output.add(message.toString());
}

@Override
protected void err(String tag, Throwable e) {
exceptions.put(tag, e);
}

@Override
protected void debug(CharSequence message) {
debug.add(message.toString());
Expand Down Expand Up @@ -75,7 +80,7 @@ public boolean post(String command, long timeOutMS) {
try {
synchronized (this) {
wait(timeOutMS);
final Exception e = exceptions.get(command);
final Throwable e = exceptions.get(command);
if (e!=null) {
if (e instanceof UnknownCommandException) {
return false;
Expand Down

0 comments on commit 571d8cc

Please sign in to comment.