Skip to content

Commit

Permalink
Parse cli arguments and use them as UCI commands (#370)
Browse files Browse the repository at this point in the history
Parse cli arguments and feed them to the engine as if they were uci commands.
This allows to easily do:

```bash
dotnet run -c Release "position fen rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1" "perft 5"

dotnet run -c Release "position startpos" "go depth 6"

./Lynx.Cli.exe bench

# etc.
```

There's a catch: you can't pass "exit" to terminate the execution at the end since `LynxDriver` reads the commands asynchronously in case a `stop` (or 'quit') are requested by GUIs, so that would happen immediately.
So can't really create an action with this
  • Loading branch information
eduherminio authored Aug 21, 2023
1 parent ae56e95 commit f97e38c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
7 changes: 6 additions & 1 deletion src/Lynx.Cli/Listener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,15 @@ public Listener(Channel<string> guiInputReader)
_logger = LogManager.GetCurrentClassLogger();
}

public async Task Run(CancellationToken cancellationToken)
public async Task Run(CancellationToken cancellationToken, params string[] args)
{
try
{
foreach (var arg in args)
{
await _guiInputReader.Writer.WriteAsync(arg, cancellationToken);
}

while (!cancellationToken.IsCancellationRequested)
{
var input = Console.ReadLine();
Expand Down
6 changes: 1 addition & 5 deletions src/Lynx.Cli/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,13 @@
{
new Writer(engineChannel).Run(cancellationToken),
new LynxDriver(uciChannel, engineChannel, new Engine(engineChannel)).Run(cancellationToken),
new Listener(uciChannel).Run(cancellationToken),
new Listener(uciChannel).Run(cancellationToken, args),
uciChannel.Reader.Completion,
engineChannel.Reader.Completion
};

try
{
if (args.Length > 0 && args[0] == "bench")
{
await uciChannel.Writer.WriteAsync("bench");
}
await Task.WhenAny(tasks);
}
catch (AggregateException ae)
Expand Down

0 comments on commit f97e38c

Please sign in to comment.