[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:
parent
ecde338602
commit
40e8e055f9
7 changed files with 202 additions and 163 deletions
|
@ -1,7 +1,6 @@
|
|||
// Eryn Wells <eryn@erynwells.me>
|
||||
|
||||
mod captures;
|
||||
mod make_move;
|
||||
mod unmake_move;
|
||||
|
||||
use chessfriend_moves::{
|
||||
|
@ -9,14 +8,14 @@ use chessfriend_moves::{
|
|||
AllPiecesMoveGenerator, BishopMoveGenerator, KingMoveGenerator, KnightMoveGenerator,
|
||||
PawnMoveGenerator, QueenMoveGenerator, RookMoveGenerator,
|
||||
},
|
||||
GeneratedMove, Move, MoveRecord,
|
||||
GeneratedMove, MakeMove, Move, MoveRecord, ValidateMove,
|
||||
};
|
||||
pub use make_move::ValidateMove;
|
||||
|
||||
use captures::CapturesList;
|
||||
use chessfriend_bitboard::BitBoard;
|
||||
use chessfriend_board::{
|
||||
display::DiagramFormatter, fen::ToFenStr, Board, PlacePieceError, PlacePieceStrategy,
|
||||
display::DiagramFormatter, fen::ToFenStr, Board, BoardProvider, PlacePieceError,
|
||||
PlacePieceStrategy,
|
||||
};
|
||||
use chessfriend_core::{Color, Piece, Shape, Square};
|
||||
use std::fmt;
|
||||
|
@ -142,6 +141,16 @@ impl ToFenStr for Position {
|
|||
}
|
||||
}
|
||||
|
||||
impl BoardProvider for Position {
|
||||
fn board(&self) -> &Board {
|
||||
&self.board
|
||||
}
|
||||
|
||||
fn board_mut(&mut self) -> &mut Board {
|
||||
&mut self.board
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq for Position {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.board == other.board
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue