TL;DR

A programmer has built a chess engine that plays using a sequence of 84,688 regular expressions. This demonstrates a creative, if impractical, method of implementing game logic with regex. The development raises questions about the boundaries of regex and computational creativity.

A developer has constructed a chess engine that operates entirely through a sequence of 84,688 regular expressions, effectively playing a 2-ply minimax game. This project, shared via a blog post and GitHub, demonstrates an unconventional use of regex for game logic, highlighting both technical curiosity and computational creativity.

The developer created a list of 84,688 regular expressions that, when executed sequentially, interpret and modify a chess board state represented as a string. The approach involves designing a custom instruction set encoded within regex patterns, effectively turning regex into a simple CPU capable of running a minimax algorithm for move selection. The implementation is intentionally minimalistic and experimental, not optimized for performance or practical use.

The project was shared publicly on GitHub, with the developer emphasizing that the primary goal was to explore the theoretical boundaries of regex as a computational tool, rather than creating a competitive chess engine. The code interprets a chessboard string and applies regex transformations to simulate move generation and evaluation, culminating in a move decision based on a 2-ply minimax search.

Why It Matters

This project pushes the boundaries of what is considered feasible with regular expressions, a tool typically used for pattern matching rather than computation. You can see a chess puzzle I found in my dad’s old book as an example of strategic thinking. It highlights how regex can be repurposed for Turing-complete tasks in highly contrived scenarios, sparking discussions about the limits of pattern-based programming and creative problem-solving. While impractical for real chess engines, it serves as a proof of concept and a thought experiment about computational universality.

Amazon

regular expression chess engine

As an affiliate, we earn on qualifying purchases.

As an affiliate, we earn on qualifying purchases.

Background

Traditional chess engines rely on complex algorithms, heuristics, and optimized data structures to evaluate positions and generate moves. This project diverges radically by encoding game logic within regex patterns, a method inspired by the idea of a regex-based computer. The concept was shared over the holidays, building on previous experiments with unconventional computation, such as cellular automata and custom CPUs built from simple instruction sets. You might find this chess puzzle I found in my dad’s old book interesting for understanding complex game logic.

The developer described the process as a playful exploration rather than a serious attempt at chess AI, emphasizing the novelty of using regex as a programming paradigm. For more on chess strategies, see this chess puzzle I found in my dad’s old book. Prior to this, regex has been shown to be Turing-complete in theory, but practical applications are rare and usually limited to pattern matching tasks. For a deep dive into complex problem-solving, see this chess puzzle I found in my dad’s old book.

“This sequence of regular expressions demonstrates that you can, in fact, use regex as a computational engine for something as complex as chess.”

— Developer

“The goal was to see if regex could interpret and execute a simple minimax algorithm, and the answer is yes — with a lot of regexes.”

— GitHub post

Competitive Programming 4 - Book 1: The Lower Bound of Programming Contests in the 2020s

Competitive Programming 4 – Book 1: The Lower Bound of Programming Contests in the 2020s

As an affiliate, we earn on qualifying purchases.

As an affiliate, we earn on qualifying purchases.

What Remains Unclear

It is not yet clear how well this regex-based engine performs in terms of move quality or speed. The project is primarily a proof of concept rather than a practical chess engine, and its scalability or adaptability to more complex scenarios remains untested.

Chess: 5334 Problems, Combinations and Games

Chess: 5334 Problems, Combinations and Games

Used Book in Good Condition

As an affiliate, we earn on qualifying purchases.

As an affiliate, we earn on qualifying purchases.

What’s Next

Further exploration may involve optimizing the regex sequence, testing the engine against other chess programs, or extending the approach to deeper search depths. The developer may also publish more detailed technical insights or experiment with other games and computational tasks using regex as a core tool.

50 Algorithms Every Programmer Should Know: Tackle computer science challenges with classic to modern algorithms in machine learning, software design, data systems, and cryptography

50 Algorithms Every Programmer Should Know: Tackle computer science challenges with classic to modern algorithms in machine learning, software design, data systems, and cryptography

As an affiliate, we earn on qualifying purchases.

As an affiliate, we earn on qualifying purchases.

Key Questions

Is this regex chess engine practical for playing real games?

No, this project is primarily a proof of concept demonstrating how regex can be used for computation, not a practical chess engine.

How does the engine evaluate moves?

It uses a sequence of regex transformations to simulate a 2-ply minimax algorithm, interpreting a string representation of the chessboard and applying move logic encoded as regex patterns.

Can this method be scaled to deeper search depths?

Currently, it is highly impractical due to the enormous number of regex patterns required; scaling would require significant re-engineering and likely surpass reasonable computational limits.

Why use regex for such a task?

The developer aimed to explore the theoretical limits of regex as a universal computational tool, rather than seeking efficiency or practicality.

Source: Hacker News

You May Also Like

Mounting git commits as folders with NFS (2023)

A developer has created a tool to mount git commits as folders via NFS on Mac, making exploring repository history more filesystem-native. The project is experimental but innovative.

Why Digital Proofing Is Becoming Essential for Fine Art Printing

Digital proofing is becoming essential in fine art printing because it helps…

Virtual Art Galleries: The Future of Exhibition

Many believe virtual art galleries will revolutionize exhibitions, but how exactly will they reshape your art experience?

Jay Forrester filed the first practical computer RAM patent 75 years ago this week — his Magnetic Core Memory patent would be granted five years later

Celebrating 75 years since Jay Forrester filed the first practical computer RAM patent, a milestone that shaped modern digital computing and memory technology.