[board] Reorganize bitboard and position modules and export some symbols from the crate

Move position.rs to the position module and create a mod.rs.
Do the same for bitboard.rs in the bitboard modules.
Export Color, Piece, Position, and Square and use crate::Thing directly instead of referring to the symbol in the nested modules.
This commit is contained in:
Eryn Wells 2023-12-26 11:25:27 -07:00
parent d2d33a4915
commit 758a3d95fc
7 changed files with 32 additions and 18 deletions

View file

@ -1,9 +1,7 @@
// Eryn Wells <eryn@erynwells.me>
mod bit_scanner;
use self::bit_scanner::BitScanner;
use crate::square::Square;
use super::BitScanner;
use crate::Square;
use std::fmt;
use std::ops::{BitAnd, BitOr, Not};
@ -154,7 +152,7 @@ impl BitOr<&BitBoard> for BitBoard {
#[cfg(test)]
mod tests {
use super::*;
use crate::square::Square;
use crate::Square;
#[test]
fn is_empty() {

View file

@ -0,0 +1,5 @@
mod bit_scanner;
mod bitboard;
pub(crate) use self::bit_scanner::BitScanner;
pub(crate) use self::bitboard::BitBoard;

View file

@ -3,3 +3,7 @@ mod neighbor;
mod piece;
mod position;
mod square;
pub use piece::{Color, Piece};
pub use position::Position;
pub use square::Square;

View file

@ -1,6 +1,6 @@
// Eryn Wells <eryn@erynwells.me>
use crate::square::Square;
use crate::Square;
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub enum Color {

View file

@ -0,0 +1,5 @@
mod pieces;
mod position;
pub use pieces::Pieces;
pub use position::Position;

View file

@ -1,10 +1,9 @@
// Eryn Wells <eryn@erynwells.me>
use super::Position;
use crate::bitboard::BitBoard;
use crate::piece::{Color, Piece, PlacedPiece, Shape};
use crate::position::Position;
use crate::square::Square;
use std::collections::HashSet;
use crate::Square;
pub struct Pieces<'a> {
color: Color,
@ -89,8 +88,9 @@ impl<'a> Iterator for Pieces<'a> {
mod tests {
use super::*;
use crate::piece::{Color, Piece, Shape};
use crate::position::Position;
use crate::square::Square;
use crate::Position;
use crate::Square;
use std::collections::HashSet;
fn square_at(sq: &str) -> Square {
Square::from_algebraic_string(sq).expect(sq)

View file

@ -1,11 +1,9 @@
// Eryn Wells <eryn@erynwells.me>
mod pieces;
use self::pieces::Pieces;
use super::Pieces;
use crate::bitboard::BitBoard;
use crate::square::Square;
use crate::piece::{Color, Piece, PiecePlacementError};
use crate::Square;
use std::fmt;
use std::fmt::Write;
@ -21,7 +19,7 @@ pub struct Position {
}
impl Position {
fn empty() -> Position {
pub fn empty() -> Position {
Position {
color_to_move: Color::White,
pieces_per_color: [BitBoard::empty(), BitBoard::empty()],
@ -76,7 +74,11 @@ impl Position {
}
}
fn place_piece(&mut self, piece: &Piece, square: &Square) -> Result<(), PiecePlacementError> {
pub fn place_piece(
&mut self,
piece: &Piece,
square: &Square,
) -> Result<(), PiecePlacementError> {
let bitboard = self.bitboard_for_piece_mut(piece);
if bitboard.has_piece_at(&square) {
@ -96,7 +98,7 @@ impl Position {
&mut self.pieces_per_type[piece.color as usize][piece.shape as usize]
}
fn pieces(&self, color: Color) -> Pieces {
pub fn pieces(&self, color: Color) -> Pieces {
Pieces::new(&self, color)
}
}