The Regex Engine as a Graphics Card
Imagine rendering a frame of Doom, the iconic 1993 first-person shooter, not with pixels and shaders, but with text substitutions. That's precisely what a programmer, known online as 'Byte[]', has achieved. This isn't a port in the traditional sense; it's an audacious experiment in computational abstraction. The entire game engine, including its video output, has been re-implemented using only regular expressions. The result is, predictably, glacial: 180 seconds per frame.
The core idea hinges on treating regular expressions as a Turing-complete programming language. By carefully crafting a single, massive text string that contains the entire game's logic and output instructions, Byte[] uses the regex engine to interpret and execute it. Each frame requires nearly 14 million substitutions, processed at a rate of approximately 80,000 substitutions per second. This is less about playing Doom and more about a profound exploration of what can be computed with the most unlikely tools.
The analogy provided by the coder, 'correspondence chess with a shotgun,' is particularly apt. Correspondence chess involves long deliberation times between moves, much like the extended rendering time per frame here. The 'shotgun' element speaks to the brute-force, almost violent, application of a tool (regex substitutions) far beyond its intended purpose to achieve a complex outcome.
From C Code to Text Patterns
The original Doom engine is written in C. To translate this into a regex-based system, Byte[] effectively created a domain-specific language where game states, rendering commands, and even the machine's virtual output are represented as text patterns. When the regex engine processes this master string, it performs substitutions that, in essence, simulate the execution of game logic and the drawing of each frame. This means that every action, from player movement to enemy AI, is being calculated through the application and re-application of text patterns.
Consider the complexity: a single frame of Doom involves calculating visibility, drawing walls, sprites, and the skybox, all while handling player input and game logic updates. To achieve this with regex means that each of these operations must be encoded as a pattern. For instance, a pattern might be designed to find a certain arrangement of characters representing a wall segment and substitute it with another pattern representing its rendered appearance on screen. This process is repeated millions of times for every single frame.

The sheer volume of substitutions is staggering. If a typical frame in modern games renders at 60 frames per second, and each frame takes 180 seconds here, the performance difference is astronomical. This project doesn't aim for playable frame rates; its goal is to demonstrate the expressive power of regular expressions and the surprising computational capabilities that can be unlocked by pushing them to their absolute limits. It's a proof-of-concept that blurs the lines between text processing and general-purpose computation.
The 'Why' Behind the Absurdity
Why undertake such a monumental and impractical task? For Byte[], it appears to be a deep dive into the nature of computation and the expressive power of tools we often take for granted. Regular expressions are ubiquitous in programming for pattern matching and text manipulation. They are typically used for tasks like log analysis, data validation, or simple text replacement. Using them as the sole engine for a 3D game engine is an extreme form of computational archaeology, stripping away conventional programming paradigms to see what fundamental computing primitives can achieve.
This project also touches on the concept of 'esoteric programming languages.' While regex isn't typically classified as such, its application here places it in a similar category of tools used for intellectual exploration rather than practical software development. It forces a re-evaluation of what constitutes a 'computable' process and how different computational models can be mapped onto one another. The challenge lies in encoding complex algorithms, like those found in a game engine, into the specific syntax and operational semantics of regular expressions.
The performance bottleneck, 180 seconds per frame, is a direct consequence of the regex engine's design. Regex engines are optimized for finding patterns, not for the kind of stateful, iterative calculations required by a game loop. Each substitution is a discrete operation, and chaining millions of them to simulate a single graphical update is inherently inefficient. However, the achievement is not in speed, but in the successful realization of the concept itself.
Implications and Future Questions
While this project will not lead to a new generation of regex-based game engines, it offers valuable insights. It highlights the surprising universality of computational models. If a task as complex as rendering Doom can be simulated with regex substitutions, it suggests that many computational problems can, in theory, be expressed in vastly different forms, even if the practical performance is abysmal.
What remains unanswered is the precise methodology Byte[] employed to translate the C code's mathematical operations, memory management, and rendering pipeline into a series of text patterns. Reverse-engineering or re-implementing a complex C codebase into a regex dialect is a non-trivial undertaking, requiring a deep understanding of both the original game's architecture and the nuances of regex engine behavior. The specific choice of regex engine and its particular feature set would also play a crucial role in what is possible.
This endeavor serves as a testament to human ingenuity and the endless pursuit of exploring computational boundaries. It's a fascinating, if impractical, demonstration of how far one can push a single, powerful tool beyond its intended scope.
