-
Notifications
You must be signed in to change notification settings - Fork 35
MCTS
[cite_start]ShashChess introduces a sophisticated Hybrid Search Architecture, integrating a state-of-the-art Monte Carlo Tree Search (MCTS) engine directly alongside the traditional Alpha-Beta search[cite: 895].
[cite_start]Crucially, this MCTS implementation is not a replacement but a context-aware specialist: it is selectively triggered based on Alexander Shashin's chess theory, specifically targeting defensive (Petrosian) and chaotic positions where standard engines often fail to find the most resilient path[cite: 896].
[cite_start]Traditional engines rely on Alpha-Beta pruning, which is highly effective but can suffer from "strategic blindness" in positions where long-term probabilities matter more than immediate tactical refutations[cite: 893, 894].
[cite_start]Unlike engines that use MCTS for everything (like Leela Chess Zero) or nothing (like Stockfish), ShashChess uses the Shashin Framework to decide when to use MCTS[cite: 898].
[cite_start]The engine analyzes the position's characteristics (Win Probability, Piece Density, Mobility) to classify it into a Shashin Zone[cite: 900]:
- Petrosian Zones (Defensive/Passive): These positions are notorious for being misevaluated by Alpha-Beta search. [cite_start]MCTS is activated here to find the most probabilistically sound defense[cite: 901, 902].
- [cite_start]High-Density Capablanca: In strategic positions with many pieces on the board, MCTS is enabled via the
MCTS Exploreoption to understand statistical outcomes rather than calculating concrete variations[cite: 903, 904].
graph TD
A[Root Position] --> B{Shashin Analysis}
B -->|Standard Position| C[Alpha-Beta Search]
B -->|Petrosian / High Density| D{Enable MCTS?}
D -->|Yes| E[Hybrid MCTS Search]
D -->|No| C
C --> F[Best Move]
E --> F
The MCTS implementation in ShashChess (montecarlo.cpp) is built from the ground up to interoperate with the existing Stockfish infrastructure.
-
Modified UCB: The core selection mechanism uses a modified Upper Confidence Bound (UCT) formula to balance exploration and exploitation.
-
Prior Estimation: Unlike pure random playouts, ShashChess uses a "smart" prior based on a shallow Alpha-Beta search (evaluate_with_minimax) to guide the tree growth initially.
-
Virtual Loss: To support multi-threading without locking issues, the engine applies "virtual losses" to nodes being visited, discouraging other threads from exploring the exact same path simultaneously.
Instead of playing random moves until the end of the game (which is slow and inaccurate for chess), ShashChess performs Alpha-Beta Rollouts.
How it works: When a leaf node is reached, the engine doesn't just "guess"; it runs a short, high-precision Minimax search to determine the node's value. This combines the strategic vision of MCTS with the tactical sharpness of Stockfish.
The MCTS engine reads from and writes to the main Transposition Table (TT).
-
Shared Intelligence: If the Alpha-Beta search finds a good move, the MCTS search "sees" it immediately via the TT.
-
Persistent Memory: MCTS results are cached, so if the engine encounters the same position again, it doesn't start from scratch.
The integration is seamless within the main search loop. As seen in search.cpp, the MCTS module is instantiated only when specific conditions are met:
// from search.cpp
if (bool(options["MCTS by Shashin"])) {
// Check if the position fits the criteria (Petrosian/Chaos)
bool possibleMCTSByValue = localShashinManager.isMCTSApplicableByValue();
if ( ... (possibleMCTSByValue || mctsExplore) ... ) {
// Initialize the Monte Carlo specialist
MonteCarlo* monteCarlo = new MonteCarlo(rootPos, this, tt);
monteCarlo->search(...);
}
} `
This architecture solves a critical problem in computer chess: homogeneity.
-
Diversity: ShashChess finds moves that standard Alpha-Beta engines miss simply because it "thinks" differently.
-
Resilience: In bad positions (Petrosian Zone), MCTS is historically better at finding practical drawing chances than Minimax, which assumes perfect play from the opponent.
-
Human-Like Analysis: The MCTS probabilities often align better with human intuition about "risk" than the raw centipawn output of standard engines.