From 85131d68c5defd39c7cef539ae9b2432fc016811 Mon Sep 17 00:00:00 2001 From: primenumber Date: Sun, 5 May 2024 08:10:07 +0900 Subject: [PATCH] Return node_count from think_parallel --- src/book.rs | 2 +- src/engine/think.rs | 16 ++++++++++++---- src/play.rs | 4 ++-- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/book.rs b/src/book.rs index 1f8d748..9e27545 100644 --- a/src/book.rs +++ b/src/book.rs @@ -192,7 +192,7 @@ fn search( 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(), diff --git a/src/engine/think.rs b/src/engine/think.rs index 014788c..cebb4ac 100644 --- a/src/engine/think.rs +++ b/src/engine/think.rs @@ -350,26 +350,34 @@ pub fn think_parallel( 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, + ) }) } diff --git a/src/play.rs b/src/play.rs index 4c067d3..795151d 100644 --- a/src/play.rs +++ b/src/play.rs @@ -357,7 +357,7 @@ pub fn codingame(_matches: &ArgMatches) -> Result<(), Box 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(), @@ -366,7 +366,7 @@ pub fn codingame(_matches: &ArgMatches) -> Result<(), Box ); eprintln!( "Estimated result: {}, Depth: {}, Nodes: {}", - score, depth, searcher.node_count + score, depth, node_count ); best } else {