diff options
author | eug-vs <eugene@eug-vs.xyz> | 2023-01-23 13:07:21 +0300 |
---|---|---|
committer | eug-vs <eugene@eug-vs.xyz> | 2023-01-23 13:07:21 +0300 |
commit | 444fd1734c5ecc4167826909900d60e2ccee83b5 (patch) | |
tree | 910a5d3f921e50e2a64b8c0c7bb5856a6473aa20 /src/board.rs | |
parent | 6465ab6db6b47d80cb5f13609cec4f50a874ae69 (diff) | |
download | chessnost-444fd1734c5ecc4167826909900d60e2ccee83b5.tar.gz |
refactor: add Board::new
Diffstat (limited to 'src/board.rs')
-rw-r--r-- | src/board.rs | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/src/board.rs b/src/board.rs index 2cb4fcf..659f447 100644 --- a/src/board.rs +++ b/src/board.rs @@ -1,7 +1,5 @@ use crate::{bitboard::{Bitboard, serialize_bitboard, bitscan}, moves::{Move, MoveKind}, attacks::Attacks, square::Square}; -pub static DEFAULT_FEN: &str = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"; - #[derive(Debug, Clone, PartialEq, Eq)] pub struct Board { pub pieces: [Bitboard; 12], @@ -99,6 +97,11 @@ impl Board { board } + pub fn new() -> Self { + let default_fen = String::from("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"); + Self::from_FEN(default_fen) + } + fn update_occupancy(&mut self) { self.occupancy = 0; // TODO: reduce @@ -499,9 +502,8 @@ mod tests { } #[test] - fn test_from_fen() { - let fen = String::from(DEFAULT_FEN); - let board = Board::from_FEN(fen); + fn test_new_from_default_fen() { + let board = Board::new(); board.print(); print(board.empty(), "Empty squares"); @@ -531,8 +533,7 @@ mod tests { #[test] fn test_generate_moves_starting_position() { - let fen = String::from(DEFAULT_FEN); - let board = Board::from_FEN(fen); + let board = Board::new(); let moves = board.generate_moves(Color::White); let black_moves = board.generate_moves(Color::Black); @@ -603,8 +604,7 @@ mod tests { #[test] fn test_perft() { - let fen = String::from(DEFAULT_FEN); - let mut board = Board::from_FEN(fen); + let mut board = Board::new(); assert_eq!(board.perft(0, false), (1, 0, 0, 0)); assert_eq!(board.perft(1, false), (20, 0, 0, 0)); @@ -616,8 +616,7 @@ mod tests { #[test] fn test_is_square_attacked() { - let fen = String::from(DEFAULT_FEN); - let board = Board::from_FEN(fen); + let board = Board::new(); assert_eq!(board.is_square_attacked(Square::E2, Color::White), true); assert_eq!(board.is_square_attacked(Square::E2, Color::Black), false); |