I think you can improve it a lot by taking into account its own position. I mean, moving forward isn't very important want you are under the menace of a checkmate somewhere else.
But if you intentionally hang your pieces, it tends to take them. And it will try to promote pawns in the endgame. So it is possible for it to stumble upon a checkmate, though in my effort where I gave away all my pieces, it instead found the only move to stalemate once it had K+Q+R vs K.
Chose the most aggressive move (in term of pieces value and check-mate), if none is aggressive, it takes on of the move equally non aggressive.
Didn't remember the depth of the algorithm but it was very simple C code, could check quickly. It should be able to find a mate in 2 or 3 if it was in position of having one.
I didn't check the correctness of the algorithm, just the intention.
I applaud the effort but not sure I see the point, I had a more capable chess playing program than this on a zx speccy in the 80’s.
https://www.chessprogramming.org/ is also really interesting, see e.g. https://www.chessprogramming.org/Sunfish and https://www.chessprogramming.org/Quiescence_Search
Link I get shows 500 lines and it starts with 50 lines of piece-square tables. Maybe it's obvious when you are into the domain but otherwise... that's pretty much of opposite of what I would call "readable".
The file is 500 lines because of the piece square tables (as you mentioned), comments, and the CLI interface logic
Previous HN thread here: https://news.ycombinator.com/item?id=20068651
> I got 111 by deleting the tables in the top, and the UI code in the bottom, and then running 'cloc' on the result. That gave 20 blanks, 56 comments and 111 lines of code. ;-)
I always hated that video mode, but it looks good here when the magenta and cyan are limited just to links and headers!
Uncaught Failed to apply player move! cm-chessboard:69:55
promotion result
Object { type: "pieceSelected", square: "c8", piece: "wq" }
cm-chessboard:111:37
Uncaught Error: Invalid move: {"from":"d7","to":"c8","promotion":"q"}
I had forked a rook and king with a pawn. Pawn takes rook, and was going to be offered a promotion, but taking and promoting at once seems to make it crash.
apetresc•1d ago
``` Uncaught Error: Invalid move: {"from":"e8","to":"c8"} at Chess.move (chess.js:2530:23) at cm-chessboard/:75:23 ```
There didn't seem to be a way to recover besides refreshing.