update vocabulary
This commit is contained in:
parent
ecb82b3120
commit
270ac66db4
2 changed files with 35 additions and 58 deletions
90
src/board.rs
90
src/board.rs
|
|
@ -4,7 +4,10 @@ use crate::bitboard::*;
|
||||||
|
|
||||||
macro_rules! container {
|
macro_rules! container {
|
||||||
($v:vis, $a:ident, $b:ident, $n:literal) => {
|
($v:vis, $a:ident, $b:ident, $n:literal) => {
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
#[doc = "Container with values for each [`"]
|
||||||
|
#[doc = stringify!($a)]
|
||||||
|
#[doc = "`]."]
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||||
$v struct $b<T>(pub(crate) [T; $n]);
|
$v struct $b<T>(pub(crate) [T; $n]);
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
impl<T> $b<T> {
|
impl<T> $b<T> {
|
||||||
|
|
@ -123,9 +126,7 @@ impl File {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// ## Safety
|
/// **Safety:** The caller must ensure that `index < 8`.
|
||||||
///
|
|
||||||
/// The caller must ensure that `index < 8`.
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub const unsafe fn new_unchecked(index: u8) -> Self {
|
pub const unsafe fn new_unchecked(index: u8) -> Self {
|
||||||
debug_assert!(index < 8);
|
debug_assert!(index < 8);
|
||||||
|
|
@ -216,9 +217,7 @@ impl Rank {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// ## Safety
|
/// **Safety:** The caller must ensure that `index < 8`.
|
||||||
///
|
|
||||||
/// The caller must ensure that `index < 8`.
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub const unsafe fn new_unchecked(index: u8) -> Self {
|
pub const unsafe fn new_unchecked(index: u8) -> Self {
|
||||||
debug_assert!(index < 8);
|
debug_assert!(index < 8);
|
||||||
|
|
@ -257,13 +256,13 @@ impl Rank {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub const fn mirror(self) -> Self {
|
pub const fn bitboard(self) -> Bitboard {
|
||||||
unsafe { Self::new_unchecked(!(self as u8)) }
|
Bitboard(0xFF << ((self as u64) << 3))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub const fn bitboard(self) -> Bitboard {
|
pub const fn mirror(self) -> Self {
|
||||||
Bitboard(0xFF << ((self as u64) << 3))
|
unsafe { Self::new_unchecked(!(self as u8)) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -315,9 +314,7 @@ impl Square {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// ## Safety
|
/// **Safety:** The caller must ensure that `index < 64`.
|
||||||
///
|
|
||||||
/// The caller must ensure that `index < 64`.
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub const unsafe fn new_unchecked(index: u8) -> Self {
|
pub const unsafe fn new_unchecked(index: u8) -> Self {
|
||||||
debug_assert!(index < 64);
|
debug_assert!(index < 64);
|
||||||
|
|
@ -339,47 +336,15 @@ impl Square {
|
||||||
unsafe { Rank::new_unchecked((self as u8) >> 3) }
|
unsafe { Rank::new_unchecked((self as u8) >> 3) }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub const fn mirror(self) -> Self {
|
|
||||||
let sq = self as u8;
|
|
||||||
unsafe { Self::new_unchecked(sq & 0b000111 | (!sq & 0b111000)) }
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub const fn bitboard(self) -> Bitboard {
|
pub const fn bitboard(self) -> Bitboard {
|
||||||
Bitboard(1 << self as u8)
|
Bitboard(1 << self as u8)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
#[rustfmt::skip]
|
pub const fn mirror(self) -> Self {
|
||||||
pub(crate) fn to_str(self) -> &'static str {
|
let sq = self as u8;
|
||||||
match self {
|
unsafe { Self::new_unchecked(sq & 0b000111 | (!sq & 0b111000)) }
|
||||||
Self::A1 => "a1", Self::B1 => "b1", Self::C1 => "c1", Self::D1 => "d1", Self::E1 => "e1", Self::F1 => "f1", Self::G1 => "g1", Self::H1 => "h1",
|
|
||||||
Self::A2 => "a2", Self::B2 => "b2", Self::C2 => "c2", Self::D2 => "d2", Self::E2 => "e2", Self::F2 => "f2", Self::G2 => "g2", Self::H2 => "h2",
|
|
||||||
Self::A3 => "a3", Self::B3 => "b3", Self::C3 => "c3", Self::D3 => "d3", Self::E3 => "e3", Self::F3 => "f3", Self::G3 => "g3", Self::H3 => "h3",
|
|
||||||
Self::A4 => "a4", Self::B4 => "b4", Self::C4 => "c4", Self::D4 => "d4", Self::E4 => "e4", Self::F4 => "f4", Self::G4 => "g4", Self::H4 => "h4",
|
|
||||||
Self::A5 => "a5", Self::B5 => "b5", Self::C5 => "c5", Self::D5 => "d5", Self::E5 => "e5", Self::F5 => "f5", Self::G5 => "g5", Self::H5 => "h5",
|
|
||||||
Self::A6 => "a6", Self::B6 => "b6", Self::C6 => "c6", Self::D6 => "d6", Self::E6 => "e6", Self::F6 => "f6", Self::G6 => "g6", Self::H6 => "h6",
|
|
||||||
Self::A7 => "a7", Self::B7 => "b7", Self::C7 => "c7", Self::D7 => "d7", Self::E7 => "e7", Self::F7 => "f7", Self::G7 => "g7", Self::H7 => "h7",
|
|
||||||
Self::A8 => "a8", Self::B8 => "b8", Self::C8 => "c8", Self::D8 => "d8", Self::E8 => "e8", Self::F8 => "f8", Self::G8 => "g8", Self::H8 => "h8",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub(crate) fn from_str(s: &str) -> Option<Self> {
|
|
||||||
match s.as_bytes() {
|
|
||||||
[f, r] => Self::from_ascii(&[*f, *r]),
|
|
||||||
_ => None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub(crate) fn from_ascii(s: &[u8; 2]) -> Option<Self> {
|
|
||||||
let [f, r] = *s;
|
|
||||||
Some(Self::from_coords(
|
|
||||||
File::from_ascii(f)?,
|
|
||||||
Rank::from_ascii(r)?,
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
@ -431,7 +396,10 @@ impl Square {
|
||||||
impl core::fmt::Display for Square {
|
impl core::fmt::Display for Square {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
|
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
|
||||||
f.write_str(self.to_str())
|
use core::fmt::Write;
|
||||||
|
f.write_char(self.file().to_char())?;
|
||||||
|
f.write_char(self.rank().to_char())?;
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -449,7 +417,14 @@ impl core::str::FromStr for Square {
|
||||||
type Err = ParseSquareError;
|
type Err = ParseSquareError;
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||||
Self::from_str(s).ok_or(ParseSquareError)
|
(|| match s.as_bytes() {
|
||||||
|
[f, r] => Some(Self::from_coords(
|
||||||
|
File::from_ascii(*f)?,
|
||||||
|
Rank::from_ascii(*r)?,
|
||||||
|
)),
|
||||||
|
_ => None,
|
||||||
|
})()
|
||||||
|
.ok_or(ParseSquareError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -568,7 +543,8 @@ impl Role {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
|
/// Container with values for each [`Role`].
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||||
pub struct ByRole<T>(pub(crate) [T; 6]);
|
pub struct ByRole<T>(pub(crate) [T; 6]);
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
impl<T> ByRole<T> {
|
impl<T> ByRole<T> {
|
||||||
|
|
@ -578,15 +554,15 @@ impl<T> ByRole<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub const fn get(&self, role: Role) -> &T {
|
pub const fn get(&self, k: Role) -> &T {
|
||||||
let i = unsafe { (role as usize).unchecked_sub(1) };
|
let i = unsafe { (k as usize).unchecked_sub(1) };
|
||||||
unsafe { core::hint::assert_unchecked(i < 6) };
|
unsafe { core::hint::assert_unchecked(i < 6) };
|
||||||
&self.0[i]
|
&self.0[i]
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub const fn get_mut(&mut self, role: Role) -> &mut T {
|
pub const fn get_mut(&mut self, k: Role) -> &mut T {
|
||||||
let i = unsafe { (role as usize).unchecked_sub(1) };
|
let i = unsafe { (k as usize).unchecked_sub(1) };
|
||||||
unsafe { core::hint::assert_unchecked(i < 6) };
|
unsafe { core::hint::assert_unchecked(i < 6) };
|
||||||
&mut self.0[i]
|
&mut self.0[i]
|
||||||
}
|
}
|
||||||
|
|
@ -701,7 +677,7 @@ pub enum CastlingSide {
|
||||||
Long,
|
Long,
|
||||||
}
|
}
|
||||||
|
|
||||||
container!(pub(crate), CastlingSide, ByCastlingSide, 2);
|
container!(pub, CastlingSide, ByCastlingSide, 2);
|
||||||
|
|
||||||
impl CastlingSide {
|
impl CastlingSide {
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
|
||||||
|
|
@ -210,7 +210,8 @@ impl Setup {
|
||||||
|
|
||||||
match self.en_passant.try_into_square() {
|
match self.en_passant.try_into_square() {
|
||||||
Some(sq) => {
|
Some(sq) => {
|
||||||
w.write_str(sq.to_str())?;
|
w.write_char(sq.file().to_char())?;
|
||||||
|
w.write_char(sq.rank().to_char())?;
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
w.write_char('-')?;
|
w.write_char('-')?;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue