Skip to content

Commit e034a35

Browse files
authored
Add movepicker bonus for moving out of harm (#737)
STC Elo | 1.97 +- 1.55 (95%) SPRT | 8.0+0.08s Threads=1 Hash=16MB LLR | 2.97 (-2.25, 2.89) [0.00, 3.00] Games | N: 51546 W: 13168 L: 12875 D: 25503 Penta | [171, 6028, 13107, 6271, 196] https://recklesschess.space/test/11753/ LTC Elo | 2.10 +- 1.63 (95%) SPRT | 40.0+0.40s Threads=1 Hash=64MB LLR | 2.90 (-2.25, 2.89) [0.00, 3.00] Games | N: 40808 W: 10066 L: 9819 D: 20923 Penta | [14, 4570, 10987, 4821, 12] https://recklesschess.space/test/11756/ Bench: 3652336
1 parent 8690d82 commit e034a35

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

src/movepick.rs

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use crate::{
2+
lookup::{bishop_attacks, knight_attacks, pawn_attacks_setwise, rook_attacks},
23
search::NodeType,
34
thread::ThreadData,
4-
types::{ArrayVec, MAX_MOVES, Move, MoveList, PieceType},
5+
types::{ArrayVec, Bitboard, MAX_MOVES, Move, MoveList, PieceType},
56
};
67

78
#[derive(Copy, Clone, Eq, PartialEq, PartialOrd)]
@@ -181,6 +182,29 @@ impl MovePicker {
181182
fn score_quiet(&mut self, td: &ThreadData, ply: isize) {
182183
let threats = td.board.threats();
183184
let side = td.board.side_to_move();
185+
let occ = td.board.occupancies();
186+
187+
let pawn_threats = pawn_attacks_setwise(td.board.their(PieceType::Pawn), !side);
188+
189+
let mut minor_threats = Bitboard(0);
190+
for square in td.board.their(PieceType::Knight) {
191+
minor_threats |= knight_attacks(square);
192+
}
193+
for square in td.board.their(PieceType::Bishop) {
194+
minor_threats |= bishop_attacks(square, occ);
195+
}
196+
minor_threats |= pawn_threats;
197+
198+
let mut rook_threats = Bitboard(0);
199+
for square in td.board.their(PieceType::Rook) {
200+
rook_threats |= rook_attacks(square, occ);
201+
}
202+
rook_threats |= minor_threats;
203+
204+
let threatened = (td.board.our(PieceType::Queen) & rook_threats)
205+
| (td.board.our(PieceType::Rook) & minor_threats)
206+
| (td.board.our(PieceType::Knight) & pawn_threats)
207+
| (td.board.our(PieceType::Bishop) & pawn_threats);
184208

185209
for entry in self.list.iter_mut() {
186210
let mv = entry.mv;
@@ -196,6 +220,18 @@ impl MovePicker {
196220
+ td.conthist(ply, 4, mv)
197221
+ td.conthist(ply, 6, mv);
198222

223+
// bonus for escaping capture
224+
if threatened.contains(mv.from()) {
225+
let pt = td.board.piece_on(mv.from()).piece_type();
226+
if pt == PieceType::Queen {
227+
entry.score += 20000;
228+
} else if pt == PieceType::Rook {
229+
entry.score += 10000;
230+
} else if pt != PieceType::Pawn {
231+
entry.score += 4000;
232+
}
233+
}
234+
199235
// Bonus for checking moves
200236
if td.board.checking_squares(td.board.moved_piece(mv).piece_type()).contains(mv.to()) {
201237
entry.score += 10000;

0 commit comments

Comments
 (0)