![Probabilistic Chess](https://marc.ai/media/posts/10/android-chrome-192x192.png)
Probabilistic Chess
Introducing Probabilistic Chess
An exciting new variant of chess that you can play at marc.ai/probchess. By adding success probabilities to each move, the game becomes a blend of strategy and excitement, making every decision critical and unpredictable.
The Rules:
- Movement Probability: Each square on the board has a probability of successfully moving to it.
- Dice Roll: A happy-face dice roll means the move was successful.
- Winning Condition: You win by capturing the opponent's king.
For example, if you attempt to move a pawn from e2 to e4 and e4 has a 60% success probability, you will see a dice roll animation. The dice will have a 60% chance of landing on a happy face and a 40% chance of landing on a sad face. If it lands on a happy face, the move succeeds. If it lands on a sad face, the move fails, the pawn returns to e2, and it's now the opponent’s turn.
Capturing the King
An intriguing aspect of probabilistic chess is that checkmate no longer guarantees a win. In traditional chess, checkmate ends the game because it ensures the king will be captured. However, in probabilistic chess, capturing the king is not guaranteed. The king may be on a low probability square, making it challenging to capture. Additionally, the opponent may capture your king while you attempt to capture theirs, or the king might escape while you try to capture it. Therefore, thinking probabilistically and strategizing based on square probabilities is crucial.
Key points:
- Checkmate: Checkmate does not win the game; capturing the king does.
- Moves During Check: You can make moves while your king is in check.
- Self-Check: You can make moves that put your king in check.
This dynamic adds a fun twist to chess. Traditional chess often ends with a checkmate without ever capturing the king, but now, you get the satisfaction of an actual capture (or the frustration of a failed attempt).
All Games End in a Win
Due to the probabilistic nature of the board, traditional draw scenarios do not apply. Stalemates are impossible because the king can always attempt to escape, and the opponent might fail to capture it. Even with only two kings left, they can capture each other by moving to low probability squares. If one king tries to capture and fails, the other can succeed.
This rule change is similar to modifications in professional sports to eliminate draws, like hockey's overtime and shootouts or the NBA's continual overtimes until a winner is declared.
Always having a game end in a win is really enjoyable, eliminates the frustration of stalemates and perpetual checks and ensures a thrilling conclusion every time. It also means that victory is always within reach: even if you fall behind, the a lucky roll of the dice means you always have a chance to come back.
In case players decide to prolong the game indefinitely (e.g. with two kings avoiding each other instead of doing the honorable thing of thing of trying to capture each other in a final showdown), I'm considering adding a "shrinking board" variation where the board gradually gets smaller, forcing the kings toward each other. Feedback on handling these scenarios is welcome.
Variants
While I like the simplicity of the default rules, we're testing out different variants of the game based on our experience playing it. You can try these out in the 'Variants' drop-down section of the site.
- King Moves Always Succeed: King moves are always successful.
- King Moves Double Success Rate: King moves have double the success rate of the destination square.
These 'king move' variants were introduced to reduce the chances of winning simply by constantly attacking the king and getting a lucky dice roll as it can be frustrating to lose when far ahead simply because the opponent YOLO's their pieces at your king. There may be a way to play to lower the odds of this, or maybe these variants are needed. We'd love some feedback on if a variant should become part of the core game mechanics.
Implementation Details
Board Probabilities Setup
- Random Initialization: Probabilities are randomly set at the start of each game.
- King Square: Starts with a probability of at least 20%. This lowers the chances of having the king start on an almost uncapturable square.
- Minimum Probability: 5% for any square.
- Maximum Probability: 99% for any square.
Note: These rules may change as the game evolves.
Client-Side Implementation
The game is implemented purely in HTML, CSS, and JavaScript to run without a server. This approach ensures fast loading times and low server costs but poses challenges for creating a performant chess AI.
Chess AI Opponent
Creating a chess AI for Probabilistic Chess is a fun project. It needs to both understand chess and think probabilistically. The AI combines chess.js and stockfish.js.
Stockfish AI (Moderate)
This simple AI uses Stockfish to determine the best move. While Stockfish is a strong chess program, it does not account for probabilities, resulting in occasional poor decisions, like repeatedly attempting moves to low probability squares.
Alpha-Beta with Expectation-Maximization (Hard and Expert)
This is the primary AI for the game, incorporating an alpha-beta search algorithm and the expectation-maximization algorithm to consider board probabilities. It calculates:
- Move Success Score: The score if the move succeeds, by recursively calling alpha-beta and calling stockfish's eval method once the desired depth is reached.
- Move Failed Score: The score if the move fails and it’s the opponent’s turn.
- Expected Value:
moveSuccessScore * probOfMoveSucceeding + moveFailedScore * (1 - probOfMoveSucceeding)
This runs recursively up to a certain depth, using the traditional chess alpha-beta search algorithm. When it reaches the desired depth, it asks Stockfish to provide an eval for the position.
This seems to work pretty well and results in a decently strong opponent that takes square probabilities into account.
Additional details:
- Performance: Running a large search tree in JavaScript is slow, limiting the search depth.
- Multi-threading: I'm considering a newer, multi-threaded version of Stockfish's JavaScript engine, though it requires setting CORS headers which my host doesn't support. I'm going to try one of the documented workarounds.
- AI vs. AI: You can set AIs for both black and white to watch them play against each other.
- Endgame Issues: There can be problems when the AI believes the game is over (e.g. it’s way ahead, or the game is a draw). At this point, most moves have an identical score so it doesn’t quite know what to do. I’m looking at improving this.
Monte Carlo Simulation
This earlier algorithm ran several simulations using Stockfish's top moves to determine the best move based on average scores. It worked decently but was slow and is no longer actively developed.
Status
This is an experimental 'alpha' version of the game. Please expect changes along the way and feedback is welcome.
Conclusion
Developing Probabilistic Chess has been a lot of fun. My dad and I have spent over 30 years working on programming projects together and a big part of that was focused on ML and applying it to chess so building a new variant of chess together has been great.
Credits
- Created by: Marc Stogaitis and Guy Stogaitis
- Special Thanks: Ghislaine Stogaitis and Mimi Sun
- Inspired by: Cameron Sun’s probabilistic tic-tac-toe
- Libraries Used: chess.js, stockfish.js
- Try out probabilistic chess here.
Contact
- Twitter: @marcsto
- Email: marcsto@gmail.com
Please share Probabilistic Chess with your friends!