Board: add random
This commit is contained in:
parent
cb463ed492
commit
c648be20aa
@ -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(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user