[board] Fix some bugs in the starting position
Turns out I was doing the starting position really wrong. In an upcoming commit, I will implement FEN output for Positions. While doing that work, I found several issues that were causing the output of the FEN formatter to return garbage. Implement a handful of unit tests to track down the errors. Rename Shape::_ascii_representation() → Shape::to_ascii. Implement to_ascii() on Piece.
This commit is contained in:
parent
84c9c43a7d
commit
829d9af52c
5 changed files with 87 additions and 42 deletions
|
@ -33,22 +33,22 @@ impl Position {
|
|||
|
||||
/// Return a starting position.
|
||||
pub fn starting() -> Self {
|
||||
let white_pieces = [
|
||||
BitBoard::new(0x00FF000000000000),
|
||||
BitBoard::new(0x4200000000000000),
|
||||
BitBoard::new(0x2400000000000000),
|
||||
BitBoard::new(0x8100000000000000),
|
||||
BitBoard::new(0x1000000000000000),
|
||||
BitBoard::new(0x0800000000000000),
|
||||
let black_pieces = [
|
||||
BitBoard::new(0b0000000011111111 << 48),
|
||||
BitBoard::new(0b0100001000000000 << 48),
|
||||
BitBoard::new(0b0010010000000000 << 48),
|
||||
BitBoard::new(0b1000000100000000 << 48),
|
||||
BitBoard::new(0b0000100000000000 << 48),
|
||||
BitBoard::new(0b0001000000000000 << 48),
|
||||
];
|
||||
|
||||
let black_pieces = [
|
||||
BitBoard::new(0xFF00),
|
||||
BitBoard::new(0x0042),
|
||||
BitBoard::new(0x0024),
|
||||
BitBoard::new(0x0081),
|
||||
BitBoard::new(0x0010),
|
||||
BitBoard::new(0x0008),
|
||||
let white_pieces = [
|
||||
BitBoard::new(0b1111111100000000),
|
||||
BitBoard::new(0b0000000001000010),
|
||||
BitBoard::new(0b0000000000100100),
|
||||
BitBoard::new(0b0000000010000001),
|
||||
BitBoard::new(0b0000000000001000),
|
||||
BitBoard::new(0b0000000000010000),
|
||||
];
|
||||
|
||||
Self {
|
||||
|
@ -242,7 +242,32 @@ impl fmt::Display for Position {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::{position, Castle, Color};
|
||||
use crate::{position, Castle, Color, Position, Square};
|
||||
|
||||
#[test]
|
||||
fn piece_on_square() {
|
||||
let pos = test_position![
|
||||
Black Bishop on F7,
|
||||
];
|
||||
|
||||
let piece = pos.piece_on_square(Square::F7);
|
||||
assert_eq!(piece, Some(piece!(Black Bishop on F7)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn piece_in_starting_position() {
|
||||
let pos = Position::starting();
|
||||
println!("{pos}");
|
||||
|
||||
assert_eq!(
|
||||
pos.piece_on_square(Square::H1),
|
||||
Some(piece!(White Rook on H1))
|
||||
);
|
||||
assert_eq!(
|
||||
pos.piece_on_square(Square::A8),
|
||||
Some(piece!(Black Rook on A8))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn king_is_in_check() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue