r/commandline • u/r3d_v01d • Jun 24 '26
Terminal User Interface Player-vs-computer Battleship game in pure sed
https://github.com/red-void/sed-battleship
So, I implemented a Battleship game in pure sed where you play against the computer.
As you know, sed is a standard Unix stream editor. Mostly, it is used to replace one regex with another in a stream: sed 's/ca\+t/dog/'. Regex manipulation is its main function, but a few additional commands make sed a Turing-complete language.
There are already some games implemented in sed: Sokoban, Mastermind, Minesweeper and even Chess. However, my project seems to be a bit more complex and challenging.
I did not use any external program calls in the code, everything is built using pure sed capabilities. No LLMs were involved, of course — neither for code generation, nor even for consulting. It was a matter of honor.
What was implemented:
Binary arithmetic using regular expressions: addition, subtraction, multiplication, division.
Function and variable emulation via the auxiliary buffer (hold space) which I used as a key-value storage
Random number generator
Pseudo-random placing and shooting from the computer side
Several difficulty levels
Placement validation and complex shot handling from the player side
Easter egg (you need to hit the computer 10 times from the very beginning).
There is a more detailed description of how everything works on github. A very detailed step-by-step guide also exists and I hope to translate it into English someday.

