[core,board] Update all use imports referring to Square, Rank, and File

This commit is contained in:
Eryn Wells 2024-01-24 08:32:09 -08:00
parent 3c3a62345d
commit 106800bcb3
16 changed files with 40 additions and 40 deletions

View file

@ -6,3 +6,4 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
chess_core = { path = "../chess_core" }

View file

@ -3,8 +3,9 @@
use crate::{ use crate::{
piece::{Piece, PlacedPiece}, piece::{Piece, PlacedPiece},
r#move::Castle, r#move::Castle,
Color, File, Position, Rank, Square, Color, Position,
}; };
use chess_core::{File, Rank, Square};
use std::fmt::Write; use std::fmt::Write;
#[derive(Clone, Copy, Debug, Eq, PartialEq)] #[derive(Clone, Copy, Debug, Eq, PartialEq)]
@ -42,7 +43,7 @@ impl ToFen for Position {
write!(fen_string, "{}", empty_squares).map_err(|err| FenError::FmtError(err))?; write!(fen_string, "{}", empty_squares).map_err(|err| FenError::FmtError(err))?;
empty_squares = 0; empty_squares = 0;
} }
if rank != &Rank::One { if rank != &Rank::ONE {
write!(fen_string, "/").map_err(|err| FenError::FmtError(err))?; write!(fen_string, "/").map_err(|err| FenError::FmtError(err))?;
} }
} }

View file

@ -16,6 +16,5 @@ mod sight;
pub use piece::{Color, Piece}; pub use piece::{Color, Piece};
pub use position::{MoveBuilder as MakeMoveBuilder, Position, PositionBuilder}; pub use position::{MoveBuilder as MakeMoveBuilder, Position, PositionBuilder};
pub use r#move::{Castle, MakeMoveError, Move, MoveBuilder}; pub use r#move::{Castle, MakeMoveError, Move, MoveBuilder};
pub use square::{File, Rank, Square};
pub(crate) use bitboard::BitBoard; pub(crate) use bitboard::BitBoard;

View file

@ -6,7 +6,7 @@ macro_rules! piece {
$crate::piece::Piece::new($crate::piece::Color::$color, $crate::piece::Shape::$shape) $crate::piece::Piece::new($crate::piece::Color::$color, $crate::piece::Shape::$shape)
}; };
($color:ident $shape:ident on $square:ident) => { ($color:ident $shape:ident on $square:ident) => {
$crate::piece::PlacedPiece::new(piece!($color $shape), $crate::square::Square::$square) $crate::piece::PlacedPiece::new(piece!($color $shape), chess_core::Square::$square)
} }
} }

View file

@ -1,10 +1,7 @@
// Eryn Wells <eryn@erynwells.me> // Eryn Wells <eryn@erynwells.me>
use crate::{ use crate::piece::{Piece, PlacedPiece, Shape};
piece::{Piece, PlacedPiece, Shape}, use chess_core::{Rank, Square};
square::Rank,
Square,
};
use std::fmt; use std::fmt;
pub use castle::Castle; pub use castle::Castle;
@ -20,7 +17,8 @@ pub enum MakeMoveError {
} }
mod castle { mod castle {
use crate::{Color, Square}; use crate::Color;
use chess_core::Square;
#[repr(u16)] #[repr(u16)]
#[derive(Copy, Clone, Debug, Eq, PartialEq)] #[derive(Copy, Clone, Debug, Eq, PartialEq)]
@ -248,8 +246,8 @@ impl MoveBuilder {
Shape::Pawn => { Shape::Pawn => {
let from_rank = from.rank(); let from_rank = from.rank();
let to_rank = to.rank(); let to_rank = to.rank();
let is_white_double_push = from_rank == Rank::Two && to_rank == Rank::Four; let is_white_double_push = from_rank == Rank::TWO && to_rank == Rank::FOUR;
let is_black_double_push = from_rank == Rank::Seven && to_rank == Rank::Five; let is_black_double_push = from_rank == Rank::SEVEN && to_rank == Rank::FIVE;
if is_white_double_push || is_black_double_push { if is_white_double_push || is_black_double_push {
Kind::DoublePush Kind::DoublePush
} else { } else {
@ -421,8 +419,8 @@ mod move_formatter {
$crate::piece::Color::$color, $crate::piece::Color::$color,
$crate::piece::Shape::$shape, $crate::piece::Shape::$shape,
), ),
$crate::Square::$from_square, chess_core::Square::$from_square,
$crate::Square::$to_square, chess_core::Square::$to_square,
) )
.build() .build()
}; };
@ -432,15 +430,15 @@ mod move_formatter {
$crate::piece::Color::$color, $crate::piece::Color::$color,
$crate::piece::Shape::$shape, $crate::piece::Shape::$shape,
), ),
$crate::Square::$from_square, chess_core::Square::$from_square,
$crate::Square::$to_square, chess_core::Square::$to_square,
) )
.capturing($crate::piece::PlacedPiece::new( .capturing($crate::piece::PlacedPiece::new(
$crate::piece::Piece::new( $crate::piece::Piece::new(
$crate::piece::Color::$captured_color, $crate::piece::Color::$captured_color,
$crate::piece::Shape::$captured_shape, $crate::piece::Shape::$captured_shape,
), ),
$crate::Square::$to_square, chess_core::Square::$to_square,
)) ))
.build() .build()
}; };

