2023-12-19 11:13:06 -08:00
|
|
|
// Eryn Wells <eryn@erynwells.me>
|
|
|
|
|
2023-12-20 11:45:12 -08:00
|
|
|
use crate::bitboard::BitBoard;
|
|
|
|
use std::fmt;
|
|
|
|
|
2023-12-19 11:13:06 -08:00
|
|
|
mod color {
|
2023-12-20 11:45:12 -08:00
|
|
|
const WHITE: u8 = 0;
|
|
|
|
const BLACK: u8 = 1;
|
2023-12-19 11:13:06 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
mod piece {
|
2023-12-20 11:45:12 -08:00
|
|
|
const PAWN: u8 = 0;
|
|
|
|
const KNIGHT: u8 = 1;
|
|
|
|
const BISHOP: u8 = 2;
|
|
|
|
const ROOK: u8 = 3;
|
|
|
|
const QUEEN: u8 = 4;
|
|
|
|
const KING: u8 = 5;
|
2023-12-19 11:13:06 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
|
|
|
|
pub struct Position {
|
|
|
|
/// Composite bitboards for all the pieces of a particular color.
|
|
|
|
pieces_per_color: [BitBoard; 2],
|
|
|
|
|
|
|
|
/// Bitboards representing positions of particular piece types per color.
|
|
|
|
pieces_per_type: [[BitBoard; 6]; 2],
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Position {
|
2023-12-20 11:45:12 -08:00
|
|
|
fn empty() -> Position {
|
2023-12-19 11:13:06 -08:00
|
|
|
Position {
|
2023-12-20 11:45:12 -08:00
|
|
|
pieces_per_color: [BitBoard(0), BitBoard(0)],
|
|
|
|
pieces_per_type: [
|
|
|
|
[
|
|
|
|
BitBoard(0),
|
|
|
|
BitBoard(0),
|
|
|
|
BitBoard(0),
|
|
|
|
BitBoard(0),
|
|
|
|
BitBoard(0),
|
|
|
|
BitBoard(0),
|
|
|
|
],
|
|
|
|
[
|
|
|
|
BitBoard(0),
|
|
|
|
BitBoard(0),
|
|
|
|
BitBoard(0),
|
|
|
|
BitBoard(0),
|
|
|
|
BitBoard(0),
|
|
|
|
BitBoard(0),
|
|
|
|
],
|
|
|
|
],
|
2023-12-19 11:13:06 -08:00
|
|
|
}
|
|
|
|
}
|
2023-12-20 11:45:12 -08:00
|
|
|
|
|
|
|
/// Return a starting position.
|
|
|
|
fn starting() -> Position {
|
|
|
|
let white_pieces = [
|
|
|
|
BitBoard(0x00FF000000000000),
|
|
|
|
BitBoard(0x4200000000000000),
|
|
|
|
BitBoard(0x2400000000000000),
|
|
|
|
BitBoard(0x8100000000000000),
|
|
|
|
BitBoard(0x1000000000000000),
|
|
|
|
BitBoard(0x8000000000000000),
|
|
|
|
];
|
|
|
|
|
|
|
|
let black_pieces = [
|
|
|
|
BitBoard(0xFF00),
|
|
|
|
BitBoard(0x0042),
|
|
|
|
BitBoard(0x0024),
|
|
|
|
BitBoard(0x0081),
|
|
|
|
BitBoard(0x0010),
|
|
|
|
BitBoard(0x0080),
|
|
|
|
];
|
|
|
|
|
|
|
|
Position {
|
|
|
|
pieces_per_color: [
|
|
|
|
BitBoard(white_pieces.iter().map(|bb| bb.0).fold(0, |a, b| a | b)),
|
|
|
|
BitBoard(black_pieces.iter().map(|bb| bb.0).fold(0, |a, b| a | b)),
|
|
|
|
],
|
|
|
|
pieces_per_type: [white_pieces, black_pieces],
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn piece_at_square(&self, sq: &str) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl fmt::Display for Position {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
|
|
write!(f, "abcdefg")
|
|
|
|
}
|
2023-12-19 11:13:06 -08:00
|
|
|
}
|