Skip to content

Commit a7e1675

Browse files
authored
Add type_on to simplify some code (#912)
No functional change. Bench: 3344311
1 parent 9d0b288 commit a7e1675

4 files changed

Lines changed: 12 additions & 8 deletions

File tree

src/board.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,10 @@ impl Board {
184184
self.colored_pieces(color, PieceType::King).lsb()
185185
}
186186

187+
pub fn type_on(&self, square: Square) -> PieceType {
188+
self.mailbox[square].piece_type()
189+
}
190+
187191
pub fn piece_on(&self, square: Square) -> Piece {
188192
self.mailbox[square]
189193
}

src/board/see.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ impl super::Board {
8989
}
9090

9191
fn move_value(&self, mv: Move) -> i32 {
92-
let capture = self.piece_on(mv.capture_sq()).piece_type();
92+
let capture = self.type_on(mv.capture_sq());
9393
let mut value = capture.value();
9494

9595
if mv.is_promotion() {

src/movepick.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,8 @@ impl MovePicker {
158158

159159
for entry in self.list.iter_mut() {
160160
let mv = entry.mv;
161-
let captured = td.board.piece_on(mv.capture_sq()).piece_type();
162-
let pt = td.board.piece_on(mv.from()).piece_type();
161+
let captured = td.board.type_on(mv.capture_sq());
162+
let pt = td.board.type_on(mv.from());
163163

164164
entry.score = 16 * captured.value()
165165
+ td.noisy_history.get(threats, td.board.moved_piece(mv), mv.to(), captured)
@@ -213,7 +213,7 @@ impl MovePicker {
213213

214214
for entry in self.list.iter_mut() {
215215
let mv = entry.mv;
216-
let pt = td.board.piece_on(mv.from()).piece_type();
216+
let pt = td.board.type_on(mv.from());
217217

218218
entry.score = 2048 * td.quiet_history.get(threats, side, mv) / 1024
219219
+ 1536 * td.conthist(ply, 1, mv) / 1024

src/search.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,7 @@ fn search<NODE: NodeType>(
725725
let history = if is_quiet {
726726
td.quiet_history.get(td.board.all_threats(), stm, mv) + td.conthist(ply, 1, mv) + td.conthist(ply, 2, mv)
727727
} else {
728-
let captured = td.board.piece_on(mv.to()).piece_type();
728+
let captured = td.board.type_on(mv.to());
729729
td.noisy_history.get(td.board.all_threats(), td.board.moved_piece(mv), mv.to(), captured)
730730
};
731731

@@ -1029,7 +1029,7 @@ fn search<NODE: NodeType>(
10291029
td.board.all_threats(),
10301030
td.board.moved_piece(best_move),
10311031
best_move.to(),
1032-
td.board.piece_on(best_move.to()).piece_type(),
1032+
td.board.type_on(best_move.to()),
10331033
noisy_bonus,
10341034
);
10351035
} else {
@@ -1043,7 +1043,7 @@ fn search<NODE: NodeType>(
10431043
}
10441044

10451045
for &mv in noisy_moves.iter() {
1046-
let captured = td.board.piece_on(mv.to()).piece_type();
1046+
let captured = td.board.type_on(mv.to());
10471047
td.noisy_history.update(td.board.all_threats(), td.board.moved_piece(mv), mv.to(), captured, -noisy_malus);
10481048
}
10491049

@@ -1292,7 +1292,7 @@ fn qsearch<NODE: NodeType>(td: &mut ThreadData, mut alpha: i32, beta: i32, ply:
12921292
td.board.all_threats(),
12931293
td.board.moved_piece(best_move),
12941294
best_move.to(),
1295-
td.board.piece_on(best_move.to()).piece_type(),
1295+
td.board.type_on(best_move.to()),
12961296
bonus,
12971297
);
12981298
} else {

0 commit comments

Comments
 (0)