This is delightfully insane! I don't think I would say it doesn't play _entirely_ terrible though ;) It's playing really bad, but it could be worse and it's already super impressive that it can even generate legal moves.
Depends on what you mean by that. You can convert every NFA into a DFA. That's a NP complete (IIRC), but running the DFA is O(n). Running the NFA without converting it is also NP complete. One isn't better than the other, but the costs vary for different expressions and usages.
It would be different, if somehow all those 84688 regexes were coded by hand. Then it would be a piece of art.
It would be different, if the number of regexes was maybe below 300, and it still plays acceptably. The sheer number of regexes kind of defeats the purpose.
At that code size, a much better engine can be written, or other kind of code for an engine be generated. Regexes themselves are not really something we should strive to use more either. Maybe its intentional badness kind of makes it art?
Oh, I didn't mean that this specific project wouldn't work. I just wish HN were a little friendlier towards projects that are primarily thought experiments.
Some of the best things I've ever created started from, "I wonder what would happen if I tried this crazy approach..."
> Maybe its intentional badness kind of makes it art?
I guess it's the whole point of such type of blog posts. Similarly, some people write complicated interactive web pages without using JS, like this https://benjaminaster.com/css-minecraft/. But if you look at the HTML / CSS code size, it's usually huge, but still requires creativity to do that because of constraints. Obviously, it's not something practical or even optimal.
> There are people who navigate the web with JavaScript turned off, so those experiments do have practical applications.
This is practical (and necessary) for relatively basic stuff, such as text content, navigation, basic form / input validation, and things like that. But when people write more complicated things (requiring state management, logical branches, etc), like games, 3d programs, etc, it's much more challenging (also can be sub-optimal) and requires more creativity. I mean they are more of a demo art rather than some strong necessity.
You completely missed the point of the article. It's the equivalent of compiling C++ to a Turing machine. Not practical, not optimum, but freaking amazing. Maybe think about it as an art project.
The technical write up is worth perusing but I played a game before reading and accidentally found a winning strategy immediately. I'm not sure if this is a result of the 2-ply nature of the engine or if the mentioned deficiencies account for this but the computer did not act to prevent checkmate in 1 (without any intervening check); the game I played was (in algebraic notation):
1. e4 e5
2. kf3 kf6
3. kxe5 kxe4
4. d4 kxf2
5. Kxf2 a5
6. Qf3 b5??
7. Qxf7
1-0
(In terms of Regexes, Javascript has a very rich Turing complete Regex library; it’s an open question whether Lua 5.1’s regexes are Turing complete, but they are good enough for the text processing I do)
I won with 1. e4 e5 2. Qh5 a6 3.Bc4 a5 4. Qxf7#. I wonder if you could implement a stronger engine in regex (stockfish classic at O(1) nodes is plenty strong already)
This reminded me of Tom7's video where he made a bunch of ridiculous engines and pitted them against each other (and against "diluted" versions of Stockfish):
You've mentioned that the initial version needs 30 mins for a step, but after the optimization, it decreases to seconds. I was wondering what optimization like \n could give such a huge improvement? Like what does it do?
Upon reading the title, this is one of those "I know that's possible, but I'd never bother to implement it" things, although this particular implementation isn't exactly what I had in mind.
Not sure it's completely accurate. I played a standard queen's gambit accepted, took black's queen which it immediately blundered, then tried to move my queen from c5 -> e5 and the game ended immediately showing:
*Illegal Move*
You Lose.
Game over.
A little disappointed, since it's of course a valid move.
It’s very picky about how you specify a move. “e2e4” is fine as a first move, for example, but auto-capitalized “E2e4” is losing immediately. Quite weird, given that there are guardrails against “e2-e4” and “E2-E4” (an alert pops up telling you how to write moves)
It's not just regex. The regular expressions are used to select and perform an action. There's a loop around it with controls the stack. That has more power than the regex.
It’s turing complete so you could compile almost any language to regex. You might have to build a vm for some languages, also in regex. The point is, it’s regex all the way down.
Javascript/PCRE/etc regexes have additional features (like backreferences) that give them strictly more computational power than a regular DFA/NFA. (Still not Turing complete though without external control flow to support arbitrary iteration/recursion, like is done here)
This is an odd comment because it's a famously (imo) over known fact due to cs textbooks and how academia organizes knowledge, optimizing for pushing papers over genuine discovery.
reply