1
0
Fork 0

Setup::validate -> Setup::into_position

This commit is contained in:
Paul-Nicolas Madelaine 2025-10-23 23:34:31 +02:00
parent 0d22c59cc3
commit 6f409799db
5 changed files with 19 additions and 18 deletions

View file

@ -18,7 +18,7 @@ fn recursive_check_aux(position: Position, depth: usize) {
.to_string()
.parse::<Setup>()
.unwrap()
.validate()
.into_position()
.unwrap(),
);
@ -50,7 +50,7 @@ fn recursive_check_aux(position: Position, depth: usize) {
.en_passant_target_square()
.map(|square| square.mirror()),
);
setup.validate().unwrap()
setup.into_position().unwrap()
};
let expected_mirror = position.mirror();
assert_eq!(computed_mirror, expected_mirror);
@ -75,7 +75,7 @@ fn recursive_check_aux(position: Position, depth: usize) {
}
}
fn recursive_check(record: &str) {
recursive_check_aux(record.parse::<Setup>().unwrap().validate().unwrap(), 4);
recursive_check_aux(record.parse::<Setup>().unwrap().into_position().unwrap(), 4);
}
#[test]
fn recursive_check_1() {
@ -199,7 +199,7 @@ fn setup() {
record
.parse::<Setup>()
.unwrap()
.validate()
.into_position()
.is_err_and(|e| e.reasons().contains(reason)),
"{record} should be invalid because of {reason:?}",
);
@ -222,18 +222,18 @@ fn mirror() {
let position = "rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b Kq e3"
.parse::<Setup>()
.unwrap()
.validate()
.into_position()
.unwrap();
let mirror = "rnbqkbnr/pppp1ppp/8/4p3/8/8/PPPPPPPP/RNBQKBNR w Qk e6"
.parse::<Setup>()
.unwrap()
.validate()
.into_position()
.unwrap();
assert_eq!(mirror, position.mirror());
}
fn perft_aux(record: &str, tests: &[u128]) {
let position = record.parse::<Setup>().unwrap().validate().unwrap();
let position = record.parse::<Setup>().unwrap().into_position().unwrap();
for (depth, value) in tests.iter().copied().enumerate() {
assert_eq!(
position.perft(depth),
@ -275,7 +275,7 @@ fn san() {
let position = "8/2KN1p2/5p2/3N1B1k/5PNp/7P/7P/8 w - -"
.parse::<Setup>()
.unwrap()
.validate()
.into_position()
.unwrap();
let san1 = "N7xf6#".parse::<San>().unwrap();
let m1 = san1.to_move(&position).unwrap();