Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Heiaha committed Nov 28, 2024
1 parent c3fa0b9 commit be535ef
Show file tree
Hide file tree
Showing 14 changed files with 269 additions and 288 deletions.
1 change: 0 additions & 1 deletion src/attacks.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use super::bitboard::*;
use super::color::*;
use super::magics::*;
use super::piece::*;
use super::square::*;
Expand Down
8 changes: 3 additions & 5 deletions src/bitboard.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
use std::fmt;
use std::ops::*;

use super::attacks;
use super::color::*;
use super::file::*;
use super::piece::*;
use super::square::*;
use super::types::*;
use std::fmt;
use std::ops::*;

#[derive(Clone, Copy, Default, PartialEq, Eq)]
pub struct Bitboard(pub Hash);
Expand Down
3 changes: 0 additions & 3 deletions src/board.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
use super::attacks;
use super::bitboard::*;
use super::color::*;
use super::file::*;
use super::moov::*;
use super::move_list::*;
use super::nnue::*;
use super::piece::*;
use super::rank::*;
use super::square::*;
use super::types::*;
use super::zobrist::*;
Expand Down
66 changes: 0 additions & 66 deletions src/color.rs

This file was deleted.

105 changes: 0 additions & 105 deletions src/diagonal.rs

This file was deleted.

43 changes: 0 additions & 43 deletions src/file.rs

This file was deleted.

2 changes: 0 additions & 2 deletions src/magics.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use super::attacks::*;
use super::bitboard::*;
use super::file::*;
use super::rank::*;
use super::square::*;

// Fancy magic bitboard implementation inspired by Rustfish's port of Stockfish
Expand Down
4 changes: 0 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ use crate::uci::*;
mod bitboard;
mod attacks;
mod board;
mod color;
mod diagonal;
mod file;
mod magics;
mod moov;
mod move_list;
Expand All @@ -22,7 +19,6 @@ mod nnue;
mod nnue_weights;
mod perft;
mod piece;
mod rank;
mod search;
mod search_master;
mod square;
Expand Down
1 change: 0 additions & 1 deletion src/move_sorter.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use super::attacks;
use super::bitboard::*;
use super::board::*;
use super::color::*;
use super::moov::*;
use super::move_list::*;
use super::piece::*;
Expand Down
68 changes: 66 additions & 2 deletions src/piece.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use super::types::*;
use std::convert::TryFrom;
use std::fmt;

use super::color::*;
use std::ops::Not;

#[derive(Copy, Clone, PartialEq, PartialOrd, Eq, Debug)]
#[repr(u8)]
pub enum Piece {
WhitePawn = 0b0000,
WhiteKnight = 0b0001,
Expand Down Expand Up @@ -130,3 +131,66 @@ impl PieceType {
pub const N_PIECE_TYPES: usize = 6;
pub const PIECE_TYPE_STR: &'static str = "pnbrqk";
}

#[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(u8)]
pub enum Color {
White,
Black,
}

impl Color {
pub fn index(self) -> usize {
self as usize
}

pub fn factor(&self) -> Value {
match *self {
Self::White => 1,
Self::Black => -1,
}
}
}

impl From<u8> for Color {
fn from(n: u8) -> Self {
unsafe { std::mem::transmute::<u8, Self>(n) }
}
}

impl Not for Color {
type Output = Color;

fn not(self) -> Self {
Color::from((self as u8) ^ 1)
}
}

impl fmt::Display for Color {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
f,
"{}",
match *self {
Self::White => "w",
Self::Black => "b",
}
)
}
}

impl TryFrom<char> for Color {
type Error = &'static str;

fn try_from(value: char) -> Result<Self, Self::Error> {
match value {
'w' => Ok(Self::White),
'b' => Ok(Self::Black),
_ => Err("Color must be either 'w' or 'b'."),
}
}
}

impl Color {
pub const N_COLORS: usize = 2;
}
Loading

0 comments on commit be535ef

Please sign in to comment.