-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
uci option to toggle opening book usage
- Loading branch information
1 parent
6fb539e
commit d1e14f5
Showing
7 changed files
with
86 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace SicTransit.Woodpusher.Common | ||
{ | ||
public class EngineOptions | ||
{ | ||
public bool UseOpeningBook { get; set; } = false; | ||
|
||
public static EngineOptions Default => new(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,8 +5,12 @@ A more or less UCI-compatible chess engine. Plug it into your favourite GUI. | |
|
||
## Features | ||
- UCI-compatible | ||
- PGN and FEN parsing | ||
- Perft test | ||
- Opening book | ||
- Zobrist hashing | ||
- Transposition table | ||
- Killer heuristic | ||
|
||
## UCI Commands | ||
|
||
|
@@ -19,11 +23,25 @@ Initializes the engine and provides engine information. | |
**Example:** | ||
``` | ||
uci | ||
id name Woodpusher 1.0.0+169dfebfdb4749ad97aabcbd779ec507f051ad72 | ||
id name Woodpusher 1.2.0+17b3326627bad1b95724019c2ab68eb6041c4409 | ||
id author Mikael Fredriksson <[email protected]> | ||
option name OwnBook type check default true | ||
uciok | ||
``` | ||
|
||
### `setoption` | ||
|
||
Sets an engine option. | ||
|
||
**Arguments:** | ||
- `name <option_name>`: The name of the option. | ||
- `value <option_value>`: The value of the option. | ||
|
||
**Example:** | ||
``` | ||
setoption name OwnBook value false | ||
``` | ||
|
||
### `isready` | ||
Checks if the engine is ready. | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
using Serilog; | ||
using SicTransit.Woodpusher.Common; | ||
using SicTransit.Woodpusher.Common.Extensions; | ||
using SicTransit.Woodpusher.Common.Interfaces; | ||
using SicTransit.Woodpusher.Common.Parsing; | ||
|
@@ -22,6 +23,7 @@ public class UniversalChessInterface | |
private static readonly Regex PositionCommand = new(@"^position", RegexOptions.Compiled); | ||
private static readonly Regex GoCommand = new(@"^go", RegexOptions.Compiled); | ||
private static readonly Regex DisplayCommand = new(@"^d$", RegexOptions.Compiled); | ||
private static readonly Regex SetOptionCommand = new(@"^setoption", RegexOptions.Compiled); | ||
|
||
|
||
private static readonly Regex PositionRegex = | ||
|
@@ -32,11 +34,14 @@ public class UniversalChessInterface | |
private static readonly Regex MovesToGoRegex = new(@"movestogo (\d+)", RegexOptions.Compiled); | ||
private static readonly Regex MovetimeRegex = new(@"movetime (\d+)", RegexOptions.Compiled); | ||
private static readonly Regex PerftRegex = new(@"perft (\d+)", RegexOptions.Compiled); | ||
private static readonly Regex OptionRegex = new(@"^setoption name (\w+) value (\w+)$", RegexOptions.Compiled); | ||
|
||
private const int engineLatency = 100; | ||
|
||
private readonly IEngine engine; | ||
|
||
private EngineOptions options = EngineOptions.Default; | ||
|
||
public UniversalChessInterface(Action<string> consoleOutput, IEngine engine) | ||
{ | ||
this.consoleOutput = consoleOutput; | ||
|
@@ -75,6 +80,10 @@ public void ProcessCommand(string command) | |
{ | ||
task = Display(); | ||
} | ||
else if (SetOptionCommand.IsMatch(command)) | ||
{ | ||
task = SetOption(command); | ||
} | ||
else if (QuitCommand.IsMatch(command)) | ||
{ | ||
Quit = true; | ||
|
@@ -107,6 +116,7 @@ private Task Uci() | |
|
||
consoleOutput($"id name Woodpusher {version}"); | ||
consoleOutput("id author Mikael Fredriksson <[email protected]>"); | ||
consoleOutput("option name OwnBook type check default true"); | ||
consoleOutput("uciok"); | ||
} | ||
}); | ||
|
@@ -118,7 +128,7 @@ private Task Initialize() | |
{ | ||
lock (engine) | ||
{ | ||
engine.Initialize(); | ||
engine.Initialize(options); | ||
} | ||
}); | ||
} | ||
|
@@ -142,6 +152,25 @@ private Task Stop() | |
}); | ||
} | ||
|
||
private Task SetOption(string command) | ||
{ | ||
return Task.Run(() => | ||
{ | ||
var match = OptionRegex.Match(command); | ||
if (!match.Success) | ||
{ | ||
Log.Error("Unable to parse: {Command}", command); | ||
return; | ||
} | ||
var name = match.Groups[1].Value; | ||
var value = match.Groups[2].Value; | ||
if (name == "OwnBook") | ||
{ | ||
options.UseOpeningBook = bool.Parse(value); | ||
} | ||
}); | ||
} | ||
|
||
private Task Position(string command) | ||
{ | ||
return Task.Run(() => | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
<Nullable>enable</Nullable> | ||
<RootNamespace>SicTransit.Woodpusher</RootNamespace> | ||
<Authors>Mikael Fredriksson <[email protected]></Authors> | ||
<Version>1.1.0</Version> | ||
<Version>1.2.0</Version> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
|