Skip to content

Commit

Permalink
Fixes + upgrades
Browse files Browse the repository at this point in the history
Fixes:
- *searchmoves* option of go command ignored in *AbstractEngine*
- Now returns bestmove (none) when no move is possible in go
Library upgrades:
- java 17
- games-core 0.0.9
- junit 5.10.2
  • Loading branch information
fathzer committed Mar 13, 2024
1 parent 26e6f5d commit bdbec51
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 15 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ If you want another way to exchange messages, you can subclass the UCI class and
If you do not use the *com.fathzer.jchess.uci.extended* and *com.fathzer.jchess.uci.helper* packages, you can exclude the *com.fathzer:games-core* dependency.

## Known bugs
- The *searchmoves* option of the go command is ignored by **AbstractEngine**

## TODO
* Verify the engine is protected against strange client behavior (like changing the position during a go request).
Expand Down
10 changes: 5 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,25 @@
<version>1.0.8</version>
</parent>
<artifactId>jchess-uci</artifactId>
<version>2.0.0-SNAPSHOT</version>
<version>2.0.1-SNAPSHOT</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<check-dependencies-java-version>11</check-dependencies-java-version>
<maven.compiler.release>11</maven.compiler.release>
<check-dependencies-java-version>17</check-dependencies-java-version>
<maven.compiler.release>17</maven.compiler.release>
<sonar.organization>fathzer-games</sonar.organization>
</properties>

<dependencies>
<dependency>
<groupId>com.fathzer</groupId>
<artifactId>games-core</artifactId>
<version>0.0.6-SNAPSHOT</version>
<version>0.0.9-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.7.2</version>
<version>5.10.2</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
12 changes: 10 additions & 2 deletions src/main/java/com/fathzer/jchess/uci/BestMoveReply.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,22 @@ public class BestMoveReply {
public BestMoveReply(UCIMove move) {
this(move, null);
}

public BestMoveReply(UCIMove move, UCIMove ponderMove) {
this.move = move;
this.ponderMove = ponderMove;
}
public UCIMove getMove() {
return move;

public Optional<UCIMove> getMove() {
return Optional.ofNullable(move);
}

public Optional<UCIMove> getPonderMove() {
return Optional.ofNullable(ponderMove);
}

@Override
public String toString() {
return "bestmove "+(move==null?"(none)":move)+(ponderMove==null?"":(" "+ponderMove));
}
}
5 changes: 1 addition & 4 deletions src/main/java/com/fathzer/jchess/uci/UCI.java
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,7 @@ protected void doGo(Deque<String> tokens) {
final Optional<GoParameters> goOptions = parse(GoParameters::new, GoParameters.PARSER, tokens);
if (goOptions.isPresent()) {
final LongRunningTask<BestMoveReply> task = engine.go(goOptions.get());
final boolean started = doBackground(() -> {
final BestMoveReply reply = task.get();
out("bestmove "+reply.getMove()+(reply.getPonderMove().isEmpty()?"":(" "+reply.getPonderMove().get())));
}, task::stop);
final boolean started = doBackground(() -> out(task.get().toString()), task::stop);
if (!started) {
debug("Engine is already working");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,10 @@ public LongRunningTask<BestMoveReply> go(GoParameters options) {
public BestMoveReply get() {
final UCIEngineSearchConfiguration<M, B> c = new UCIEngineSearchConfiguration<>(timeManager);
final UCIEngineSearchConfiguration.EngineConfiguration previous = c.configure(engine, options, board);
//FIXME searchmoves is ignored
final M move = engine.apply(board);
final List<M> candidates = options.getMoveToSearch().stream().map(AbstractEngine.this::toMove).toList();
final M move = engine.getBestMove(board, candidates.isEmpty() ? null : candidates);
c.set(engine, previous);
return new BestMoveReply(toUCI(move));
return new BestMoveReply(move==null ? null : toUCI(move));
}

@Override
Expand Down

0 comments on commit bdbec51

Please sign in to comment.