11//! evaluating the positions of the pieces on the board
22use std:: ops:: BitAnd ;
33
4+ use chess:: BitBoard ;
45use chess:: Board ;
56use chess:: Color ;
7+ use chess:: Piece ;
68use chess:: Square ;
79
810use crate :: evaluation:: Interp ;
@@ -11,6 +13,11 @@ use crate::evaluation::bitboards::MG_PESTO_TABLE;
1113use crate :: evaluation:: bitboards:: POS_PIECE_TYPES ;
1214use crate :: setup:: values:: Value ;
1315
16+ /// bitboard of dark squares
17+ const DARK_SQUARES : BitBoard = BitBoard ( 0xAA55AA55AA55AA55 ) ;
18+ /// bitboard of light squares
19+ const LIGHT_SQUARES : BitBoard = BitBoard ( 0x55AA55AA55AA55AA ) ;
20+
1421/// returns the benefit this side has from its pieces' positions
1522pub fn piece_position_benefit_for_side ( pos : & Board , color : Color , interp : Interp ) -> Value {
1623 let mut value = Value :: ZERO ;
@@ -48,6 +55,23 @@ pub fn sq_pi(sq: Square, color: Color) -> (usize, usize) {
4855 ( rank, file)
4956}
5057
58+ /// check how much are my bishops blocked by other pieces.
59+ ///
60+ /// issue: engine sacks bishops to minimise penalty
61+ #[ allow( dead_code) ]
62+ pub fn bishop_penalty ( pos : & Board , side : Color ) -> Value {
63+ let bishop_squares = pos. pieces ( Piece :: Bishop ) & pos. color_combined ( side) ;
64+ let mut penalty = Value :: ZERO ;
65+
66+ let dark_bishops = bishop_squares. bitand ( DARK_SQUARES ) ;
67+ let light_bishops = bishop_squares. bitand ( LIGHT_SQUARES ) ;
68+
69+ penalty += Value :: from ( ( pos. combined ( ) & DARK_SQUARES ) . popcnt ( ) * dark_bishops. popcnt ( ) ) ;
70+ penalty += Value :: from ( ( pos. combined ( ) & LIGHT_SQUARES ) . popcnt ( ) * light_bishops. popcnt ( ) ) ;
71+
72+ penalty
73+ }
74+
5175#[ cfg( test) ]
5276#[ path = "tests/positions.rs" ]
5377mod tests;
0 commit comments