Make use of 'ChessBoard::default' in tests

This commit is contained in:
Bruno BELANYI 2022-07-28 21:45:28 +02:00
parent 9cddda7478
commit 99129e453c

View file

@ -408,35 +408,7 @@ mod test {
#[test] #[test]
fn valid() { fn valid() {
let default_position = ChessBoard { let default_position = ChessBoard::default();
piece_occupancy: [
// King
Square::E1 | Square::E8,
// Queen
Square::D1 | Square::D8,
// Rook
Square::A1 | Square::A8 | Square::H1 | Square::H8,
// Bishop
Square::C1 | Square::C8 | Square::F1 | Square::F8,
// Knight
Square::B1 | Square::B8 | Square::G1 | Square::G8,
// Pawn
Rank::Second.into_bitboard() | Rank::Seventh.into_bitboard(),
],
color_occupancy: [
Rank::First.into_bitboard() | Rank::Second.into_bitboard(),
Rank::Seventh.into_bitboard() | Rank::Eighth.into_bitboard(),
],
combined_occupancy: Rank::First.into_bitboard()
| Rank::Second.into_bitboard()
| Rank::Seventh.into_bitboard()
| Rank::Eighth.into_bitboard(),
castle_rights: [CastleRights::BothSides; 2],
en_passant: None,
half_move_clock: 0,
total_plies: 0,
side: Color::White,
};
assert!(default_position.is_valid()); assert!(default_position.is_valid());
} }
@ -646,35 +618,7 @@ mod test {
#[test] #[test]
fn fen_default_position() { fn fen_default_position() {
let default_position = ChessBoard { let default_position = ChessBoard::default();
piece_occupancy: [
// King
Square::E1 | Square::E8,
// Queen
Square::D1 | Square::D8,
// Rook
Square::A1 | Square::A8 | Square::H1 | Square::H8,
// Bishop
Square::C1 | Square::C8 | Square::F1 | Square::F8,
// Knight
Square::B1 | Square::B8 | Square::G1 | Square::G8,
// Pawn
Rank::Second.into_bitboard() | Rank::Seventh.into_bitboard(),
],
color_occupancy: [
Rank::First.into_bitboard() | Rank::Second.into_bitboard(),
Rank::Seventh.into_bitboard() | Rank::Eighth.into_bitboard(),
],
combined_occupancy: Rank::First.into_bitboard()
| Rank::Second.into_bitboard()
| Rank::Seventh.into_bitboard()
| Rank::Eighth.into_bitboard(),
castle_rights: [CastleRights::BothSides; 2],
en_passant: None,
half_move_clock: 0,
total_plies: 0,
side: Color::White,
};
assert_eq!( assert_eq!(
ChessBoard::from_fen("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1") ChessBoard::from_fen("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1")
.unwrap(), .unwrap(),
@ -685,35 +629,7 @@ mod test {
#[test] #[test]
fn fen_en_passant() { fn fen_en_passant() {
// Start from default position // Start from default position
let mut position = ChessBoard { let mut position = ChessBoard::default();
piece_occupancy: [
// King
Square::E1 | Square::E8,
// Queen
Square::D1 | Square::D8,
// Rook
Square::A1 | Square::A8 | Square::H1 | Square::H8,
// Bishop
Square::C1 | Square::C8 | Square::F1 | Square::F8,
// Knight
Square::B1 | Square::B8 | Square::G1 | Square::G8,
// Pawn
Rank::Second.into_bitboard() | Rank::Seventh.into_bitboard(),
],
color_occupancy: [
Rank::First.into_bitboard() | Rank::Second.into_bitboard(),
Rank::Seventh.into_bitboard() | Rank::Eighth.into_bitboard(),
],
combined_occupancy: Rank::First.into_bitboard()
| Rank::Second.into_bitboard()
| Rank::Seventh.into_bitboard()
| Rank::Eighth.into_bitboard(),
castle_rights: [CastleRights::BothSides; 2],
en_passant: None,
half_move_clock: 0,
total_plies: 0,
side: Color::White,
};
// Modify it to account for e4 move // Modify it to account for e4 move
position.xor(Color::White, Piece::Pawn, Square::E2 | Square::E4); position.xor(Color::White, Piece::Pawn, Square::E2 | Square::E4);
position.en_passant = Some(Square::E3); position.en_passant = Some(Square::E3);
@ -750,35 +666,7 @@ mod test {
#[test] #[test]
fn do_move() { fn do_move() {
// Start from default position // Start from default position
let mut position = ChessBoard { let mut position = ChessBoard::default();
piece_occupancy: [
// King
Square::E1 | Square::E8,
// Queen
Square::D1 | Square::D8,
// Rook
Square::A1 | Square::A8 | Square::H1 | Square::H8,
// Bishop
Square::C1 | Square::C8 | Square::F1 | Square::F8,
// Knight
Square::B1 | Square::B8 | Square::G1 | Square::G8,
// Pawn
Rank::Second.into_bitboard() | Rank::Seventh.into_bitboard(),
],
color_occupancy: [
Rank::First.into_bitboard() | Rank::Second.into_bitboard(),
Rank::Seventh.into_bitboard() | Rank::Eighth.into_bitboard(),
],
combined_occupancy: Rank::First.into_bitboard()
| Rank::Second.into_bitboard()
| Rank::Seventh.into_bitboard()
| Rank::Eighth.into_bitboard(),
castle_rights: [CastleRights::BothSides; 2],
en_passant: None,
half_move_clock: 0,
total_plies: 0,
side: Color::White,
};
// Modify it to account for e4 move // Modify it to account for e4 move
position.do_move( position.do_move(
MoveBuilder { MoveBuilder {
@ -841,35 +729,7 @@ mod test {
#[test] #[test]
fn do_move_and_undo() { fn do_move_and_undo() {
// Start from default position // Start from default position
let mut position = ChessBoard { let mut position = ChessBoard::default();
piece_occupancy: [
// King
Square::E1 | Square::E8,
// Queen
Square::D1 | Square::D8,
// Rook
Square::A1 | Square::A8 | Square::H1 | Square::H8,
// Bishop
Square::C1 | Square::C8 | Square::F1 | Square::F8,
// Knight
Square::B1 | Square::B8 | Square::G1 | Square::G8,
// Pawn
Rank::Second.into_bitboard() | Rank::Seventh.into_bitboard(),
],
color_occupancy: [
Rank::First.into_bitboard() | Rank::Second.into_bitboard(),
Rank::Seventh.into_bitboard() | Rank::Eighth.into_bitboard(),
],
combined_occupancy: Rank::First.into_bitboard()
| Rank::Second.into_bitboard()
| Rank::Seventh.into_bitboard()
| Rank::Eighth.into_bitboard(),
castle_rights: [CastleRights::BothSides; 2],
en_passant: None,
half_move_clock: 0,
total_plies: 0,
side: Color::White,
};
// Modify it to account for e4 move // Modify it to account for e4 move
let move_1 = MoveBuilder { let move_1 = MoveBuilder {
piece: Piece::Pawn, piece: Piece::Pawn,