use macro
This commit is contained in:
parent
c19498e6b5
commit
34df546eaa
1 changed files with 22 additions and 16 deletions
|
|
@ -60,6 +60,26 @@ pub struct Position(Setup);
|
||||||
|
|
||||||
pub(crate) const MAX_LEGAL_MOVES: usize = 218;
|
pub(crate) const MAX_LEGAL_MOVES: usize = 218;
|
||||||
|
|
||||||
|
const PAWN: u8 = Role::Pawn as u8;
|
||||||
|
const KNIGHT: u8 = Role::Knight as u8;
|
||||||
|
const BISHOP: u8 = Role::Bishop as u8;
|
||||||
|
const ROOK: u8 = Role::Rook as u8;
|
||||||
|
const QUEEN: u8 = Role::Queen as u8;
|
||||||
|
const KING: u8 = Role::King as u8;
|
||||||
|
|
||||||
|
macro_rules! map_role {
|
||||||
|
($f:ident, $role:ident, $($x:expr),+) => (
|
||||||
|
match $role {
|
||||||
|
Role::Pawn => $f::<PAWN>($($x),+),
|
||||||
|
Role::Knight => $f::<KNIGHT>($($x),+),
|
||||||
|
Role::Bishop => $f::<BISHOP>($($x),+),
|
||||||
|
Role::Rook => $f::<ROOK>($($x),+),
|
||||||
|
Role::Queen => $f::<QUEEN>($($x),+),
|
||||||
|
Role::King => $f::<KING>($($x),+),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
impl Position {
|
impl Position {
|
||||||
/// Returns the initial position of a chess game.
|
/// Returns the initial position of a chess game.
|
||||||
///
|
///
|
||||||
|
|
@ -366,14 +386,7 @@ impl Position {
|
||||||
} else {
|
} else {
|
||||||
role
|
role
|
||||||
};
|
};
|
||||||
match role {
|
map_role!(aux, role, self, promotion, from, to)
|
||||||
Role::Pawn => aux::<1>(self, promotion, from, to),
|
|
||||||
Role::Knight => aux::<2>(self, promotion, from, to),
|
|
||||||
Role::Bishop => aux::<3>(self, promotion, from, to),
|
|
||||||
Role::Rook => aux::<4>(self, promotion, from, to),
|
|
||||||
Role::Queen => aux::<5>(self, promotion, from, to),
|
|
||||||
Role::King => aux::<6>(self, promotion, from, to),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn move_from_san<'l>(&'l self, san: &San) -> Result<Move<'l>, InvalidSan> {
|
pub(crate) fn move_from_san<'l>(&'l self, san: &San) -> Result<Move<'l>, InvalidSan> {
|
||||||
|
|
@ -482,14 +495,7 @@ impl Position {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
match role {
|
map_role!(aux, role, self, promotion, from, to)
|
||||||
Role::Pawn => aux::<1>(self, promotion, from, to),
|
|
||||||
Role::Knight => aux::<2>(self, promotion, from, to),
|
|
||||||
Role::Bishop => aux::<3>(self, promotion, from, to),
|
|
||||||
Role::Rook => aux::<4>(self, promotion, from, to),
|
|
||||||
Role::Queen => aux::<5>(self, promotion, from, to),
|
|
||||||
Role::King => aux::<6>(self, promotion, from, to),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue