From c8faad799e64af616539b698ad8ddb300039a062 Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Fri, 2 Feb 2024 07:28:12 -0800 Subject: [PATCH] [position] Clean up Position's construction scheme Position::default specifies the defaults for all field. Then, ::new() and ::starting() can use ..Default::default() in their implementations to avoid having to specify empty values for all the internal structures. --- position/src/position/position.rs | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/position/src/position/position.rs b/position/src/position/position.rs index 75b4b79..774fc26 100644 --- a/position/src/position/position.rs +++ b/position/src/position/position.rs @@ -26,16 +26,7 @@ pub struct Position { impl Position { pub fn empty() -> Position { - Position { - color_to_move: Color::White, - flags: Default::default(), - pieces: PieceBitBoards::default(), - en_passant_square: None, - sight: [OnceCell::new(), OnceCell::new()], - moves: OnceCell::new(), - half_move_counter: 0, - full_move_number: 1, - } + Default::default() } /// Return a starting position. @@ -60,13 +51,8 @@ impl Position { Self { color_to_move: Color::White, - flags: Flags::default(), pieces: PieceBitBoards::new([white_pieces, black_pieces]), - en_passant_square: None, - sight: [OnceCell::new(), OnceCell::new()], - moves: OnceCell::new(), - half_move_counter: 0, - full_move_number: 1, + ..Default::default() } } @@ -340,7 +326,16 @@ impl Position { impl Default for Position { fn default() -> Self { - Self::empty() + Self { + color_to_move: Color::White, + flags: Flags::default(), + pieces: PieceBitBoards::default(), + en_passant_square: None, + sight: [OnceCell::new(), OnceCell::new()], + moves: OnceCell::new(), + half_move_counter: 0, + full_move_number: 1, + } } }