Board: make starting_pos a const variable instead
This commit is contained in:
parent
672a523fd1
commit
30476757da
@ -16,7 +16,7 @@ fn extend_layers_no_pruning(depth: usize) -> usize {
|
||||
children_eval_method: ChildrenEvalMethod::AverageDivDepth,
|
||||
};
|
||||
let mut fut = FutureMoves::new(Piece::Black, config);
|
||||
fut.update_from_board(&Board::new().starting_pos());
|
||||
fut.update_from_board(&Board::STARTING_POSITION);
|
||||
fut.extend_layers();
|
||||
fut.arena_len()
|
||||
}
|
||||
|
||||
@ -22,7 +22,7 @@ pub fn run() {
|
||||
},
|
||||
);
|
||||
|
||||
let mut board = Board::new().starting_pos();
|
||||
let mut board = Board::STARTING_POSITION;
|
||||
let mut rng = rand::rng();
|
||||
let mut i = 0;
|
||||
while board.game_winner() == Winner::None && i < 2 {
|
||||
|
||||
@ -8,7 +8,7 @@ pub struct Game {
|
||||
impl Game {
|
||||
pub fn new(player1: Box<dyn Agent>, player2: Box<dyn Agent>) -> Self {
|
||||
Self {
|
||||
inner: GameInner::new(player1, player2, true, Board::new().starting_pos()),
|
||||
inner: GameInner::new(player1, player2, true, Board::STARTING_POSITION),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -629,7 +629,7 @@ mod tests {
|
||||
let mut futm = FutureMoves::new(Piece::Black, FUTURE_MOVES_CONFIG);
|
||||
futm.config.max_depth = 1;
|
||||
|
||||
futm.update_from_board(&Board::new().starting_pos());
|
||||
futm.update_from_board(&Board::STARTING_POSITION);
|
||||
|
||||
futm.extend_layers();
|
||||
assert_eq!(futm.arena_len(), 5);
|
||||
@ -710,7 +710,7 @@ mod tests {
|
||||
#[test]
|
||||
fn skip_move_recovery() {
|
||||
let mut futm = FutureMoves::new(Piece::Black, FUTURE_MOVES_CONFIG);
|
||||
let mut board = Board::new().starting_pos();
|
||||
let mut board = Board::STARTING_POSITION;
|
||||
|
||||
// replay of a test I did
|
||||
// TODO! make this as small of a test as possible
|
||||
@ -774,8 +774,8 @@ mod tests {
|
||||
fn derive_board() {
|
||||
let mut futm = FutureMoves::new(Piece::White, FUTURE_MOVES_CONFIG);
|
||||
|
||||
let mut b = Board::new().starting_pos();
|
||||
futm.update_from_board(&Board::new().starting_pos());
|
||||
let mut b = Board::STARTING_POSITION;
|
||||
futm.update_from_board(&b);
|
||||
|
||||
b.place((4, 2).into(), Piece::White).unwrap();
|
||||
|
||||
|
||||
@ -123,7 +123,7 @@ impl Board {
|
||||
}
|
||||
|
||||
pub fn random(steps: usize) -> Self {
|
||||
let mut new = Self::new().starting_pos();
|
||||
let mut new = Self::STARTING_POSITION;
|
||||
let mut p = Piece::Black;
|
||||
let mut rng = rand::rng();
|
||||
for _ in 0..steps {
|
||||
@ -137,16 +137,17 @@ impl Board {
|
||||
new
|
||||
}
|
||||
|
||||
/// Starting position
|
||||
pub const fn starting_pos(mut self) -> Self {
|
||||
pub const STARTING_POSITION: Self = {
|
||||
let mut new = Self::new();
|
||||
let hf = Self::SIZE / 2;
|
||||
self.place_unchecked(CoordPair::from_axes(hf - 1, hf - 1), Piece::White);
|
||||
self.place_unchecked(CoordPair::from_axes(hf, hf - 1), Piece::Black);
|
||||
|
||||
self.place_unchecked(CoordPair::from_axes(hf - 1, hf), Piece::Black);
|
||||
self.place_unchecked(CoordPair::from_axes(hf, hf), Piece::White);
|
||||
self
|
||||
}
|
||||
new.place_unchecked(CoordPair::from_axes(hf - 1, hf - 1), Piece::White);
|
||||
new.place_unchecked(CoordPair::from_axes(hf, hf - 1), Piece::Black);
|
||||
|
||||
new.place_unchecked(CoordPair::from_axes(hf - 1, hf), Piece::Black);
|
||||
new.place_unchecked(CoordPair::from_axes(hf, hf), Piece::White);
|
||||
new
|
||||
};
|
||||
|
||||
/// Provides an iterator of all possible positions on the board
|
||||
pub fn all_positions() -> impl Iterator<Item = CoordPair> {
|
||||
@ -499,7 +500,7 @@ mod test {
|
||||
#[test]
|
||||
fn format_test() {
|
||||
assert_eq!(
|
||||
Board::new().starting_pos().to_string().as_str(),
|
||||
Board::STARTING_POSITION.to_string().as_str(),
|
||||
" 7 6 5 4 3 2 1 0
|
||||
-----------------
|
||||
7| | | | | | | | |
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user