implemented constructor by piece_index for enum PieceType

This commit is contained in:
Varga Dávid Lajos
2025-11-21 13:01:38 +01:00
parent d649afdcfd
commit b137e6ceab

View File

@@ -16,3 +16,23 @@ pub enum PieceType {
BlackKing,
}
impl PieceType {
pub(in super) fn from_index(idx: u8) -> Self {
return match idx {
0 => PieceType::WhitePawn,
1 => PieceType::WhiteKnight,
2 => PieceType::WhiteBishop,
3 => PieceType::WhiteRook,
4 => PieceType::WhiteQueen,
5 => PieceType::WhiteKing,
6 => PieceType::BlackPawn,
7 => PieceType::BlackKnight,
8 => PieceType::BlackBishop,
9 => PieceType::BlackRook,
10 => PieceType::BlackQueen,
11 => PieceType::BlackKing,
_ => panic!("invalid piece index! should NEVER appear")
}
}
}