From af18600d157a7f01618457c45db80e66f8ccbaed Mon Sep 17 00:00:00 2001 From: dogeystamp Date: Sat, 23 Nov 2024 18:42:36 -0500 Subject: [PATCH] refactor: move to main.rs file and add prelude --- Cargo.toml | 2 -- src/bin/movegen_tool.rs | 15 --------------- src/bin/perft_tool.rs | 14 -------------- src/lib.rs | 12 +++++++----- src/{bin/engine.rs => main.rs} | 6 +----- src/prelude.rs | 20 ++++++++++++++++++++ 6 files changed, 28 insertions(+), 41 deletions(-) delete mode 100644 src/bin/movegen_tool.rs delete mode 100644 src/bin/perft_tool.rs rename src/{bin/engine.rs => main.rs} (96%) create mode 100644 src/prelude.rs diff --git a/Cargo.toml b/Cargo.toml index 954df3b..723e31f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,8 +4,6 @@ version = "0.1.0" edition = "2021" license = "GPL-3.0-or-later" -default-run = "engine" - # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] diff --git a/src/bin/movegen_tool.rs b/src/bin/movegen_tool.rs deleted file mode 100644 index a2cca2b..0000000 --- a/src/bin/movegen_tool.rs +++ /dev/null @@ -1,15 +0,0 @@ -//! Generates moves from the FEN in the argv. - -use chess_inator::fen::FromFen; -use chess_inator::movegen::MoveGen; -use chess_inator::Board; -use std::env; - -fn main() { - let fen = env::args().nth(1).unwrap(); - let mut board = Board::from_fen(&fen).unwrap(); - let mvs = board.gen_moves(); - for mv in mvs.into_iter() { - println!("{mv:?}") - } -} diff --git a/src/bin/perft_tool.rs b/src/bin/perft_tool.rs deleted file mode 100644 index 114cfb9..0000000 --- a/src/bin/perft_tool.rs +++ /dev/null @@ -1,14 +0,0 @@ -//! Runs perft at depth for a given FEN. - -use chess_inator::fen::FromFen; -use chess_inator::movegen::perft; -use chess_inator::Board; -use std::env; - -fn main() { - let depth = env::args().nth(1).unwrap().parse::().unwrap(); - let fen = env::args().nth(2).unwrap(); - let mut board = Board::from_fen(&fen).unwrap(); - let res = perft(depth, &mut board); - println!("{res}") -} diff --git a/src/lib.rs b/src/lib.rs index cbdde83..2606ea7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -24,13 +24,15 @@ pub mod movegen; pub mod random; pub mod search; +pub mod prelude; + use crate::fen::{FromFen, ToFen, START_POSITION}; use crate::hash::Zobrist; use eval::eval_score::EvalScores; -const BOARD_WIDTH: usize = 8; -const BOARD_HEIGHT: usize = 8; -const N_SQUARES: usize = BOARD_WIDTH * BOARD_HEIGHT; +pub const BOARD_WIDTH: usize = 8; +pub const BOARD_HEIGHT: usize = 8; +pub const N_SQUARES: usize = BOARD_WIDTH * BOARD_HEIGHT; #[derive(Debug, Copy, Clone, Default, PartialEq, Eq)] pub enum Color { @@ -38,7 +40,7 @@ pub enum Color { White = 0, Black = 1, } -const N_COLORS: usize = 2; +pub const N_COLORS: usize = 2; impl Color { /// Return opposite color (does not assign). @@ -74,7 +76,7 @@ enum Piece { Queen, Pawn, } -const N_PIECES: usize = 6; +pub const N_PIECES: usize = 6; pub struct PieceErr; diff --git a/src/bin/engine.rs b/src/main.rs similarity index 96% rename from src/bin/engine.rs rename to src/main.rs index 7bb6785..125932e 100644 --- a/src/bin/engine.rs +++ b/src/main.rs @@ -12,11 +12,7 @@ Copyright © 2024 dogeystamp //! Main UCI engine binary. -use chess_inator::eval::eval_metrics; -use chess_inator::fen::FromFen; -use chess_inator::movegen::{FromUCIAlgebraic, Move, ToUCIAlgebraic}; -use chess_inator::search::{best_line, InterfaceMsg, SearchEval, TranspositionTable}; -use chess_inator::{Board, Color}; +use chess_inator::prelude::*; use std::cmp::min; use std::io; use std::sync::mpsc::channel; diff --git a/src/prelude.rs b/src/prelude.rs new file mode 100644 index 0000000..52c594e --- /dev/null +++ b/src/prelude.rs @@ -0,0 +1,20 @@ +/* + +This file is part of chess_inator. + +chess_inator is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. + +chess_inator is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with chess_inator. If not, see https://www.gnu.org/licenses/. + +Copyright © 2024 dogeystamp +*/ + +//! Prelude that you can import entirely to use the library conveniently. + +pub use crate::eval::{eval_metrics, EvalMetrics}; +pub use crate::fen::{FromFen, ToFen}; +pub use crate::movegen::{FromUCIAlgebraic, Move, MoveGen, ToUCIAlgebraic}; +pub use crate::search::{best_line, best_move, InterfaceMsg, SearchEval, TranspositionTable}; +pub use crate::{Board, Color, BOARD_HEIGHT, BOARD_WIDTH, N_COLORS, N_PIECES, N_SQUARES};