View file

@ -3,9 +3,9 @@
use super::{move_generator_declaration, MoveGeneratorInternal, MoveSet}; use super::{move_generator_declaration, MoveGeneratorInternal, MoveSet};
use crate::{ use crate::{
piece::{Color, Piece, PlacedPiece}, piece::{Color, Piece, PlacedPiece},
square::Direction,
BitBoard, MoveBuilder, Position, BitBoard, MoveBuilder, Position,
}; };
use chess_core::Direction;
move_generator_declaration!(ClassicalMoveGenerator); move_generator_declaration!(ClassicalMoveGenerator);

View file

@ -3,9 +3,9 @@
use super::{move_generator_declaration, MoveGeneratorInternal, MoveSet}; use super::{move_generator_declaration, MoveGeneratorInternal, MoveSet};
use crate::{ use crate::{
piece::{Color, Piece, PlacedPiece}, piece::{Color, Piece, PlacedPiece},
square::Direction,
BitBoard, MoveBuilder, Position, BitBoard, MoveBuilder, Position,
}; };
use chess_core::Direction;
move_generator_declaration!(ClassicalMoveGenerator); move_generator_declaration!(ClassicalMoveGenerator);

View file

@ -3,9 +3,9 @@
use super::{move_generator_declaration, MoveGeneratorInternal, MoveSet}; use super::{move_generator_declaration, MoveGeneratorInternal, MoveSet};
use crate::{ use crate::{
piece::{Color, Piece, PlacedPiece}, piece::{Color, Piece, PlacedPiece},
square::Direction,
BitBoard, MoveBuilder, Position, BitBoard, MoveBuilder, Position,
}; };
use chess_core::Direction;
move_generator_declaration!(ClassicalMoveGenerator); move_generator_declaration!(ClassicalMoveGenerator);
@ -62,9 +62,8 @@ impl<'pos> MoveGeneratorInternal for ClassicalMoveGenerator<'pos> {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use crate::{ use crate::{piece::Piece, position, position::DiagramFormatter, BitBoard, Color, Position};
piece::Piece, position, position::DiagramFormatter, BitBoard, Color, Position, Square, use chess_core::Square;
};
#[test] #[test]
fn classical_single_rook_bitboard() { fn classical_single_rook_bitboard() {

View file

@ -1,9 +1,7 @@
// Eryn Wells <eryn@erynwells.me> // Eryn Wells <eryn@erynwells.me>
use crate::{ use crate::display::{ASCIIDisplay, FENDisplay, UnicodeDisplay};
display::{ASCIIDisplay, FENDisplay, UnicodeDisplay}, use chess_core::Square;
Square,
};
use std::fmt; use std::fmt;
use std::slice::Iter; use std::slice::Iter;

View file

@ -4,9 +4,9 @@ use crate::{
piece::{PlacedPiece, Shape}, piece::{PlacedPiece, Shape},
position::flags::Flags, position::flags::Flags,
r#move::Castle, r#move::Castle,
square::Direction, BitBoard, Color, MakeMoveError, Move, Piece, Position,
BitBoard, Color, MakeMoveError, Move, Piece, Position, Square,
}; };
use chess_core::{Direction, Square};
/// A position builder that builds a new position by making a move. /// A position builder that builds a new position by making a move.
#[derive(Clone)] #[derive(Clone)]

View file

@ -5,9 +5,9 @@ use crate::{
piece::{PlacedPiece, Shape}, piece::{PlacedPiece, Shape},
position::{flags::Flags, piece_sets::PieceBitBoards}, position::{flags::Flags, piece_sets::PieceBitBoards},
r#move::Castle, r#move::Castle,
square::{Direction, Rank}, BitBoard, Color, MakeMoveError, Move, Piece, Position,
BitBoard, Color, MakeMoveError, Move, Piece, Position, Square,
}; };
use chess_core::{Rank, Square};
use std::collections::BTreeMap; use std::collections::BTreeMap;
#[derive(Clone)] #[derive(Clone)]
@ -100,7 +100,7 @@ impl Builder {
// Pawns cannot be placed on the first (back) rank of their side, // Pawns cannot be placed on the first (back) rank of their side,
// and cannot be placed on the final rank without a promotion. // and cannot be placed on the final rank without a promotion.
let rank = piece.square().rank(); let rank = piece.square().rank();
return rank != Rank::One && rank != Rank::Eight; return rank != Rank::ONE && rank != Rank::EIGHT;
} }
true true

