Skip to content

Commit

Permalink
refactor: clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
Saphereye committed Oct 6, 2024
1 parent ee22ba7 commit 1770a49
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 35 deletions.
14 changes: 6 additions & 8 deletions src/evaluate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ pub fn evaluate_board(board: &Board) -> i64 {
}

// Piece mobility (count legal moves)
let mobility = MoveGen::new_legal(&board)
let mobility = MoveGen::new_legal(board)
.filter(|m| m.get_source() == sq)
.count() as i32;
if board.color_on(sq) == Some(Color::White) {
Expand All @@ -182,13 +182,11 @@ pub fn evaluate_board(board: &Board) -> i64 {
}

// Rook on open files
if piece == Piece::Rook {
if rook_on_open_file(sq, board) {
if board.color_on(sq) == Some(Color::White) {
white_rook_bonus += 50;
} else {
black_rook_bonus += 50;
}
if piece == Piece::Rook && rook_on_open_file(sq, board) {
if board.color_on(sq) == Some(Color::White) {
white_rook_bonus += 50;
} else {
black_rook_bonus += 50;
}
}
}
Expand Down
31 changes: 9 additions & 22 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use evaluate::evaluate_board;
mod uci;
use uci::*;

#[derive(Clone)]
#[derive(Clone, Default)]
struct Node {
board: Board,
total_score: i64,
Expand All @@ -22,22 +22,9 @@ struct Node {
move_to_reach: Option<ChessMove>,
}

impl Default for Node {
fn default() -> Self {
Self {
board: Board::default(),
total_score: 0,
number_of_visits: 0,
first_child: None,
next_sibling: None,
move_to_reach: None,
}
}
}

impl Debug for Node {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
writeln!(f, "")?;
writeln!(f)?;
self.fmt_with_indent(f, 0)
}
}
Expand Down Expand Up @@ -201,9 +188,9 @@ fn find_best_move(root: &Node) -> ChessMove {
best_child.and_then(|child| child.move_to_reach).unwrap()
}

const VERSION: &'static str = env!("CARGO_PKG_VERSION");
const AUTHORS: &'static str = env!("CARGO_PKG_AUTHORS");
const NAME: &'static str = env!("CARGO_PKG_NAME");
const VERSION: &str = env!("CARGO_PKG_VERSION");
const AUTHORS: &str = env!("CARGO_PKG_AUTHORS");
const NAME: &str = env!("CARGO_PKG_NAME");

fn uci_to_move(uci: &str) -> Result<ChessMove, String> {
let from = Square::from_str(&uci[0..2]).map_err(|_| "Invalid from square")?;
Expand All @@ -229,15 +216,15 @@ fn main() {
let mut current_root: *mut Node = &mut root;

loop {
unsafe {
dbg!(&*current_root);
}
// unsafe {
// dbg!(&*current_root);
// }
let mut input = String::new();
std::io::stdin().read_line(&mut input).unwrap();
let input = input.trim();

match parse(input) {
Ok(("", UCICommand::UCI)) => {
Ok(("", UCICommand::Uci)) => {
println!("id name {NAME} {VERSION}");
println!("id author {AUTHORS}");
println!("uciok");
Expand Down
9 changes: 4 additions & 5 deletions src/uci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ use nom::{

#[derive(Debug, PartialEq)]
pub enum UCICommand {
UCI,
Debug(bool),
Uci,
IsReady,
Position {
fen: Option<String>,
Expand Down Expand Up @@ -89,7 +88,7 @@ pub fn parse_quit(input: &str) -> IResult<&str, UCICommand> {

pub fn parse_uci(input: &str) -> IResult<&str, UCICommand> {
let (input, _) = tag("uci")(input)?;
Ok((input, UCICommand::UCI))
Ok((input, UCICommand::Uci))
}

pub fn parse_isready(input: &str) -> IResult<&str, UCICommand> {
Expand All @@ -99,7 +98,7 @@ pub fn parse_isready(input: &str) -> IResult<&str, UCICommand> {

fn parse_fen(input: &str) -> IResult<&str, String> {
let (input, fen) =
take_until(" moves")(input).or_else(|_: nom::Err<NomError<&str>>| Ok((input, input)))?;
take_until::<&str, &str, NomError<&str>>(" moves")(input).or(Ok((input, input)))?;
Ok((input, fen.trim().to_string()))
}

Expand Down Expand Up @@ -149,7 +148,7 @@ mod tests {
#[test]
fn test_parse_uci() {
let input = "uci";
let expected = UCICommand::UCI;
let expected = UCICommand::Uci;
let result = parse(input);
assert_eq!(result, Ok(("", expected)));
}
Expand Down

0 comments on commit 1770a49

Please sign in to comment.