A probabilistic chess engine

Discussion of chess software programming and technical issues.

Moderator: Ras

one_thousand_lakes
Posts: 1
Joined: Tue Mar 05, 2024 7:33 am
Full name: Luke Salamone

A probabilistic chess engine

Post by one_thousand_lakes »

Hi everyone, I am working on a probabilistic engine which uses opponent modeling to play the move which has the best expected value given an accurate model of the opponent. Currently it uses a neural net model of lichess 1500 elo players for the opponent model, and stockfish as an oracle for the value of a position under consideration.

For minimax, my understanding is we are essentially playing the best move under the assumption that the opponent will play their best move. But this isn't necessarily the fastest path to victory or the most engaging to play with. If we have a model of the opponent's behavior, we might be able to beat them faster. And from the player's perspective, it is possible to beat such an engine by playing moves which are better and out of distribution. In practical terms, this engine will try to trap you, but learning to play better moves will let you beat it.

Here is a demo: https://chessmate-demo.s3.amazonaws.com/play.html

(Technical note: the model is around 33mb, so it may take a minute to load depending on your connection. Unfortunately I don't have a loading bar for that yet. But the whole thing should run from your browser, no server necessary.)
User avatar
towforce
Posts: 12229
Joined: Thu Mar 09, 2006 12:57 am
Location: Birmingham UK
Full name: Graham Laight

Re: A probabilistic chess engine

Post by towforce »

Loved the fact that I could play it in the browser, like a chess.com bot!

Can't say how good it's probabilistic feature is - it simply outplayed me: got its pawns into good positions, trapped my bishop, made a lethal attack against my king. I'd have to concentrate more to give it a competitive game:




Edit: just uncovered a bug: the PGN output isn't usable at this site.
Want to attract exceptional people? Be exceptional.
reallyturborandom
Posts: 1
Joined: Wed May 08, 2024 3:41 pm
Full name: James Lee

Re: A probabilistic chess engine

Post by reallyturborandom »

really cool idea, but the engine feels too weak? (I'm 1300-1400 on chess.com for reference, and was winning fairly comfortably, occasionally it would trick me but i would recover after pretty easily)

also the pgn is missing spaces between moves, and it would be nice to be able to play with black...

I'm interested to see how this progresses, and towforce is right, I can definitely see this becoming a chess.com bot in the future
User avatar
Ajedrecista
Posts: 2077
Joined: Wed Jul 13, 2011 9:04 pm
Location: Madrid, Spain.

Re: A probabilistic chess engine.

Post by Ajedrecista »

Hello:
towforce wrote: Wed Apr 10, 2024 9:38 pm[...]




Edit: just uncovered a bug: the PGN output isn't usable at this site.
reallyturborandom wrote: Sat May 11, 2024 4:39 pm[...]

also the pgn is missing spaces between moves, and it would be nice to be able to play with black...

[...]
Yes, it should be fixed. Meanwhile, there must be some regex expression to add spaces after certain patterns {[a-h][1-8] with optional + (from check), O (from castlings), p (from en passant) and so on}. An interesting combination would be en passant with check (exf6+ ep or how? SF 16.1 under Arena displays e5xf6/ep+), just like in the proof game 1. e4 e6 2. Nc3 d5 3. Nxd5 exd5 4. e5 Bc5 5. Qe2 f5 and the en passant with check now. Wikipedia suggest exf6 e.p.+ in this case.

I simply added spaces manually to towforce's game this time:



Regards from Spain.

Ajedrecista.
User avatar
Ras
Posts: 2691
Joined: Tue Aug 30, 2016 8:19 pm
Full name: Rasmus Althoff

Re: A probabilistic chess engine

Post by Ras »

Rasmus Althoff
https://www.ct800.net
User avatar
hgm
Posts: 28318
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: A probabilistic chess engine

Post by hgm »

I tried it against the Interactive Diagram. But because the I.D. would never think more than 1 sec even on its highest setting (4 ply) for an 8x8 game, and the demo applet uses about 17 sec/move, it lost the first few games dismally.

So I modified the script to allow 5.5 ply (using the experimental betzaNewer.js script). This made the I.D. think up to 7 sec, although for most of the game it was more like 2 sec. This produced the following game:

User avatar
Ras
Posts: 2691
Joined: Tue Aug 30, 2016 8:19 pm
Full name: Rasmus Althoff

Re: A probabilistic chess engine

Post by Ras »

Here a game between the CT800 V1.45, microcontroller version (GD32 Cortex-M4, 168MHz) at 5s/move, roughly matching the Chessmate. The CT800 with its about 30kNPS (yes, k not M) gets around 8 plies of main depth in the middle game. Chessmate sets up a nice tactical trap in move 8, but the CT800 sees through it.

Rasmus Althoff
https://www.ct800.net
User avatar
hgm
Posts: 28318
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: A probabilistic chess engine

Post by hgm »

Ras wrote: Sat May 18, 2024 9:07 pmThe CT800 with its about 30kNPS (yes, k not M) gets around 8 plies of main depth in the middle game.
The Interactive Diagram is similar (22knps). The depth of 5.5 ply is an under-estimate, though, as it has many extensions. And in particular extends the moves in the root that are tactically connected to the latest move in the game. OTOH it does not fully extend all captures in QS. Even good captures that do not recapture the last-moved piece only get extended by half a ply.

[Edit] Chessmate makes strange blunders. In the game below 57... Ra4? blunders away the Rook in a won position. I cannot imagine what move it would speculate on that would make Ra4 'win faster':