diff --git a/src/repr/board.rs b/src/repr/board.rs index 27af858..58a96a3 100644 --- a/src/repr/board.rs +++ b/src/repr/board.rs @@ -5,6 +5,7 @@ use super::{ CoordAxis, CoordPair, }; use const_fn::const_fn; +use rand::{seq::IteratorRandom, Rng}; use std::{cmp::Ordering, fmt, sync::LazyLock}; #[derive(PartialEq, Eq, Copy, Clone, Debug)] @@ -97,6 +98,21 @@ impl Board { } } + pub fn random(steps: usize) -> Self { + let mut new = Self::new().starting_pos(); + let mut p = Piece::Black; + let mut rng = rand::rng(); + for _ in 0..steps { + if let Some(m) = new.possible_moves(p).choose(&mut rng) { + new.place_unchecked(m, p); + } + + p = !p; + } + + new + } + /// Starting position pub fn starting_pos(mut self) -> Self { self.place_unchecked(