[board] Implement PositionBuilder::from_position
Create a PositionBuilder from a Position.
This commit is contained in:
parent
c1008ef672
commit
bf2bccbc7d
1 changed files with 21 additions and 0 deletions
|
@ -25,6 +25,27 @@ impl Builder {
|
|||
Self::default()
|
||||
}
|
||||
|
||||
pub fn from_position(position: &Position) -> Self {
|
||||
let pieces = BTreeMap::from_iter(
|
||||
position
|
||||
.pieces(Color::White)
|
||||
.chain(position.pieces(Color::Black))
|
||||
.map(|placed_piece| (placed_piece.square(), *placed_piece.piece())),
|
||||
);
|
||||
|
||||
let white_king = position.king_square(Color::White);
|
||||
let black_king = position.king_square(Color::Black);
|
||||
|
||||
Self {
|
||||
player_to_move: position.player_to_move(),
|
||||
flags: position.flags(),
|
||||
pieces,
|
||||
kings: [white_king, black_king],
|
||||
ply_counter: position.ply_counter(),
|
||||
move_number: position.move_number(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_move(&mut self, player: Color) -> &mut Self {
|
||||
self.player_to_move = player;
|
||||
self
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue