pub type Figure = usize;
pub const NO_FIGURE: Figure = 0;
pub const PAWN: Figure = 1;
pub const KNIGHT: Figure = 2;
pub const BISHOP: Figure = 3;
pub const ROOK: Figure = 4;
pub const QUEEN: Figure = 5;
pub const KING: Figure = 6;
pub const LANCER: Figure = 7;
pub const LANCERN: Figure = 8;
pub const LANCERNE: Figure = 9;
pub const LANCERE: Figure = 10;
pub const LANCERSE: Figure = 11;
pub const LANCERS: Figure = 12;
pub const LANCERSW: Figure = 13;
pub const LANCERW: Figure = 14;
pub const LANCERNW: Figure = 15;
pub const SENTRY: Figure = 16;
pub const JAILER: Figure = 17;
pub const FIGURE_FEN_SYMBOLS: [&str; 18] = [
".", "p", "n", "b", "r", "q", "k", "l", "ln", "lne", "le", "lse", "ls", "lsw", "lw", "lnw",
"s", "j",
];
pub const FIGURE_SAN_LETTERS: [&str; 18] = [
".", "P", "N", "B", "R", "Q", "K", "L", "L", "L", "L", "L", "L", "L", "L", "L", "S", "J",
];
pub trait FigureTrait {
fn symbol(self) -> &'static str;
}
impl FigureTrait for Figure {
fn symbol(self) -> &'static str {
FIGURE_FEN_SYMBOLS[self]
}
}
pub type Color = usize;
pub const BLACK: Color = 0;
pub const WHITE: Color = 1;
pub type Piece = usize;
pub const PIECE_FEN_SYMBOLS: [&str; 36] = [
".", ".", "p", "P", "n", "N", "b", "B", "r", "R", "q", "Q", "k", "K", "l", "L", "ln", "Ln",
"lne", "Lne", "le", "Le", "lse", "Lse", "ls", "Ls", "lsw", "Lsw", "lw", "Lw", "lnw", "Lnw",
"s", "S", "j", "J",
];
pub fn color_figure(col: Color, fig: Figure) -> Piece {
(2 * fig) + col
}
pub trait PieceTrait {
fn color(self) -> Color;
fn figure(self) -> Figure;
fn fen_symbol(self) -> &'static str;
fn san_symbol(self) -> &'static str;
fn uci_symbol(self) -> &'static str;
fn san_letter(self) -> &'static str;
}
impl PieceTrait for Piece {
fn color(self) -> Color {
return if self & 1 == 0 { BLACK } else { WHITE };
}
fn figure(self) -> Figure {
self >> 1
}
fn fen_symbol(self) -> &'static str {
PIECE_FEN_SYMBOLS[self]
}
fn san_symbol(self) -> &'static str {
return color_figure(WHITE, self.figure()).fen_symbol();
}
fn uci_symbol(self) -> &'static str {
return self.figure().symbol();
}
fn san_letter(self) -> &'static str {
FIGURE_SAN_LETTERS[self.figure()]
}
}