implement iterability for theatened()
This commit is contained in:
parent
88e1c43781
commit
960f06c4f4
@ -109,11 +109,9 @@ impl Board {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_fen(fen: String) -> Self {
|
pub fn from_fen(fen: String) -> Self {
|
||||||
trace!("{fen}");
|
|
||||||
let mut pos = Board::default();
|
let mut pos = Board::default();
|
||||||
let mut parts = fen.split_whitespace();
|
let mut parts = fen.split_whitespace();
|
||||||
|
|
||||||
trace!("{:?}", parts);
|
|
||||||
// parse board
|
// parse board
|
||||||
parts.next().unwrap().split('/').enumerate().for_each(|(y, row)| {
|
parts.next().unwrap().split('/').enumerate().for_each(|(y, row)| {
|
||||||
let mut x = 0;
|
let mut x = 0;
|
||||||
@ -245,16 +243,14 @@ impl Board {
|
|||||||
let check = self.check_init();
|
let check = self.check_init();
|
||||||
self.mut_ref_position().ref_set_check(check);
|
self.mut_ref_position().ref_set_check(check);
|
||||||
let castl_possibilities = self.castling_possibilities_init();
|
let castl_possibilities = self.castling_possibilities_init();
|
||||||
trace!("{self:?}");
|
|
||||||
self.mut_ref_position().ref_set_castle_possibilities(castl_possibilities);
|
self.mut_ref_position().ref_set_castle_possibilities(castl_possibilities);
|
||||||
let moves = self.valid_moves_init();
|
let moves = self.valid_moves_init();
|
||||||
// self.mut_ref_position().ref_set_moves(moves);
|
self.mut_ref_position().ref_set_moves(moves);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_init(&mut self) -> Option<bool> {
|
fn check_init(&mut self) -> Option<bool> {
|
||||||
let whites_turn = self.ref_whites_turn();
|
let whites_turn = self.ref_whites_turn();
|
||||||
trace!("{whites_turn}");
|
|
||||||
let attacker = self.threatened_by(self.king_pos(*whites_turn));
|
let attacker = self.threatened_by(self.king_pos(*whites_turn));
|
||||||
match attacker.len() {
|
match attacker.len() {
|
||||||
0 => None,
|
0 => None,
|
||||||
@ -332,7 +328,6 @@ impl Board {
|
|||||||
square.y() as i8 + change.ref_y() < 0 || square.y() as i8 + change.ref_y() > 7 {
|
square.y() as i8 + change.ref_y() < 0 || square.y() as i8 + change.ref_y() > 7 {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
trace!("{:?}:{:?} => {}:{:?}", {square.x() as i8 + change.ref_x()}, {square.y() as i8 + change.ref_y()}, {if to_move {"w".to_string()} else {"b".to_string()}}, variant);
|
|
||||||
if self.ref_rows()
|
if self.ref_rows()
|
||||||
[(square.x() as i8 + change.ref_x()) as usize]
|
[(square.x() as i8 + change.ref_x()) as usize]
|
||||||
[(square.y() as i8 + change.ref_y()) as usize] ==
|
[(square.y() as i8 + change.ref_y()) as usize] ==
|
||||||
@ -353,20 +348,28 @@ impl Board {
|
|||||||
changes = MoveVariant::variant_move(variant.borrow());
|
changes = MoveVariant::variant_move(variant.borrow());
|
||||||
for mut change in changes {
|
for mut change in changes {
|
||||||
change = change.reverse();
|
change = change.reverse();
|
||||||
if square.x() as i8 + change.ref_x() < 0 || square.x() as i8 + change.ref_x() > 7 ||
|
let mut multiplier = 1;
|
||||||
square.y() as i8 + change.ref_y() < 0 || square.y() as i8 + change.ref_y() > 7 {
|
|
||||||
continue;
|
loop {
|
||||||
}
|
multiplier += 1;
|
||||||
trace!("{:?}:{:?} => {}:{:?}", {square.x() as i8 + change.ref_x()}, {square.y() as i8 + change.ref_y()}, {if to_move {"w".to_string()} else {"b".to_string()}}, variant);
|
if square.x() as i8 + change.ref_x() * multiplier < 0 || square.x() as i8 + change.ref_x() * multiplier > 7 ||
|
||||||
if self.ref_rows()
|
square.y() as i8 + change.ref_y() * multiplier < 0 || square.y() as i8 + change.ref_y() * multiplier > 7 ||
|
||||||
[(square.x() as i8 + change.ref_x()) as usize]
|
self.used(Square::new((square.x() as i8 + change.ref_x() * multiplier) as u8, (square.y() as i8 + change.ref_y() * multiplier) as u8)) {
|
||||||
[(square.y() as i8 + change.ref_y()) as usize] ==
|
break;
|
||||||
Some(Piece::new(to_move, variant.as_piece_variant())) {
|
}
|
||||||
trace!("matched: {:?}:{:?}", {square.x() as i8 + change.ref_x()}, {square.y() as i8 + change.ref_y()});
|
|
||||||
attacker.push(Square::new(
|
if self.ref_rows()
|
||||||
(square.x() as i8 + change.ref_x()) as u8,
|
[(square.y() as i8 + change.ref_y()) as usize]
|
||||||
(square.y() as i8 + change.ref_y()) as u8,
|
[(square.x() as i8 + change.ref_x()) as usize] ==
|
||||||
));
|
Some(Piece::new(!to_move, variant.as_piece_variant())) {
|
||||||
|
attacker.push(Square::new(
|
||||||
|
(square.x() as i8 + change.ref_x()) as u8,
|
||||||
|
(square.y() as i8 + change.ref_y()) as u8,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
if !variant.iterable() {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -146,6 +146,27 @@ impl MoveVariant {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn iterable(&self) -> bool {
|
||||||
|
match self {
|
||||||
|
Self::King => false,
|
||||||
|
Self::KingCastle => false,
|
||||||
|
Self::Queen => true,
|
||||||
|
Self::Rook => true,
|
||||||
|
Self::Bishop => true,
|
||||||
|
Self::Knight => false,
|
||||||
|
Self::PawnWhite => false,
|
||||||
|
Self::PawnWhiteDouble => false,
|
||||||
|
Self::PawnWhiteEnPassent => false,
|
||||||
|
Self::PawnWhiteCaptureLeft => false,
|
||||||
|
Self::PawnWhiteCaptureRight => false,
|
||||||
|
Self::PawnBlack => false,
|
||||||
|
Self::PawnBlackDouble => false,
|
||||||
|
Self::PawnBlackEnPassent => false,
|
||||||
|
Self::PawnBlackCaptureLeft => false,
|
||||||
|
Self::PawnBlackCaptureRight => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn as_piece_variant(&self) -> PieceVariant {
|
pub fn as_piece_variant(&self) -> PieceVariant {
|
||||||
match self {
|
match self {
|
||||||
Self::King => PieceVariant::King,
|
Self::King => PieceVariant::King,
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
|
|
||||||
use crate::{chess::board::Board, config::get_config};
|
use crate::{chess::board::Board, config::get_config};
|
||||||
use log::trace;
|
use log::{debug, info, trace};
|
||||||
|
|
||||||
mod chess;
|
mod chess;
|
||||||
mod config;
|
mod config;
|
||||||
@ -27,4 +27,5 @@ fn main() {
|
|||||||
.position_init()
|
.position_init()
|
||||||
.ref_position()
|
.ref_position()
|
||||||
.ref_moves();
|
.ref_moves();
|
||||||
|
info!("{:?}", moves);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user