diff --git a/outputD1.txt b/outputD1.txt deleted file mode 100644 index d79dbbf..0000000 --- a/outputD1.txt +++ /dev/null @@ -1,44 +0,0 @@ -h2h3: 1 -h2h4: 1 -g2g3: 1 -g2g4: 1 -c2c3: 1 -b2b3: 1 -b2b4: 1 -a2a3: 1 -a2a4: 1 -d7c8: 1 -d7c8: 1 -d7c8: 1 -d7c8: 1 -b1a3: 1 -b1c3: 1 -b1d2: 1 -e2d4: 1 -e2f4: 1 -e2c3: 1 -e2g3: 1 -e2g1: 1 -c1d2: 1 -c1e3: 1 -c1f4: 1 -c1g5: 1 -c1h6: 1 -c4b5: 1 -c4a6: 1 -c4b3: 1 -c4d5: 1 -c4e6: 1 -c4f7: 1 -c4d3: 1 -h1g1: 1 -h1f1: 1 -d1d2: 1 -d1d3: 1 -d1d4: 1 -d1d5: 1 -d1d6: 1 -e1d2: 1 -e1f2: 1 -e1f1: 1 -e1g1: 1 diff --git a/outputD2.txt b/outputD2.txt deleted file mode 100644 index 2f44015..0000000 --- a/outputD2.txt +++ /dev/null @@ -1,44 +0,0 @@ -h2h3: 35 -h2h4: 35 -g2g3: 35 -g2g4: 35 -c2c3: 35 -b2b3: 35 -b2b4: 34 -a2a3: 35 -a2a4: 35 -d7c8: 41 -d7c8: 41 -d7c8: 41 -d7c8: 41 -b1a3: 35 -b1c3: 35 -b1d2: 35 -e2d4: 35 -e2f4: 35 -e2c3: 35 -e2g3: 35 -e2g1: 35 -c1d2: 35 -c1e3: 35 -c1f4: 35 -c1g5: 33 -c1h6: 34 -c4b5: 35 -c4a6: 34 -c4b3: 35 -c4d5: 36 -c4e6: 36 -c4f7: 34 -c4d3: 35 -h1g1: 35 -h1f1: 35 -d1d2: 35 -d1d3: 35 -d1d4: 35 -d1d5: 36 -d1d6: 32 -e1d2: 35 -e1f2: 29 -e1f1: 35 -e1g1: 35 diff --git a/src/gamemanager/legal_moves.rs b/src/gamemanager/legal_moves.rs index 5ece668..c1f3e35 100644 --- a/src/gamemanager/legal_moves.rs +++ b/src/gamemanager/legal_moves.rs @@ -30,7 +30,7 @@ impl GameManager { // Based on color, union all the friendly and enemy pieces, and determine // which squares the enemy is attacking. We'll need that info for checking // whether the king is in danger. - let (friendly_pieces, enemy_pieces, enemy_attacked) = match color { + let (friendly_pieces, enemy_pieces, currently_attacked) = match color { Color::Black => { let friendly_pieces = self.bitboard.pawns_black | self.bitboard.rooks_black @@ -105,9 +105,6 @@ impl GameManager { /* ************************************************************************************* */ for mv in &pslm { - if mv.2 == Square::F2 { - dbg!(&mv.3); - } debug_assert!(mv.1 != mv.2); // Create a new GameManager here. let mut modified_gm = { @@ -140,191 +137,25 @@ impl GameManager { } // TODO: Test mask and king intersection. - } - - // A pseudolegal move may be illegal iff it puts the king in check. - // For each possible move, check legality. - 'pslms: for (piecetype, from, to, movetype) in pslm { - // Test for king safety against each enemy bitboard, - // by grabbing all the moves a super piece can make - // from the king's square. + let enemy_attacked = modified_gm.attacked_by(match color { + Color::Black => Color::White, + Color::White => Color::Black, + }); - // Create a new GameManager here. - let mut modified_gm = { - match color { - Color::Black => { - self.black_match_block(piecetype.clone(), movetype.clone(), from, to) + match color { + Color::Black => { + if modified_gm.bitboard.king_black & enemy_attacked == 0 { + // Good move; push it. + legal_moves.push((mv.0.clone(), mv.1, mv.2, mv.3.clone(), modified_gm)); } - Color::White => { - self.white_match_block(piecetype.clone(), movetype.clone(), from, to) - } - } - }; - - // Increment the fullmove clock every black move. - if color == Color::Black { - modified_gm.fullmoves += 1; - modified_gm.white_to_move = true; - } else { - modified_gm.white_to_move = false; - } - - // Increment the halfmove counter every quiet/non-pawn move. - use MoveType::*; - match movetype { - QuietMove | KingCastle | QueenCastle => { - modified_gm.halfmoves += 1; - modified_gm.en_passant_target = String::new(); // Made a quiet move instead of EPCapture. } - EPCapture => { - modified_gm.halfmoves = 0; - modified_gm.en_passant_target = String::new() + Color::White => { + if modified_gm.bitboard.king_white & enemy_attacked == 0 { + // Good move; push it. + legal_moves.push((mv.0.clone(), mv.1, mv.2, mv.3.clone(), modified_gm)); + } } - _ => modified_gm.halfmoves = 0, - } - - // Continue to check against each bitboard with moves from the corresponding piece type. - let psl_pawn_moves: Vec<(PieceType, Square, Square, MoveType)> = - pseudolegal_moves::pseudolegal_pawn_moves( - // Should be the opposite of the current color. - if color == Color::Black { - Color::White - } else { - Color::Black - }, - &MOVETABLE, - GameManager::powers_of_two(match color { - Color::Black => modified_gm.bitboard.pawns_white, - Color::White => modified_gm.bitboard.pawns_black, - }), - friendly_pieces, - enemy_pieces, - &modified_gm.en_passant_target, - ); - if psl_pawn_moves.iter().fold(0, |acc, mv| acc | mv.2.to_u64()) & friendly_king != 0 { - // Position is bad. - continue 'pslms; - } - - let psl_rook_moves: Vec<(PieceType, Square, Square, MoveType)> = - pseudolegal_moves::pseudolegal_rook_moves( - if color == Color::Black { - Color::White - } else { - Color::Black - }, - &MOVETABLE, - GameManager::powers_of_two(match color { - Color::Black => modified_gm.bitboard.rooks_white, - Color::White => modified_gm.bitboard.rooks_black, - }), - friendly_pieces, - enemy_pieces, - ); - if psl_rook_moves.iter().fold(0, |acc, mv| acc | mv.2.to_u64()) & friendly_king != 0 { - // Position is bad. - continue 'pslms; } - - let psl_knight_moves: Vec<(PieceType, Square, Square, MoveType)> = - pseudolegal_moves::pseudolegal_knight_moves( - if color == Color::Black { - Color::White - } else { - Color::Black - }, - &MOVETABLE, - GameManager::powers_of_two(match color { - Color::Black => modified_gm.bitboard.knights_white, - Color::White => modified_gm.bitboard.knights_black, - }), - friendly_pieces, - enemy_pieces, - ); - if psl_knight_moves - .iter() - .fold(0, |acc, mv| acc | mv.2.to_u64()) - & friendly_king - != 0 - { - // Position is bad. - continue 'pslms; - } - - let psl_bishop_moves: Vec<(PieceType, Square, Square, MoveType)> = - pseudolegal_moves::pseudolegal_bishop_moves( - if color == Color::Black { - Color::White - } else { - Color::Black - }, - &MOVETABLE, - GameManager::powers_of_two(match color { - Color::Black => modified_gm.bitboard.bishops_white, - Color::White => modified_gm.bitboard.bishops_black, - }), - friendly_pieces, - enemy_pieces, - ); - if psl_bishop_moves - .iter() - .fold(0, |acc, mv| acc | mv.2.to_u64()) - & friendly_king - != 0 - { - // Position is bad. - continue 'pslms; - } - - let psl_queen_moves: Vec<(PieceType, Square, Square, MoveType)> = - pseudolegal_moves::pseudolegal_queen_moves( - if color == Color::Black { - Color::White - } else { - Color::Black - }, - &MOVETABLE, - GameManager::powers_of_two(match color { - Color::Black => modified_gm.bitboard.queens_white, - Color::White => modified_gm.bitboard.queens_black, - }), - friendly_pieces, - enemy_pieces, - ); - if psl_queen_moves - .iter() - .fold(0, |acc, mv| acc | mv.2.to_u64()) - & friendly_king - != 0 - { - // Position is bad. - continue 'pslms; - } - - let psl_king_moves: Vec<(PieceType, Square, Square, MoveType)> = - pseudolegal_moves::pseudolegal_king_moves( - if color == Color::Black { - Color::White - } else { - Color::Black - }, - &MOVETABLE, - GameManager::powers_of_two(match color { - Color::Black => modified_gm.bitboard.king_white, - Color::White => modified_gm.bitboard.king_black, - }), - friendly_pieces, - friendly_rooks, - enemy_pieces, - modified_gm.castling_rights, - ); - if psl_king_moves.iter().fold(0, |acc, mv| acc | mv.2.to_u64()) & friendly_king != 0 { - // Position is bad. - continue 'pslms; - } - - // Passed all the checks against every enemy piece. King wasn't under threat after all. - legal_moves.push((piecetype, from, to, movetype, modified_gm)); } legal_moves diff --git a/src/gamemanager/mod.rs b/src/gamemanager/mod.rs index 75aa03e..f225248 100644 --- a/src/gamemanager/mod.rs +++ b/src/gamemanager/mod.rs @@ -206,7 +206,6 @@ mod test { game_manager.fullmoves, ); - dbg!(&moves); assert_eq!( moves.iter().count(), 20 /* 20 valid moves at start of game. */ diff --git a/src/gamemanager/pseudolegal_moves/kings.rs b/src/gamemanager/pseudolegal_moves/kings.rs index 61b4a0e..da96346 100644 --- a/src/gamemanager/pseudolegal_moves/kings.rs +++ b/src/gamemanager/pseudolegal_moves/kings.rs @@ -119,7 +119,6 @@ pub fn pseudolegal_king_moves( )); } } - // TODO, BUG: Why is the White match arm so much different from the Black one? Color::White => { for king in king_locations { for r in movetable.get_moves(Color::White, PieceType::King, king) { @@ -255,8 +254,6 @@ mod tests { .cloned(), ); - dbg!(&pslnm); - assert!(pslnm.iter().all(|m| moves.contains(&m.2.to_u64()))); assert_eq!(pslnm.len(), moves.len()) } @@ -289,8 +286,6 @@ mod tests { .cloned(), ); - dbg!(&pslnm); - assert!(pslnm.iter().all(|m| moves.contains(&m.2.to_u64()))); assert_eq!(pslnm.len(), moves.len()) } diff --git a/src/gamemanager/pseudolegal_moves/mod.rs b/src/gamemanager/pseudolegal_moves/mod.rs index 1e68328..955725d 100644 --- a/src/gamemanager/pseudolegal_moves/mod.rs +++ b/src/gamemanager/pseudolegal_moves/mod.rs @@ -10,13 +10,6 @@ pub mod pawns; pub mod queens; pub mod rooks; -pub use bishops::pseudolegal_bishop_moves; -pub use kings::pseudolegal_king_moves; -pub use knights::pseudolegal_knight_moves; -pub use pawns::pseudolegal_pawn_moves; -pub use queens::pseudolegal_queen_moves; -pub use rooks::pseudolegal_rook_moves; - use crate::{ bitboard::BitBoard, gamemanager::GameManager, diff --git a/src/main.rs b/src/main.rs index 16ac65b..c315fdd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,10 +1,8 @@ #![allow(dead_code)] use std::sync::LazyLock; -use crate::types::{Color, PieceType}; use gamemanager::GameManager; use movetable::MoveTable; -use types::Square; mod bitboard; mod gamemanager; @@ -33,8 +31,6 @@ fn main() { // ) // ); } - - ucimanager::communicate(); } #[cfg(test)] @@ -73,7 +69,6 @@ mod test { let game = GameManager::from_fen_string(fen); let generated_fen = game.to_fen_string(); - dbg!(&fen, &generated_fen); assert_eq!(fen, generated_fen); } } diff --git a/src/movetable.rs b/src/movetable.rs index ad4e512..bb51e50 100644 --- a/src/movetable.rs +++ b/src/movetable.rs @@ -578,8 +578,6 @@ mod test { let table = MoveTable::default(); let rays = table.get_moves(Color::Black, PieceType::Knight, Square::B8.to_u64()); - dbg!(&rays); - let mut pslm: HashSet = HashSet::new(); pslm.insert(0x800000000000); pslm.insert(0x200000000000); @@ -669,7 +667,6 @@ mod test { let all_are_members = rays.iter().all(|r| r.iter().all(|m| pslm.contains(m))); let only_seven = rays.iter().fold(0, |acc, r| acc + r.iter().count()); - dbg!(&rays); assert!(all_are_members); assert_eq!(only_seven, 7); } diff --git a/stockfishOutput.txt b/stockfishOutput.txt deleted file mode 100644 index 6807125..0000000 --- a/stockfishOutput.txt +++ /dev/null @@ -1,44 +0,0 @@ -a2a3: 1 -b2b3: 1 -c2c3: 1 -g2g3: 1 -h2h3: 1 -a2a4: 1 -b2b4: 1 -g2g4: 1 -h2h4: 1 -d7c8q: 1 -d7c8r: 1 -d7c8b: 1 -d7c8n: 1 -b1d2: 1 -b1a3: 1 -b1c3: 1 -e2g1: 1 -e2c3: 1 -e2g3: 1 -e2d4: 1 -e2f4: 1 -c1d2: 1 -c1e3: 1 -c1f4: 1 -c1g5: 1 -c1h6: 1 -c4b3: 1 -c4d3: 1 -c4b5: 1 -c4d5: 1 -c4a6: 1 -c4e6: 1 -c4f7: 1 -h1f1: 1 -h1g1: 1 -d1d2: 1 -d1d3: 1 -d1d4: 1 -d1d5: 1 -d1d6: 1 -e1f1: 1 -e1d2: 1 -e1f2: 1 -e1g1: 1 diff --git a/stockfishOutputD2.txt b/stockfishOutputD2.txt deleted file mode 100644 index 6c717f1..0000000 --- a/stockfishOutputD2.txt +++ /dev/null @@ -1,44 +0,0 @@ -a2a3: 34 -b2b3: 34 -c2c3: 34 -g2g3: 34 -h2h3: 34 -a2a4: 34 -b2b4: 33 -g2g4: 34 -h2h4: 34 -d7c8q: 31 -d7c8r: 31 -d7c8b: 41 -d7c8n: 41 -b1d2: 34 -b1a3: 34 -b1c3: 34 -e2g1: 34 -e2c3: 34 -e2g3: 34 -e2d4: 34 -e2f4: 34 -c1d2: 34 -c1e3: 34 -c1f4: 34 -c1g5: 32 -c1h6: 31 -c4b3: 34 -c4d3: 34 -c4b5: 34 -c4d5: 35 -c4a6: 33 -c4e6: 35 -c4f7: 32 -h1f1: 34 -h1g1: 34 -d1d2: 34 -d1d3: 34 -d1d4: 34 -d1d5: 35 -d1d6: 28 -e1f1: 34 -e1d2: 34 -e1f2: 28 -e1g1: 34