bitstackchess 0.1.1

A bitboard‐based chess game engine with 10 × u128 move history
Documentation
//! A 10‐bit move: top‐4 bits = piece_within (0..15), low‐6 bits = dest_square (0..63).

#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct Move10(u16);

impl Move10 {
    /// Create a Move10 from (piece_id_within_side, dest_square).
    pub fn new(piece_id_within: u8, dest: u8) -> Move10 {
        assert!(piece_id_within < 16, "piece_id must fit in 4 bits");
        assert!(dest < 64, "dest must fit in 6 bits");
        let raw: u16 = ((piece_id_within as u16) << 6) | (dest as u16);
        Move10(raw & 0x03FF) // mask down to 10 bits
    }

    /// Extract piece_id_within (0..15).
    pub fn piece_id(&self) -> u8 {
        ((self.0 >> 6) as u8) & 0x0F
    }

    /// Extract dest_square (0..63).
    pub fn dest(&self) -> u8 {
        (self.0 as u8) & 0x3F
    }

    pub(crate) fn from_raw(raw: u16) -> Move10 {
        Move10(raw & 0x03FF)
    }

    pub fn bits(&self) -> u16 {
        self.0
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn roundtrip_move10() {
        for pid in 0..16u8 {
            for dst in 0..64u8 {
                let mv = Move10::new(pid, dst);
                assert_eq!(mv.piece_id(), pid);
                assert_eq!(mv.dest(), dst);
            }
        }
    }
}