mirror of
https://github.com/nolen777/eagle0.git
synced 2026-07-29 00:15:42 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5018f882d8 |
@@ -31,11 +31,31 @@ auto AbstractMCTSAI::Search(
|
||||
result.searchTime = std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||
std::chrono::steady_clock::now() - startTime);
|
||||
|
||||
if (!rootNode || rootNode->children.empty()) {
|
||||
// Fallback to first action if no tree was built
|
||||
result.bestActionIndex = 0;
|
||||
result.bestScore = 0.0;
|
||||
return result;
|
||||
if (!rootNode) {
|
||||
throw MCTSInternalError("MCTS search: BuildMCTSTree returned null root node");
|
||||
}
|
||||
|
||||
if (rootNode->children.empty()) {
|
||||
// This can happen legitimately when:
|
||||
// 1. No legal actions available (terminal state)
|
||||
// 2. Only one action and we early-exited without exploring
|
||||
// In case 1, there's no valid action to return. In case 2, we should have
|
||||
// expanded that one child. Check totalActions to distinguish.
|
||||
if (rootNode->totalActions == 0) {
|
||||
throw MCTSInternalError(
|
||||
"MCTS search: No legal actions available in initial state - cannot return an "
|
||||
"action index");
|
||||
}
|
||||
// Single action case - should have been expanded in BuildMCTSTree
|
||||
if (rootNode->totalActions == 1) {
|
||||
result.bestActionIndex = 0;
|
||||
result.bestScore = 0.0;
|
||||
return result;
|
||||
}
|
||||
// Multiple actions but no children expanded - this shouldn't happen
|
||||
throw MCTSInternalError(
|
||||
"MCTS search: Root has " + std::to_string(rootNode->totalActions) +
|
||||
" actions but no children expanded - this indicates a bug in BuildMCTSTree");
|
||||
}
|
||||
|
||||
// Find best child
|
||||
@@ -381,7 +401,11 @@ auto AbstractMCTSAI::SelectSimulationAction(
|
||||
const MCTSGameState& state,
|
||||
const std::vector<std::unique_ptr<MCTSAction>>& actions,
|
||||
const bool isMaximizing) const -> size_t {
|
||||
if (actions.empty()) { return 0; }
|
||||
if (actions.empty()) {
|
||||
throw MCTSInternalError(
|
||||
"MCTSSimulation called with empty actions list - this indicates a bug in the "
|
||||
"MCTS tree building or game state");
|
||||
}
|
||||
|
||||
thread_local std::mt19937 gen(std::random_device{}());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user