refactor how suggestion-updates are propagated to Bot and logged
This commit is contained in:
parent
7bb551b362
commit
bd840d5705
|
@ -54,8 +54,16 @@ impl Bot {
|
|||
// same as "bot.think_for(2500); bot.think_for(5000 - bot.iterations());"
|
||||
let max_iters = self.iters + gas;
|
||||
while self.iters < max_iters {
|
||||
self.algorithm
|
||||
let did_update = self
|
||||
.algorithm
|
||||
.step(&self.arena, &self.evaluator, &mut self.iters);
|
||||
if did_update {
|
||||
tracing::debug!(
|
||||
"new suggestion @ {}: {:?}",
|
||||
self.iters,
|
||||
self.algorithm.best().unwrap(),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -165,15 +173,20 @@ impl SegmentedAStar {
|
|||
self.best.map(|node| unsafe { node.as_node() })
|
||||
}
|
||||
|
||||
fn step(&mut self, arena: &Arena, eval: &Evaluator, iters: &mut u32) {
|
||||
fn step(&mut self, arena: &Arena, eval: &Evaluator, iters: &mut u32) -> bool {
|
||||
*iters += 1;
|
||||
match self.expand(arena, eval) {
|
||||
Ok(work) => *iters += work,
|
||||
Ok(work) => {
|
||||
*iters += work;
|
||||
false
|
||||
}
|
||||
Err(maybe_cand) => {
|
||||
if let Some(cand) = maybe_cand {
|
||||
self.backup(cand, *iters);
|
||||
}
|
||||
self.select();
|
||||
if let Some(cand) = maybe_cand {
|
||||
self.backup(cand)
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -206,13 +219,12 @@ impl SegmentedAStar {
|
|||
Ok(work)
|
||||
}
|
||||
|
||||
fn backup(&mut self, cand: &Node, iters: u32) {
|
||||
fn backup(&mut self, cand: &Node) -> bool {
|
||||
if self.best().map_or(true, |best| cand.is_better(best)) {
|
||||
tracing::debug!(
|
||||
"{} suggestion @ {iters}: {cand:?}",
|
||||
self.best.map_or("1st", |_| "new")
|
||||
);
|
||||
self.best = Some(cand.into());
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue