Earlier quoted context omitted.
[flagged]
I'm not sure how this quote applies to harmless pursuits like making and solving absurd puzzles. It's not like regex chess is going to be a weapon of mass destruction.
A minimax chess engine in regular expressions
31–40 of 103 posts
Re: A minimax chess engine in regular expressions
#32 (%%)([^`]\n?#stack:\n)
This should have just been written like the following (which in fact eq() does do, though eq() is itself missing the %%` -> %% regex): (%%)(\n#stack:\n)
As it is the [^`] matches the newline, which is why the \n has to be marked as optional and in practice will always be skipped.Re: A minimax chess engine in regular expressions
#33This 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
> demonstrated that printf() is Turing complete and wrote a first person shooter in ... Not gonna lie, I thought that sentence would end with the FPS being done in printf.
Re: A minimax chess engine in regular expressions
#34I want to share this quick win.
The other day I was asking myself some theoretical chess questions, and wanted to answer them programmatically and needed to build some custom chess datasets for that.
I needed the chess basic routines, like getting the next legal moves, displaying the board, and some rudimentary position scores. I contemplated writing from scratch. I contemplated using some library. But instead I settled for a higher level choice : interfacing with Stockfish game engine over a text interface.
There is something called UCI, which stands for Universal Chess Interface, ( https://official-stockfish.github.io/docs/stockfish-wiki/UCI... ), to use it you start a new stockfish process and write and read from the standard inputs.
So instead of writing bug prone routines to check the validity of board positions, it turn the basic routines into a simple wrapper of parsing task to read and write UCI protocol to use a battle tested engine.
A chess position state is simply defined as a vector representing the sequence of moves. Moves are string in long algebraic notation.
This architectural decision allows for very quick (LLM-powered development) prototyping.
namespace bp = boost::process; bp::ipstream is; bp::opstream os;
bp::child c("../Stockfish/src/stockfish", bp::std_in is);
void displayBoard( const vector & moveSeq, bp::ipstream& is, bp::opstream& os );
void getLegalMoves( const vector & moveSeq, vector& legalMoves, bp::ipstream& is, bp::opstream& os );
void getTopKMoveAndScoreAtDepthFromPosition(const vector & moveSeq,int K, int D, vector >& topkmoves, bp::ipstream& is, bp::opstream& os , bool debug = false);
void displayBoard( const vector & moveSeq, bp::ipstream& is, bp::opstream& os ) {
os for( int i = 0 ; i {
os
}os os os string line;
while (getline(is, line)) { if (!line.compare(0, 7, "readyok")) break; cout }
You get the gist...
Re: A minimax chess engine in regular expressions
#35Earlier quoted context omitted.
I'm not sure how this quote applies to harmless pursuits like making and solving absurd puzzles. It's not like regex chess is going to be a weapon of mass destruction.
It's a line from the movie Jurassic Park. Pretty sure they're just joking.
Re: A minimax chess engine in regular expressions
#36Tried it, 2 comments:
1) Engine gives a piece early with: 1. b3 b6 2. Bb2 Bb7 3. e4 ??Bxg2
2) when you enter an uppercase letter it says illegal move
Edit: and here I am trying to "stumble" on an innovation and be productive again. Erh... Humans
Re: A minimax chess engine in regular expressions
#37The idea of doing something without a defined "productive" goal might help to do things differently, discover new ways, and in the end stumble on an innovation? Tried it, 2 comments: 1) Engine gives a piece early with: 1. b3 b6 2. Bb2 Bb7 3. e4 ??Bxg2 2) when you enter an uppercase letter it says illegal move Edit: and here I am trying to "stumble" on an innovation and be productive again. Erh... Humans
Re: A minimax chess engine in regular expressions
#38Earlier quoted context omitted.
Humans can't see the balance at a glance, but we can still easily check the balance of arbitrarily complex nested parenthesis because we are not limited in the same way an FSM is. We're just way way way slower than a computer.
Yeah, I agree that humans can indeed check some non-regular languages. That doesn't however mean that humans are inherently capable for checking all non-regular languages, as they are severely limited in the working memory size. Most if not all divisibility rules are a set of least significant digits or weighted running sums because they are subject to the same constraint, so they are indeed necessarily regular.
Regular languages admit words of arbitrary length. Eg a regular language can tell you whether 461523850177206879302813461556288524354486376376930935555512181511680646984669431923718933249775297346246192616509695718413981019441670321942082230577379960485875768935619924872490629853314107285524330300421382702242540015152210668552218484465230532702298574921915359545891160565971424053668201732275877291369 is divisible by 7. But a human would have a harder time with this than with the paren example given by the grandfather comment.
Re: A minimax chess engine in regular expressions
#39> And now for my absolute favorite part of the language we've developed. By the magic of regular expressions (and the fact that they perform substitution globally over the entire string), we can run multiple threads simultaneously!
Also:
> What do you want out of a conclusion to a blog post like this? I don't really have much to conclude. I guess I'll just say that I think more people should do entirely pointless things like this. It's a lot of fun, no one cares how long it takes you to finish, no one cares if it works or not, and incidentally, it teaches you more than you wanted to know about dozens of areas of computer science outside your field.
What a wonderful ethos.
Re: A minimax chess engine in regular expressions
#40The idea of doing something without a defined "productive" goal might help to do things differently, discover new ways, and in the end stumble on an innovation? Tried it, 2 comments: 1) Engine gives a piece early with: 1. b3 b6 2. Bb2 Bb7 3. e4 ??Bxg2 2) when you enter an uppercase letter it says illegal move Edit: and here I am trying to "stumble" on an innovation and be productive again. Erh... Humans
I guess playing 'good' chess is not the point, the point is that you can play at all using regexp. (The 'move a2a3 and lose as not considered legal' is more serious then it not actually playing well).