[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.
This commit is contained in:
		
							parent
							
								
									f09376f5dc
								
							
						
					
					
						commit
						c8faad799e
					
				
					 1 changed files with 12 additions and 17 deletions
				
			
		| 
						 | 
				
			
			@ -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,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue