5 ms·
Show HN: A Implementation of Alpha Zero for Chess in MLX
A chess engine implementation inspired by AlphaZero, using MLX for neural network computations and Monte Carlo Tree Search (MCTS) for move selection.
- 29athrowaway 1y agoHow does it do against Stockfish?
- mtlmtlmtlmtl 1y agoNot the author, but probably very poorly. This seems more like a proof of concept, it's written in Python, has a very basic tree search which is very light on heuristics. And likely the NN is undertrained too, but I can't tell from the repo. In comparison Stockfish is absurdly optimised in every aspect, from its datastructures to its algorithms. Considering how long it took the LeelaZero team to get their implementation to be competitive with latest Stockfish, I'd be shocked if this thing stood a chance. Of course, beating Stockfish is almost certainly not the goal for this project, looks more like a project to get familiar with MLX.
- 29athrowaway 1y agoThanks for the explanation.
- Scene_Cast2 1y agoThis is one of those topics that LLMs (Opus 4, Gemini 2.5 pro, etc) seem bad at explaining. I was trying to figure out the difference between the Stockfish approach (minimax, alpha-beta pruning) versus Alpha Zero / Leela Chess Zero (MCTS). My very crude understanding is that stockfish has a very light & fast neural net and goes for a very thorough search. Meanwhile, in MCTS (which I don't really understand at this point), you eval the neural net, sample some paths based on the neural net (similar to minimax), and then pick the path you sampled the most. There's also the training vs eval aspect to it. Would love a better explanation.
- cgearhart 1y agoIn old-fashioned AI, it was generally believed that the best way to spend resources was to exactly evaluate as much of the search tree as possible. To that end, you should use lightweight heuristics to guide the search in promising directions and optimizations like alpha-beta pruning to eliminate useless parts of the search space. For finite games of perfect information like chess this is hard to beat when the search is deep enough. (For if you could evaluate the whole game tree from the start then you could always make optimal moves.) Stockfish follows this approach and provides ample evidence of the strength in this strategy. Perhaps a bit flippantly, you can think of MCTS as “vibe search”—but more accurately it’s a sampling-based search. The basic theory is that we can summarize the information we’ve obtained to estimate our belief in the “goodness” of every possible move and (crucially) our confidence in that belief. Then we allocate search time to prioritize the branches that we are most certain are good. In this way MCTS iteratively constructs an explicit search tree for the game with associated statistics that is used to guide decisions during play. The neural network does a “vibe check” on each new position in the tree for the initial estimate of “goodness” and then the search process refines that estimate. (Ask the NN to guess at the current position; then play a bunch of simulations to make sure it doesn’t lead to obvious blunders.)
- bobmcnamara 1y agoI feel old. Old-old-fashioned(pre-alpha beta) chess engines used a heavyweight evaluator to limit graph searched branch factor.
- mtlmtlmtlmtl 1y agoCould you elaborate on this? I thought alpha-beta first appeared way back in the 50s/60s.
- bobmcnamara 1y agoThe first non trivial chess programs were 'playing' in the late 40s(with pen and paper CPUs). Some of these include features you'll still see today. https://www.chessprogramming.org/Claude_Shannon https://www.chessprogramming.org/Claude_Shannon proposed two types of chess programs, brutes and selective. Alpha-beta is an optimization for brutes, but many search chess programs were selective with heavyweight eval, or with delayed eval. Champernowne(Turing's partner), mentions this about turochamp, "We were particularly keen on the idea that whereas certain moves would be scorned as pointless and pursued no further others would be followed quite a long way down certain paths." You can read more about the A/B/A/B algorithm shift here: https://www.chessprogramming.org/Type_B_Strategy https://www.chessprogramming.org/Type_B_Strategy
- nightfox1 1y agoVery interesting, I have been actually working on an AI Chess Coach to help explain moves of games: https://lichess.org/@/nightfox/blog/ai-chess-coach/4uMrWhR9 https://lichess.org/@/nightfox/blog/ai-chess-coach/4uMrWhR9
- JoeDaDude 1y agoCool! I'd love to tinker with this and see about adapting it to other perfect information games. If you have any suggestions (or warnings) before I do this, please let me know!.
- mtlmtlmtlmtl 1y agoAgain, I didn't write this, but in general, to take a chess engine and apply to another game the main things you'd have to change are the board representation, and you'd have to retrain the neural net(likely redesign it as well). The tree search should work assuming the game you're going to is also a perfect information, minimax game. Though it could also work for other games. There's a good chance there's prior work on applying bitboards(board representation) on whichever game that is. Chessprogrammingwiki is an invaluable resource for information about how engines like this work. Godspeed.
- dfissadifdoi 1y ago[dead]