
In Linux and many other systems, there is a command line utility
sed (“Sed”) - this is an uncomplicated editor that converts text that gets into it with simple commands.
It is mainly used for all small needs in
bash scripts - replace one line with another, delete something, and so on. Speaking in terms of more familiar languages, two string variables are available in Sedo, in one of which you can check, replace, and only exchange data from the first, tags, jump instructions and grouping commands, plus a few more. less useful directives.
It was on this disgrace that I decided to write chess, moreover, such that I could play with the computer.
In general, this is not the first game on the "Sed", there is, for example,
Tetris and
Arkanoid , but my game seems to have bypassed them in size and intelligence.
')
I have long wanted to know “SED” better, but somehow there was no reason, so I decided to write something more significant on it than the script replacing one line with another. Unfortunately, the lack of all existing hitherto games on the “Sed” is that they need considerable scripting (which obscures the purity of the idea) due to one unpleasant feature - “Sed”, before doing something, it waits for the input key to be pressed.
Therefore, when I thought about what to write, I chose chess - a step-by-step game, where each team has to confirm the input. Honestly, I did not imagine what I condemn myself for. In the end (and I wrote the game for about two weeks, albeit with gigantic interruptions), I tried to quit this activity a couple of times.
The most difficult thing was with numbers - how to subtract them, add, compare, if there is no arithmetic in the “gray” at all? We had to invent our own format for storing numbers, for example, “111 :: 11” means 302 (the number is encoded by the number of ones, dozens are separated by a colon), all the math above these numbers is done using a set of regular expressions and transitions between them.
Here is a piece of subtraction logic (the entire function takes 59 lines):

Almost immediately, I came up with the idea of merging primitives into some sort of high-level commands and storing a stack of such commands next to the data (there is nowhere else). Studied on the way, if you look at the commits, you can see some finds that then crawl away all over the code.
I must immediately warn you - the game is noticeably slow, on my “MacBook Pro” (2.9 GHz, Intel Ay7) the response to “e2 e4” is calculated 6.3 seconds. However, chess teaches patience, so this should not be a hindrance.
Of the restrictions that I set myself - do not use the
GNU sed extensions and extended regular expressions.
So what happened?
The positional evaluation and evaluation of the presence of pieces on the board are programmed (the evaluation algorithms are taken from the book Programming Chess and Other Logic Games by Kornilov Evgeny Nikolaevich), the search of moves (there is no nesting, only the closest move is moved), the check of the check and the mat that reached the end of the board is a pawn converted to a queen.
There is no detection of a stalemate (the hands did not reach, although it is easy to do) and the game, in fact, is conducted according to the rules of the XIV century - there is no castling and taking on the aisle, leaving the check is primitive. Also, I did not control the correctness of a person’s move, so if you want to assert yourself at the expense of a defenseless machine, you can immediately hack the king.
You can download the game from the
project on Github , there is also a small instruction how to play. About bugs, if you will, write in a comment or lichku, but when I correct - I do not know, after a thousand lines on the “gray” I need a break.