From 46e9fcdcce5730827355db9449c41dc0a0e42b1f Mon Sep 17 00:00:00 2001 From: eug-vs Date: Tue, 21 Feb 2023 05:22:54 +0300 Subject: refactor: use bitboard trait --- src/board/engine.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/board/engine.rs') diff --git a/src/board/engine.rs b/src/board/engine.rs index ad2b3b2..5168350 100644 --- a/src/board/engine.rs +++ b/src/board/engine.rs @@ -1,5 +1,5 @@ use std::{time::{Instant, Duration}, f32::INFINITY, cmp::Ordering}; -use crate::{bitboard::pop_count, board::*}; +use crate::board::*; use super::ttable::{NodeType, TranspositionTableItem}; @@ -171,7 +171,7 @@ impl Board { _ => panic!("Unreachable") }; - material += serialize_bitboard(*bitboard).iter().fold(0., |acc, square| { + material += bitboard.serialize().iter().fold(0., |acc, square| { acc + piece_type.static_eval() + bonus_table[ match color { Color::White => square.mirror() as usize, @@ -195,7 +195,7 @@ impl Board { for file in 0..8 { let file_mask = A_FILE << file; - let pawns_on_file = pop_count(pawns & file_mask) as f32; + let pawns_on_file = (pawns & file_mask).pop_count() as f32; // Doubled pawns (-1 because one pawn on a file is ok) result += (pawns_on_file - 1.).max(0.0); @@ -214,7 +214,7 @@ impl Board { Color::White => self.occupancy >> 8, Color::Black => self.occupancy << 8, }; - result += pop_count(pawns & blocked_mask) as f32; + result += (pawns & blocked_mask).pop_count() as f32; result } @@ -224,14 +224,14 @@ impl Board { pub fn king_tropism(&self, color: Color) -> f32 { let mut result = 0.0; - let king_square = bitscan(match color { + let king_square = match color { Color::White => self.pieces[PieceType::King as usize], Color::Black => self.pieces[PieceType::KingBlack as usize], - }); + }.bitscan(); for (piece_type, bitboard) in self.pieces_by_color(color.flip()).iter().enumerate() { if piece_type != PieceType::King as usize && piece_type != PieceType::Pawn as usize { - for square in serialize_bitboard(*bitboard) { + for square in bitboard.serialize() { let distance = (king_square.rank() as f32 - square.rank() as f32).abs() + (king_square.file() as f32 - square.file() as f32).abs(); -- cgit v1.2.3