refact(perf): use board::white_checker_cumulative to convert move to trictracAction

This commit is contained in:
Henri Bourcereau 2026-03-06 22:10:12 +01:00
parent dfc485a47a
commit 43eb5bf18d
2 changed files with 45 additions and 29 deletions

View file

@ -598,6 +598,20 @@ impl Board {
core::array::from_fn(|i| i + min)
}
/// Returns cumulative white-checker counts: result[i] = # white checkers in fields 1..=i.
/// result[0] = 0.
pub fn white_checker_cumulative(&self) -> [u8; 25] {
let mut cum = [0u8; 25];
let mut total = 0u8;
for (i, &count) in self.positions.iter().enumerate() {
if count > 0 {
total += count as u8;
}
cum[i + 1] = total;
}
cum
}
pub fn move_checker(&mut self, color: &Color, cmove: CheckerMove) -> Result<(), Error> {
self.remove_checker(color, cmove.from)?;
self.add_checker(color, cmove.to)?;