[board, moves, position] Move make_move routines to moves crate

Declare a MakeMove trait and export it from chessfriend_moves. Declare a
BoardProvider trait that both Board and Position implement.

Implement the MakeMove trait for all types that implement BoardProvider, and move
all the move making code to the moves crate.

This change makes it possible to make moves directly on a Board, rather than
requiring a Position. The indirection of declaring and implementing the trait
in the moves crate is required because chessfriend_board is a dependency of
chessfriend_moves. So, it would be a layering violation for Board to implement
make_move() directly. The board crate cannot link the moves crate because that
would introduce a circular dependency.
This commit is contained in:
Eryn Wells 2025-05-31 19:01:20 -07:00
parent ecde338602
commit 40e8e055f9
7 changed files with 202 additions and 163 deletions

View file

@ -0,0 +1,18 @@
// Eryn Wells <eryn@erynwells.me>
use crate::Board;
pub trait BoardProvider {
fn board(&self) -> &Board;
fn board_mut(&mut self) -> &mut Board;
}
impl BoardProvider for Board {
fn board(&self) -> &Board {
self
}
fn board_mut(&mut self) -> &mut Board {
self
}
}

View file

@ -9,10 +9,12 @@ pub mod macros;
pub mod movement;
pub mod sight;
mod board_provider;
mod check;
mod piece_sets;
pub use board::Board;
pub use board_provider::BoardProvider;
pub use castle::Parameters as CastleParameters;
pub use castle::Rights as CastleRights;
pub use piece_sets::{PlacePieceError, PlacePieceStrategy};