Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add custom Default implementations for PawnStructure and PawnCacheEntry #311

Merged
merged 1 commit into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions simbelmyne/src/evaluate/pawn_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::zobrist::ZHash;

use super::{pawn_structure::PawnStructure, S};

#[derive(Copy, Clone, Debug, Default)]
#[derive(Copy, Clone, Debug)]
pub struct PawnCacheEntry {
pub hash: ZHash,
pub score: S,
Expand All @@ -15,6 +15,18 @@ pub struct PawnCacheEntry {
pub outposts: [Bitboard; 2]
}

impl Default for PawnCacheEntry {
fn default() -> Self {
Self {
hash: ZHash::NULL,
score: S::default(),
passers: [Bitboard::EMPTY, Bitboard::EMPTY],
semi_opens: [!Bitboard::EMPTY, !Bitboard::EMPTY],
outposts: [Bitboard::EMPTY, Bitboard::EMPTY]
}
}
}

impl PawnCacheEntry {
pub fn new(hash: ZHash, pawn_structure: PawnStructure) -> Self {
Self {
Expand Down Expand Up @@ -51,11 +63,11 @@ impl PawnCache {

// Check whether the hash appears in the transposition table, and return it
// if so.
//
pub fn probe(&self, hash: ZHash) -> Option<PawnCacheEntry> {
let key = ZKey::from_hash(hash, self.size);

self.table.get(key.0)
// .filter(|_| hash != ZHash::NULL)
.filter(|entry| entry.hash == hash)
.copied()
}
Expand Down
13 changes: 12 additions & 1 deletion simbelmyne/src/evaluate/pawn_structure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use super::{Score, S};
const WHITE: bool = true;
const BLACK: bool = false;

#[derive(Debug, Copy, Clone, PartialEq, Eq, Default)]
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub struct PawnStructure {
/// The score associated with the pawn structure
pub score: S,
Expand All @@ -30,6 +30,17 @@ pub struct PawnStructure {
pub outposts: [Bitboard; Color::COUNT],
}

impl Default for PawnStructure {
fn default() -> Self {
Self {
score: S::default(),
passed_pawns: [Bitboard::EMPTY, Bitboard::EMPTY],
semi_open_files: [!Bitboard::EMPTY, !Bitboard::EMPTY],
outposts: [!Bitboard::EMPTY, !Bitboard::EMPTY]
}
}
}

impl PawnStructure {
pub fn new(board: &Board, mut trace: &mut impl Trace) -> Self {
// Pawn bitboardds
Expand Down
Loading