Skip to content

Commit

Permalink
Add getBestValuedChild
Browse files Browse the repository at this point in the history
  • Loading branch information
MetatransApps committed Dec 16, 2024
1 parent f769341 commit f1f0cef
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion EnginesRunner/src/bagaturchess/montecarlo/MCTS_V2.java
Original file line number Diff line number Diff line change
Expand Up @@ -434,12 +434,29 @@ private MCTSNode getMostVisitedChild(MCTSNode node) {
}


private MCTSNode getBestValuedChild(MCTSNode node) {
MCTSNode bestChild = null;
double best_eval = Double.NEGATIVE_INFINITY; // Fixed comparison value

for (MCTSNode child : node.children) {
double score = (child.colour_to_move == Constants.COLOUR_WHITE ? child.value : -child.value) / child.visits; // Adjusted value
if (score > best_eval) {
best_eval = score;
bestChild = child;
}
}

return bestChild;
}


private List<Integer> getMostVisitedChildrenMoves(MCTSNode node) {

List<Integer> moves = new ArrayList<Integer>();

while (node != null) {
node = getMostVisitedChild(node);
//node = getMostVisitedChild(node);
node = getBestValuedChild(node);
if (node != null) moves.add(node.originating_move);
}

Expand Down

0 comments on commit f1f0cef

Please sign in to comment.