0

I'm starting to work on a chess engine and I want to follow the uci interface where comunication is done using plane text. In the specification it says

all communication is done via standard input and output with text commands

but I dont know what this means in real terms.

I'm thinking of writing in C# as a .net standard library. I understand that as uci is cross platform we cannot talk in language like Console.WriteLine but what does that line in the api mean for me.

Do I have to run a loop listening for Console.ReadLine() or something similar for standard input? I just don't get it. Or should I be writing a console application that takes the input as a command line argument, and writes string to the console?

The full specification can be downloaded from this link: http://download.shredderchess.com/div/uci.zip

G Aker
  • 109
  • 4
  • Hi the specification can be dowloaded from here http://download.shredderchess.com/div/uci.zip – G Aker Nov 11 '20 at 13:33
  • Does this answer your question? [Confused about stdin, stdout and stderr?](https://stackoverflow.com/questions/3385201/confused-about-stdin-stdout-and-stderr) – Alejandro Nov 11 '20 at 13:38
  • Did you consider looking at the documentation for [`Console.WriteLine`](https://learn.microsoft.com/en-us/dotnet/api/system.console.writeline?view=net-5.0): "Writes the specified data, followed by the current line terminator, to the **standard output** stream." – Damien_The_Unbeliever Nov 11 '20 at 13:41
  • [Here](https://chess.stackexchange.com/q/4138) is relevant question on chess, quote from answer: "It's actually very straight forward and simple, a UCI engine must respond to and reply in plain text through stdin, stdout and stderr." so yes, you could use `Console` methods. – Sinatr Nov 11 '20 at 13:41

1 Answers1

0

Any process have three default streams:

  • Standard input (stdin): This is the only input stream for all terminal or console aps. When you cal Console.ReadLine or Console.Read the result is taken from this stream.
  • Standard Output (stdout): When you call output-related commands in the console singleton class, all data goes here. For example the WriteLine or theWrite methods. The color and beeps commands send data to there too.
  • Standard error (stderr): This is a dedicated stream to print error-related content to the console. This is dedicated because some applications and scripting solutions want to hide these messages.

You can communicate with the containing process (such a console prompt) with these streams. The command line arguments can be passed only to the program's main method.

Christopher Moore
  • 15,626
  • 10
  • 42
  • 52
Fran
  • 181
  • 8
  • Ok this kind of makes sense, but I want to check something? The engine I'm writing will be a console application so I can run it on it's own and manually input instructions through the terminal and it will respond. But the reason I am following uci is so i can run it in a 3rd party gui, which will presumably not use the console. So behind the scenes is the gui setting a different value for standard input and output? If so how does this work? – G Aker Nov 11 '20 at 13:52
  • The GUI program sends it's commands to your program's stdin and reads your program's standard output and reacts accordingly. You don't have to do anything, just respond to the data coming from the stdin to the stdout. – Fran Nov 12 '20 at 14:19