Fix fen parsing for castling rights
This commit is contained in:
15
src/fen.rs
15
src/fen.rs
@@ -97,9 +97,9 @@ fn castling_ability(castling: &str) -> Result<[Castle; 2], FenError> {
|
|||||||
|
|
||||||
let mut castling_ability: [Castle; 2] = [Castle::None, Castle::None];
|
let mut castling_ability: [Castle; 2] = [Castle::None, Castle::None];
|
||||||
|
|
||||||
let white_king_and_queen = bitflag & 0b11 == 0b11;
|
let white_king_and_queen = (bitflag >> 2) & 0b11 == 0b11;
|
||||||
let white_king = (bitflag >> 1) & 1 == 1;
|
let white_king = (bitflag >> 3) & 1 == 1;
|
||||||
let white_queen = bitflag & 1 == 1;
|
let white_queen = (bitflag >> 2) & 1 == 1;
|
||||||
castling_ability[0] = match (white_king_and_queen, white_king, white_queen) {
|
castling_ability[0] = match (white_king_and_queen, white_king, white_queen) {
|
||||||
(true, _, _) => Castle::Both,
|
(true, _, _) => Castle::Both,
|
||||||
(_, true, _) => Castle::Short,
|
(_, true, _) => Castle::Short,
|
||||||
@@ -107,9 +107,9 @@ fn castling_ability(castling: &str) -> Result<[Castle; 2], FenError> {
|
|||||||
_ => Castle::None,
|
_ => Castle::None,
|
||||||
};
|
};
|
||||||
|
|
||||||
let black_king_and_queen = (bitflag >> 2) & 0b11 == 0b11;
|
let black_king_and_queen = bitflag & 0b11 == 0b11;
|
||||||
let black_king = (bitflag >> 3) & 1 == 1;
|
let black_king = (bitflag >> 1) & 1 == 1;
|
||||||
let black_queen = (bitflag >> 2) & 1 == 1;
|
let black_queen = bitflag & 1 == 1;
|
||||||
castling_ability[1] = match (black_king_and_queen, black_king, black_queen) {
|
castling_ability[1] = match (black_king_and_queen, black_king, black_queen) {
|
||||||
(true, _, _) => Castle::Both,
|
(true, _, _) => Castle::Both,
|
||||||
(_, true, _) => Castle::Short,
|
(_, true, _) => Castle::Short,
|
||||||
@@ -197,4 +197,7 @@ mod tests {
|
|||||||
fn test_fen_error() -> () {
|
fn test_fen_error() -> () {
|
||||||
from_fen(FEN_EXAMPLE[4]).unwrap();
|
from_fen(FEN_EXAMPLE[4]).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO: add more happy path scenarios
|
||||||
|
//TODO: test each panic e.g. #[should_panic(expected = "less than or equal to 100")]
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user