Live data from Hacker News

A minimax chess engine in regular expressions

nicholas.carlini.com

81–90 of 103 posts

Re: A minimax chess engine in regular expressions

#84
post #30

That's some impressive code wizardry! I thought the 2-ply search would make it respond to a mate-in-1 threat, but the following game demonstrates otherwise: 1. e4 e5 2. Nf3 Nf6 3. Nxe5 Nxe4 4. Qe2 Nxd2 5. Nc6+ Ne4 6. Qxe4+ Qe7 7. Nxe7 Bxe7 8. Nc3 a5 9. Nd5 a4 10. Qxe7# 9. .., Nc6/O-O/Kf8 would have avoided mate in 1. Maybe this is related to the a2-a4 bug noticed by others?!

Apparently it's more of a 1.75ply search according to the author :)

Try: c4, Qa4, Qxa5, Qc7, Qxc8# lol

Re: A minimax chess engine in regular expressions

#85

This is truly impressive, I'm in complete awe. I do think there are some bugs based on playing a game against it. It has a tendency to give up its queen and other pieces. and it blundered mate in 1 at the end of the game when it had moves that led to mate in 2 or 3. Usually even a 2-ply engine should avoid these mistakes unless the evaluation function is completely silly, which may be the case here, I don't know. I t…

My tester could trounce a 2-ply minimax engine easily. At 6 plies with the alpha-beta optimization it beat my tester for the first time (beats the average person, gets wrecked at the chess club but is trying to change that) which frustrated him greatly but after he spent a day thinking about strategy he prevailed. (Without alpha-beta the 6 ply search would have been completely unreasonable) I got the signs wrong and…

Yeah, a 2-ply engine is pretty terrible at chess. Especially with no quiescence search.

I know what you're describing well, I've dabbled quite a bit in chess engine dev myself, and I'm planning to get back into it soon; I've got some interesting new ideas recently I wanna try out(once they're fleshed out enough to actually be implemented, right now they're just fanciful ideas I'm kicking around my head).

Testing is a bitch though, for sure. I know that stockfish is constantly being playtasted against itself, with a new instance spawned for every pull request etc, and then given an elo rating. That way they can tell if a potential change makes it weaker or stronger.

Debugging isn't easy either. Forget about stepping over code in the debugger. You have no idea whether the bug is only triggered after billions of nodes. That's a lot of stack frames to step through. And forget about debug prints too, for the most part, because putting an unconditional debug print in your search() , qsearch() or eval() will quickly lead to gigabytes and gigabytes of output...

Only helpful thing I found was to use asserts. Find invariants, and in your debug version check them every node, die if they don't hold and barf out your stack frame or a core dump. If you're lucky the bug is somewhere near where the assert failed in the call tree. Even that isn't guaranteed though.

Re: A minimax chess engine in regular expressions

#86
post #83

It does seem to play worse than it should, by game went: 1. d4 d5 2. c4 dxc4 3. e4 Qxd4 4. Qxd4 5. Bc4 6. Nf3 7. O-O 8. Rd1 9. Qd8#

Oh no dude, it's worse than that: c4, Qa4, Qxa5, Qc7, Qxc8# lol

Nice find. I tried to get an even shorter mate, but its tendency to give up its pieces got in the way: 1. e4 e5 2. Bc4 Bc5 3. Qh5 Bxf2+ 4. Ke2 Bxg1 5. Qxf7#

Can anyone get a mate in 4?

Re: A minimax chess engine in regular expressions

#87
post #86
post #83

Earlier quoted context omitted.

Oh no dude, it's worse than that: c4, Qa4, Qxa5, Qc7, Qxc8# lol

Nice find. I tried to get an even shorter mate, but its tendency to give up its pieces got in the way: 1. e4 e5 2. Bc4 Bc5 3. Qh5 Bxf2+ 4. Ke2 Bxg1 5. Qxf7# Can anyone get a mate in 4?

Oh, that was easier than expected: 1. e4 e5 2. Qh5 a6 3. Bc4 a5 4. Qxf7# I assume a mate in 3 (or a Fool's mate in 2) is not possible...

Re: A minimax chess engine in regular expressions

#88
post #49

Earlier quoted context omitted.

Apparently it takes more than skill but also persistence and concentration. Not many schools of thought explain this well .

No, it takes (1) knowing what you learn in a compilers class (or upper level math classes) and (2) putting it to work. He didn't write 80,000 regular expressions, he wrote a compiler that wrote those expressions. Commercial-quality compilers are hard to write but simple compilers are straightforward if you know the fundamentals. It's like the problem of solving the Rubik's cube. If you look at it in terms of geometry…

Okay, as you wish.

Though I've never seen people accomplish stuff like a) understand regex; and b) write a compiler for it without "persistence and concentration.". Perhaps some get it delivered through divine apparition of some kind.

What is it that really triggered your lengthy response and the narrative..., I really fail to understand, sorry.

Re: A minimax chess engine in regular expressions

#89

This is from the same gentleman who (among other things) demonstrated that printf() is Turing complete and wrote a first person shooter in 13kB of Javascript. https://github.com/HexHive/printbf https://github.com/carlini/js13k2019-yet-another-doom-clone

The development writeup for the Doom is interesting, with many details. https://nicholas.carlini.com/writing/2019/javascript-doom-cl... There was one month time to complete the competition. But it seems you were allowed to reuse any existing other code. Looks like this was quite fun to work on. (I feel a bit sad that I would never be able to get one month of free time to work on this now, due to family and job...)

Wow that’s a fascinating read, thanks for linking it!!

Re: A minimax chess engine in regular expressions

#90

This is from the same gentleman who (among other things) demonstrated that printf() is Turing complete and wrote a first person shooter in 13kB of Javascript. https://github.com/HexHive/printbf https://github.com/carlini/js13k2019-yet-another-doom-clone

> a first person shooter in 13kB of Javascript I was somewhat disappointed to realize they used WebGL for rendering the graphics.

Why is this disappointing?
Post reply on HN