Get the latest tech news

A minimax chess engine in regular expressions


I wrote a (list of) regular expressions that will play a (not very good) chess game by running a 2-ply minimax search.

(If you're someone who subscribed to this blog in the last six months or so, and have gotten accustom to me writing about "serious" and "important" things, please treat this as your fair warning that this is MY WEBSITE and I MAKE THE RULES HERE and so today you're learning about RegexChess whether you like it or not.) How to parallelize move generation for sliding pieces like bishops, rooks, and queens all at exactly the same time How castling is implemented with a specialized "is this square under attack" procedures Conversion to and from the FEN chess board to one has a single variable per square Detection of castling rights by tracking the king and rook positions The implementation of en passant capture detection and tracking An extensive 2000 lines of tests, validating the correctness of the engine over several thousand games By requiring the preceding newline and "#stack:\n" prefix in our pattern, we ensure the regex engine can quickly skip over all the True/False strings that appear in variable names or values.

Get the Android app

Or read this on Hacker News

Read more on:

Photo of chess

chess

Photo of regular expressions

regular expressions

Related news:

News photo

OpenAI's o1-preview model manipulates game files to force a win against Stockfish in chess

News photo

Chess: Magnus Carlsen disqualified in N.Y. after refusing to change out of jeans

News photo

Regular Expressions which query an Oracle