[explorer, position] Make Position.board private to the crate
Export a Position::board() method that returns a reference to the internal Board.
This commit is contained in:
		
							parent
							
								
									4ae1fd62b7
								
							
						
					
					
						commit
						f84319272c
					
				
					 3 changed files with 12 additions and 7 deletions
				
			
		|  | @ -187,7 +187,7 @@ fn respond(line: &str, state: &mut State) -> anyhow::Result<CommandResult> { | |||
| } | ||||
| 
 | ||||
| fn do_flags_command(state: &mut State, _matches: &clap::ArgMatches) -> CommandResult { | ||||
|     let board = &state.position.board; | ||||
|     let board = state.position.board(); | ||||
| 
 | ||||
|     println!("Castling:"); | ||||
| 
 | ||||
|  | @ -390,7 +390,7 @@ fn main() -> Result<(), String> { | |||
|     loop { | ||||
|         if should_print_position { | ||||
|             println!("{}", &state.position); | ||||
|             println!("{} to move.", state.position.board.active_color()); | ||||
|             println!("{} to move.", state.position.active_color()); | ||||
|         } | ||||
| 
 | ||||
|         let readline = editor.readline("\n? "); | ||||
|  |  | |||
|  | @ -24,7 +24,7 @@ use std::{collections::HashSet, fmt, sync::Arc}; | |||
| #[must_use] | ||||
| #[derive(Clone, Debug, Default, Eq)] | ||||
| pub struct Position { | ||||
|     pub board: Board, | ||||
|     pub(crate) board: Board, | ||||
|     pub(crate) moves: Vec<MoveRecord>, | ||||
|     pub(crate) captures: CapturesList, | ||||
| 
 | ||||
|  | @ -48,6 +48,11 @@ impl Position { | |||
|             ..Default::default() | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     #[must_use] | ||||
|     pub fn board(&self) -> &Board { | ||||
|         &self.board | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| impl Position { | ||||
|  |  | |||
|  | @ -8,7 +8,7 @@ | |||
| 
 | ||||
| use chessfriend_core::Color; | ||||
| use chessfriend_moves::{ | ||||
|     assert_move_list, assert_move_list_contains, assert_move_list_does_not_contain, ply, Move, | ||||
|     Move, assert_move_list, assert_move_list_contains, assert_move_list_does_not_contain, ply, | ||||
| }; | ||||
| use chessfriend_position::test_position; | ||||
| use std::collections::HashSet; | ||||
|  | @ -107,7 +107,7 @@ fn en_passant_check_capture() { | |||
|         White Pawn on D4, | ||||
|     ], D3); | ||||
| 
 | ||||
|     assert!(pos.board.active_color_is_in_check()); | ||||
|     assert!(pos.board().active_color_is_in_check()); | ||||
| 
 | ||||
|     let generated_moves: HashSet<_> = pos.all_legal_moves(Some(Color::Black)).collect(); | ||||
| 
 | ||||
|  | @ -123,7 +123,7 @@ fn en_passant_check_block() { | |||
|         White Queen on F1, | ||||
|     ], D3); | ||||
| 
 | ||||
|     assert!(pos.board.active_color_is_in_check()); | ||||
|     assert!(pos.board().active_color_is_in_check()); | ||||
| 
 | ||||
|     let generated_moves: HashSet<_> = pos.all_legal_moves(Some(Color::Black)).collect(); | ||||
| 
 | ||||
|  | @ -139,7 +139,7 @@ fn pinned_pieces_rook_cannot_move_out_of_pin() { | |||
|         White King on C1, | ||||
|     ]); | ||||
| 
 | ||||
|     assert!(!pos.board.active_color_is_in_check()); | ||||
|     assert!(!pos.board().active_color_is_in_check()); | ||||
| 
 | ||||
|     let rook_moves: HashSet<_> = pos.all_legal_moves(None).collect(); | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue