diff --git a/engine/src/bitboard.rs b/engine/src/bitboard.rs index 405141f..1486484 100644 --- a/engine/src/bitboard.rs +++ b/engine/src/bitboard.rs @@ -4,5 +4,6 @@ mod legality; mod checkinfo; mod attacks; mod bitmove; +mod movebuffer; pub mod board; \ No newline at end of file diff --git a/engine/src/bitboard/movebuffer.rs b/engine/src/bitboard/movebuffer.rs new file mode 100644 index 0000000..61a7844 --- /dev/null +++ b/engine/src/bitboard/movebuffer.rs @@ -0,0 +1,44 @@ +use super::bitmove::BitMove; + +pub struct MoveBuffer { + + buffer: [BitMove; 256], + count: usize +} + +impl MoveBuffer { + + pub fn new() -> Self { + return Self { + buffer: [BitMove::quiet(0, 0, None); 256], + count: 0 + }; + } + + #[inline] + pub fn add(&mut self, bitmove: BitMove) { + self.buffer[self.count] = bitmove; + self.count += 1; + } + #[inline] + pub fn append(&mut self, other: &MoveBuffer) { + self.buffer[self.count..self.count + other.count()].copy_from_slice(other.contents()); + self.count += other.count(); + } + #[inline(always)] + pub fn clear(&mut self) { + self.count = 0; + } + #[inline(always)] + pub fn count(&self) -> usize{ + return self.count; + } + #[inline(always)] + pub fn get(&self, idx: usize) -> &BitMove { + return &self.buffer[idx]; + } + #[inline(always)] + pub fn contents(&self) -> &[BitMove] { + return &self.buffer[0..self.count]; + } +} \ No newline at end of file