[board] Add MoveCounter struct to track current color, half move counter, and full move counter
This commit is contained in:
		
							parent
							
								
									7b0469d689
								
							
						
					
					
						commit
						c733342fca
					
				
					 2 changed files with 36 additions and 0 deletions
				
			
		| 
						 | 
					@ -6,6 +6,7 @@ pub mod en_passant;
 | 
				
			||||||
pub mod fen;
 | 
					pub mod fen;
 | 
				
			||||||
pub mod flags;
 | 
					pub mod flags;
 | 
				
			||||||
pub mod macros;
 | 
					pub mod macros;
 | 
				
			||||||
 | 
					pub mod move_counter;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
mod board;
 | 
					mod board;
 | 
				
			||||||
mod builder;
 | 
					mod builder;
 | 
				
			||||||
| 
						 | 
					@ -17,4 +18,5 @@ pub use builder::Builder;
 | 
				
			||||||
use castle::Castle;
 | 
					use castle::Castle;
 | 
				
			||||||
use en_passant::EnPassant;
 | 
					use en_passant::EnPassant;
 | 
				
			||||||
use flags::Flags;
 | 
					use flags::Flags;
 | 
				
			||||||
 | 
					use move_counter::MoveCounter;
 | 
				
			||||||
use piece_sets::PieceSet;
 | 
					use piece_sets::PieceSet;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										34
									
								
								board/src/move_counter.rs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								board/src/move_counter.rs
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,34 @@
 | 
				
			||||||
 | 
					use chessfriend_core::Color;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#[derive(Clone, Copy, Debug, Eq, PartialEq)]
 | 
				
			||||||
 | 
					pub struct MoveCounter {
 | 
				
			||||||
 | 
					    /// The player who's turn it is to move.
 | 
				
			||||||
 | 
					    pub active_color: Color,
 | 
				
			||||||
 | 
					    /// The number of completed turns. A turn finishes when every player has moved.
 | 
				
			||||||
 | 
					    pub fullmove_number: u16,
 | 
				
			||||||
 | 
					    /// The number of moves by all players since the last pawn advance or capture.
 | 
				
			||||||
 | 
					    pub halfmove_number: u16,
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					impl MoveCounter {
 | 
				
			||||||
 | 
					    pub fn advance(&mut self, should_reset_halfmove_number: bool) {
 | 
				
			||||||
 | 
					        self.active_color = self.active_color.next();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        self.fullmove_number += 1;
 | 
				
			||||||
 | 
					        self.halfmove_number = if should_reset_halfmove_number {
 | 
				
			||||||
 | 
					            0
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            self.halfmove_number + 1
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					impl Default for MoveCounter {
 | 
				
			||||||
 | 
					    fn default() -> Self {
 | 
				
			||||||
 | 
					        Self {
 | 
				
			||||||
 | 
					            active_color: Color::default(),
 | 
				
			||||||
 | 
					            fullmove_number: 0,
 | 
				
			||||||
 | 
					            halfmove_number: 0,
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue