Skip to content

Commit

Permalink
Return node_count from think_parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
primenumber committed May 4, 2024
1 parent a789296 commit 85131d6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/book.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ fn search<Eval: Evaluator>(
node_count: 0,
cache_gen: solve_obj.cache_gen,
};
let (_score, hand, _depth) = think_parallel(
let (_score, hand, _depth, _node_count) = think_parallel(
&searcher,
board,
solve_obj.evaluator.score_min(),
Expand Down
16 changes: 12 additions & 4 deletions src/engine/think.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,26 +350,34 @@ pub fn think_parallel<Eval: Evaluator>(
alpha: i16,
beta: i16,
passed: bool,
) -> (i16, Hand, i8) {
) -> (i16, Hand, i8, usize) {
thread::scope(|s| {
let mut handles = Vec::new();
for i in 0..num_cpus::get() {
handles.push(s.spawn(move || {
let mut ctx = searcher.clone();
ctx.iterative_think(board, alpha, beta, passed, 3, i)
let (score, hand, depth) = ctx.iterative_think(board, alpha, beta, passed, 3, i);
(score, hand, depth, ctx.node_count)
}));
}
let mut result_depth = 0;
let mut result_score = None;
let mut result_hand = None;
let mut result_node_count = 0;
for h in handles {
let (tscore, thand, tdepth) = h.join().unwrap();
let (tscore, thand, tdepth, node_count) = h.join().unwrap();
result_node_count += node_count;
if tdepth > result_depth {
result_depth = tdepth;
result_score = Some(tscore);
result_hand = Some(thand);
}
}
(result_score.unwrap(), result_hand.unwrap(), result_depth)
(
result_score.unwrap(),
result_hand.unwrap(),
result_depth,
result_node_count,
)
})
}
4 changes: 2 additions & 2 deletions src/play.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ pub fn codingame(_matches: &ArgMatches) -> Result<(), Box<dyn std::error::Error>
node_count: 0,
cache_gen: solve_obj.cache_gen,
};
let (score, best, depth) = think_parallel(
let (score, best, depth, node_count) = think_parallel(
&searcher,
board.board,
searcher.evaluator.score_min(),
Expand All @@ -366,7 +366,7 @@ pub fn codingame(_matches: &ArgMatches) -> Result<(), Box<dyn std::error::Error>
);
eprintln!(
"Estimated result: {}, Depth: {}, Nodes: {}",
score, depth, searcher.node_count
score, depth, node_count
);
best
} else {
Expand Down

0 comments on commit 85131d6

Please sign in to comment.