CLI

From Chessprogramming wiki
Jump to: navigation, search

Home * User Interface * Command Line Interface

Command Line Interface (CLI),
a means of a user, agent or client, interacting with a computer program in form of plain text- or command lines. Programs are either the operating system, their command-line shells, or application software, for instance chess programs.

History

The CLI has its origins in teletype and later computer terminals to act as a system console and sequential input- and output device, where the program prompts for input, that is, prints a message or symbol on the teletype printer to indicate readiness for user input, and acts upon command lines as they are entered.

Unix Philosophy

Unix and its composable design and philosophy originated by Ken Thompson was summarized by Doug McIlroy, contributor to Unix pipes [1]: Write programs that do one thing and do it well. Write programs to work together. Write programs to handle text streams, because that is a universal interface.

Shell and Applications

Operating systems such as MS-DOS, Unix or Linux per default provide a shell as CLI, such as Command.com or Unix shell. Modern desktop versions of Windows use the Windows shell which is a graphical user interface, but include a command prompt window for console applications. Most operating systems support inter-process communication with standard streams or named pipes and are able to redirect standard streams from and to other processes. Command line interfaces are therefor often preferred by advanced users or software developers, as they provide a more concise and powerful way to control a program or operating system, and are generally easier to automate via scripting [2].

Commands

Text commands as entered via the keyboard, are a sequence of ASCII- or Unicode characters finally confirmed and send to the programs standard input by typing the Enter key, which is typically encoded at the end of the command string as newline character ("\n") (Posix) or a sequence of carriage return ("\r") and newline under Windows [3]. Syntax and semantics of commands and their required or optional arguments depend on the OS or application of course, its state or mode. When the command is parsed, interpreted and executed, acknowledgments, results or answers are send back for a communication according to a protocol.

CLI and Chess Engines

Most current chess engines are implemented as console application to communicate via a command line interface. This is the most portable way, supported by all common operating systems, programming languages and their standard libraries. A proprietary chess engine interface for direct console play may be implemented by printing an ASCII-board and the game record, and prompting for a move or command, also streaming the iterative "thinking process", i.e. formatted text lines with score, depth, and principal variation to the console.

Interruptible

Pondering and the need to enter moves and commands even if the program is "thinking", requires an interruptible search routine. In single tasking operating systems like MS-DOS, engines often used coroutines to implement internal context switching between search and user interaction. Today, it is more common to rely on multithreading abilities of modern operating systems, and to use an explicit I/O-thread, while the search routine is regularly pondering whether it needs to be interrupted by pending input received by another thread, with the option to asynchronously stop the search.

Protocols

The UNIX paradigm was further archetype of both primary protocols in computer chess, to communicate with a GUI or game playing controller or server - the Chess Engine Communication Protocol, and UCI. In conformance with these chess communication protocols, engines standard streams are redirected and controlled by a parent process such as the chess GUI, a game- or match controller like Cutechess-cli for automatic engine-engine matches [4], or their proxies inside a computer network.

Chess CLIs

See also

Forum Posts

External Links

References