View file

@ -1,6 +1,7 @@
// Eryn Wells <eryn@erynwells.me> // Eryn Wells <eryn@erynwells.me>
use crate::{File, Position, Rank, Square}; use crate::Position;
use chess_core::{File, Rank, Square};
use std::fmt; use std::fmt;
pub struct DiagramFormatter<'a>(&'a Position); pub struct DiagramFormatter<'a>(&'a Position);

View file

@ -2,8 +2,9 @@
use crate::{ use crate::{
piece::{Piece, PlacedPiece}, piece::{Piece, PlacedPiece},
BitBoard, Color, Square, BitBoard, Color,
}; };
use chess_core::Square;
#[derive(Debug, Eq, PartialEq)] #[derive(Debug, Eq, PartialEq)]
pub enum PlacePieceStrategy { pub enum PlacePieceStrategy {

View file

@ -3,7 +3,7 @@
use super::Position; use super::Position;
use crate::piece::{Color, Piece, PlacedPiece, Shape}; use crate::piece::{Color, Piece, PlacedPiece, Shape};
use crate::BitBoard; use crate::BitBoard;
use crate::Square; use chess_core::Square;
pub struct Pieces<'a> { pub struct Pieces<'a> {
color: Color, color: Color,
@ -76,7 +76,6 @@ impl<'a> Iterator for Pieces<'a> {
mod tests { mod tests {
use super::*; use super::*;
use crate::piece::{Color, Piece, Shape}; use crate::piece::{Color, Piece, Shape};
use crate::Square;
use crate::{Position, PositionBuilder}; use crate::{Position, PositionBuilder};
use std::collections::HashSet; use std::collections::HashSet;

View file

@ -7,8 +7,9 @@ use crate::{
position::DiagramFormatter, position::DiagramFormatter,
r#move::Castle, r#move::Castle,
sight::Sight, sight::Sight,
BitBoard, Move, Square, BitBoard, Move,
}; };
use chess_core::Square;
use std::{cell::OnceCell, fmt}; use std::{cell::OnceCell, fmt};
#[derive(Clone, Debug, Eq, PartialEq)] #[derive(Clone, Debug, Eq, PartialEq)]
@ -266,7 +267,8 @@ impl fmt::Display for Position {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crate::{position, Castle, Color, Position, Square}; use crate::{position, Castle, Color, Position};
use chess_core::Square;
#[test] #[test]
fn piece_on_square() { fn piece_on_square() {

View file

@ -2,9 +2,9 @@
use crate::{ use crate::{
piece::{Color, PlacedPiece, Shape}, piece::{Color, PlacedPiece, Shape},
square::Direction,
BitBoard, Position, BitBoard, Position,
}; };
use chess_core::Direction;
pub(crate) trait Sight { pub(crate) trait Sight {
fn sight_in_position(&self, position: &Position) -> BitBoard; fn sight_in_position(&self, position: &Position) -> BitBoard;
@ -174,7 +174,8 @@ mod tests {
} }
mod pawn { mod pawn {
use crate::{sight::Sight, BitBoard, Square}; use crate::{sight::Sight, BitBoard};
use chess_core::Square;
sight_test!(e4_pawn, piece!(White Pawn on E4), bitboard!(D5, F5)); sight_test!(e4_pawn, piece!(White Pawn on E4), bitboard!(D5, F5));