[board, position] Simplify check methods
Only one check-testing method, Board::is_in_check(), that tests if the current active player is in check. It doesn't make sense to test if the non-active player is in check.
This commit is contained in:
		
							parent
							
								
									a30553503f
								
							
						
					
					
						commit
						e3d17219ad
					
				
					 3 changed files with 9 additions and 17 deletions
				
			
		|  | @ -5,18 +5,10 @@ use chessfriend_bitboard::BitBoard; | |||
| use chessfriend_core::{Color, Piece}; | ||||
| 
 | ||||
| impl Board { | ||||
|     /// Return whether the active color is in check.
 | ||||
|     #[must_use] | ||||
|     pub fn active_color_is_in_check(&self) -> bool { | ||||
|         self.unwrapped_color_is_in_check(self.active_color()) | ||||
|     } | ||||
| 
 | ||||
|     #[must_use] | ||||
|     pub fn color_is_in_check(&self, color: Option<Color>) -> bool { | ||||
|         self.unwrapped_color_is_in_check(self.unwrap_color(color)) | ||||
|     } | ||||
| 
 | ||||
|     #[must_use] | ||||
|     pub fn unwrapped_color_is_in_check(&self, color: Color) -> bool { | ||||
|     pub fn is_in_check(&self) -> bool { | ||||
|         let color = self.active_color(); | ||||
|         let king = self.king_bitboard(color); | ||||
|         let opposing_sight = self.opposing_sight(color); | ||||
|         (king & opposing_sight).is_populated() | ||||
|  | @ -39,7 +31,7 @@ mod tests { | |||
|             Black Rook on F3, | ||||
|         ); | ||||
| 
 | ||||
|         assert!(board.unwrapped_color_is_in_check(Color::White)); | ||||
|         assert!(board.is_in_check()); | ||||
|     } | ||||
| 
 | ||||
|     #[test] | ||||
|  | @ -49,6 +41,6 @@ mod tests { | |||
|             Black Rook on B4, | ||||
|         ); | ||||
| 
 | ||||
|         assert!(!board.unwrapped_color_is_in_check(Color::White)); | ||||
|         assert!(!board.is_in_check()); | ||||
|     } | ||||
| } | ||||
|  |  | |||
|  | @ -129,7 +129,7 @@ impl Position { | |||
|                     ); | ||||
|                 }); | ||||
| 
 | ||||
|             let move_is_legal = !test_board.color_is_in_check(Some(active_color_before_move)); | ||||
|             let move_is_legal = !test_board.is_in_check(); | ||||
| 
 | ||||
|             test_board.unmake_move(&record).unwrap_or_else(|err| { | ||||
|                 panic!( | ||||
|  |  | |||
|  | @ -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().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().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().is_in_check()); | ||||
| 
 | ||||
|     let rook_moves: HashSet<_> = pos.all_legal_moves(None).collect(); | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue