Skip to content

Commit

Permalink
✨ 🔥 🐛 IDDFS & princess bug fix
Browse files Browse the repository at this point in the history
The princess wasn't a part of is_white nor is_black and thus her moves
were not considered.
IDDFS with BFS-like scheduling is there but needs commenting and
documenting.
  • Loading branch information
adri326 committed Nov 22, 2020
1 parent 2e423f5 commit adda08b
Show file tree
Hide file tree
Showing 4 changed files with 370 additions and 69 deletions.
26 changes: 14 additions & 12 deletions lib/game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,15 +270,15 @@ impl From<Piece> for usize {
Piece::UnicornW => 7,
Piece::DragonW => 8,
Piece::PrincessW => 9,
Piece::PawnB => 11,
Piece::KnightB => 12,
Piece::BishopB => 13,
Piece::RookB => 14,
Piece::QueenB => 15,
Piece::KingB => 16,
Piece::UnicornB => 17,
Piece::DragonB => 18,
Piece::PrincessB => 19,
Piece::PawnB => 33,
Piece::KnightB => 34,
Piece::BishopB => 35,
Piece::RookB => 36,
Piece::QueenB => 37,
Piece::KingB => 38,
Piece::UnicornB => 39,
Piece::DragonB => 40,
Piece::PrincessB => 41,
}
}
}
Expand Down Expand Up @@ -319,7 +319,8 @@ impl Piece {
| Piece::QueenW
| Piece::KingW
| Piece::UnicornW
| Piece::DragonW => true,
| Piece::DragonW
| Piece::PrincessW => true,
_ => false,
}
}
Expand All @@ -335,7 +336,8 @@ impl Piece {
| Piece::QueenB
| Piece::KingB
| Piece::UnicornB
| Piece::DragonB => true,
| Piece::DragonB
| Piece::PrincessB => true,
_ => false,
}
}
Expand Down Expand Up @@ -412,7 +414,7 @@ impl Piece {
}
}

/// Returns whether or not that Piece is a `Piece::Dragon*`
/// Returns whether or not that Piece is a `Piece::Princess*`
#[inline]
pub fn is_princess(&self) -> bool {
match &self {
Expand Down
62 changes: 36 additions & 26 deletions lib/moves.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,19 +456,24 @@ pub fn probable_moves(game: &Game, board: &Board, virtual_boards: &Vec<&Board>)
// TODO: check the b and c file
let king_w = board.king_w.unwrap();
let (mut x, y) = king_w;
x -= 1;
while let Some(piece) = board.get(x, y) {
if let Piece::RookW = piece {
res.push(
Move::castle(true, (board.l, board.t, king_w.0, king_w.1), (x, y), true)
.unwrap(),
);
break;
} else if let Piece::Blank = piece {
x -= 1;
continue;
} else {
break;
if x != 0 {
x -= 1;
while let Some(piece) = board.get(x, y) {
if let Piece::RookW = piece {
res.push(
Move::castle(true, (board.l, board.t, king_w.0, king_w.1), (x, y), true)
.unwrap(),
);
break;
} else if let Piece::Blank = piece {
if x == 0 {
break;
}
x -= 1;
continue;
} else {
break;
}
}
}
}
Expand Down Expand Up @@ -498,19 +503,24 @@ pub fn probable_moves(game: &Game, board: &Board, virtual_boards: &Vec<&Board>)
// TODO: check the b and c file
let king_b = board.king_b.unwrap();
let (mut x, y) = king_b;
x -= 1;
while let Some(piece) = board.get(x, y) {
if let Piece::RookB = piece {
res.push(
Move::castle(true, (board.l, board.t, king_b.0, king_b.1), (x, y), false)
.unwrap(),
);
break;
} else if let Piece::Blank = piece {
x -= 1;
continue;
} else {
break;
if x != 0 {
x -= 1;
while let Some(piece) = board.get(x, y) {
if let Piece::RookB = piece {
res.push(
Move::castle(true, (board.l, board.t, king_b.0, king_b.1), (x, y), false)
.unwrap(),
);
break;
} else if let Piece::Blank = piece {
if x == 0 {
break;
}
x -= 1;
continue;
} else {
break;
}
}
}
}
Expand Down
Loading

0 comments on commit adda08b

Please sign in to comment.