aboutsummaryrefslogtreecommitdiff
path: root/src/board.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/board.rs')
-rw-r--r--src/board.rs21
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);