diff --git a/src/main.rs b/src/main.rs index c315fdd..94d6512 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,7 +2,7 @@ use std::sync::LazyLock; use gamemanager::GameManager; -use movetable::MoveTable; +use movetable::{noarc, MoveTable}; mod bitboard; mod gamemanager; @@ -13,6 +13,8 @@ mod ucimanager; pub static MOVETABLE: LazyLock = std::sync::LazyLock::new(MoveTable::default); fn main() { + let movetable = noarc::NoArc::new(MoveTable::default()); + let gm = GameManager::from_fen_string("rnbq1k1r/pp1Pbppp/2p5/8/2B5/8/PPP1NnPP/RNBQK2R w KQ - 1 8"); let mvlst = gm.legal_moves(); diff --git a/src/movetable/mod.rs b/src/movetable/mod.rs index 7a24ffa..744f296 100644 --- a/src/movetable/mod.rs +++ b/src/movetable/mod.rs @@ -1,6 +1,8 @@ use crate::types::{Color, PieceType}; use dashmap::DashMap; +pub mod noarc; + /// A HashMap of [`(Color, PieceType, u64)`] indexing [`Vec>`] where /// the index integer is a position on the board (must be a power of two) and /// the list of lists is a list of rays---that is, each direction the object diff --git a/src/movetable/noarc.rs b/src/movetable/noarc.rs new file mode 100644 index 0000000..f7a46b0 --- /dev/null +++ b/src/movetable/noarc.rs @@ -0,0 +1,24 @@ +use std::ops::Deref; + +#[derive(Clone)] +pub struct NoArc { + ptr: *mut T, +} + +impl NoArc { + pub fn new(val: T) -> Self { + Self { + ptr: Box::leak(Box::new(val)), + } + } +} + +unsafe impl Sync for NoArc {} +unsafe impl Send for NoArc {} + +impl Deref for NoArc { + type Target = T; + fn deref(&self) -> &Self::Target { + unsafe { self.ptr.as_ref().unwrap() } + } +}