Rename fn names for better readability
This commit is contained in:
@@ -34,12 +34,12 @@ impl Game {
|
||||
Self {
|
||||
board: Board::new(),
|
||||
history: History::new(),
|
||||
mailbox: Mailbox::new_from_board(&Board::new()),
|
||||
mailbox: Mailbox::from_board(&Board::new()),
|
||||
hash: zobrist_keys().calculate_hash(&Board::new()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new_from_fen(fen: &str) -> Result<Self, FenError> {
|
||||
pub fn from_fen(fen: &str) -> Result<Self, FenError> {
|
||||
from_fen(fen)
|
||||
}
|
||||
|
||||
@@ -64,9 +64,9 @@ impl Game {
|
||||
let old_castling_ability = board.state.castling_ability;
|
||||
|
||||
let piece_at_src = mailbox
|
||||
.find_piece_at(mv.src)
|
||||
.piece_at(mv.src)
|
||||
.expect("Expected piece at: {mv.src}");
|
||||
let piece_at_dst = mailbox.find_piece_at(mv.dst);
|
||||
let piece_at_dst = mailbox.piece_at(mv.dst);
|
||||
match &mv.move_type {
|
||||
MoveType::Quiet => {
|
||||
board.move_piece(mv.src, mv.dst, piece_at_src);
|
||||
@@ -83,7 +83,7 @@ impl Game {
|
||||
MoveType::EnPassant => {
|
||||
board.move_piece(mv.src, mv.dst, piece_at_src);
|
||||
let piece_at_capture = mailbox
|
||||
.find_piece_at(capture_square)
|
||||
.piece_at(capture_square)
|
||||
.expect("Expected piece at: {capture_square}");
|
||||
board.remove_opponent_piece(capture_square, PieceType::Pawn);
|
||||
hash.update_en_passant(mv.src, mv.dst, piece_at_src, piece_at_capture, color);
|
||||
@@ -182,11 +182,11 @@ impl Game {
|
||||
}
|
||||
|
||||
let mv = move_parameters.mv.unwrap();
|
||||
let piece_at_dst = mailbox.find_piece_at(mv.dst).expect("Expected set piece");
|
||||
let piece_at_dst = mailbox.piece_at(mv.dst).expect("Expected set piece");
|
||||
match &mv.move_type {
|
||||
MoveType::Quiet | MoveType::DoublePush => {
|
||||
board.move_piece(mv.dst, mv.src, piece_at_dst);
|
||||
mailbox.set_piece_at(mv.src, mailbox.find_piece_at(mv.dst));
|
||||
mailbox.set_piece_at(mv.src, mailbox.piece_at(mv.dst));
|
||||
mailbox.set_piece_at(mv.dst, None);
|
||||
}
|
||||
MoveType::Capture => {
|
||||
@@ -240,7 +240,7 @@ impl Game {
|
||||
board.move_piece(mv.dst, mv.src, piece_at_dst);
|
||||
board.remove_own_piece(rook_dst, PieceType::Rook);
|
||||
board.insert_own_piece(rook_src, PieceType::Rook);
|
||||
mailbox.set_piece_at(mv.src, mailbox.find_piece_at(mv.dst));
|
||||
mailbox.set_piece_at(mv.src, mailbox.piece_at(mv.dst));
|
||||
mailbox.set_piece_at(mv.dst, None);
|
||||
mailbox.set_piece_at(rook_src, Some(PieceType::Rook));
|
||||
mailbox.set_piece_at(rook_dst, None);
|
||||
@@ -283,7 +283,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_make_move_capture() -> Result<(), String> {
|
||||
let mut game = from_fen(FEN)?;
|
||||
let f3f5 = Move::new_with_type(Square::F3, Square::F5, MoveType::Capture);
|
||||
let f3f5 = Move::with_type(Square::F3, Square::F5, MoveType::Capture);
|
||||
game.make_move(&f3f5);
|
||||
|
||||
assert_eq!(game, from_fen(FEN_CAPTURE)?);
|
||||
@@ -297,7 +297,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_make_move_en_passant() -> Result<(), String> {
|
||||
let mut game = from_fen(FEN)?;
|
||||
let h5g6 = Move::new_with_type(Square::H5, Square::G6, MoveType::EnPassant);
|
||||
let h5g6 = Move::with_type(Square::H5, Square::G6, MoveType::EnPassant);
|
||||
game.make_move(&h5g6);
|
||||
|
||||
assert_eq!(game, from_fen(FEN_EN_PASSANT)?);
|
||||
@@ -311,7 +311,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_make_move_double_push() -> Result<(), String> {
|
||||
let mut game = from_fen(FEN)?;
|
||||
let b2b4 = Move::new_with_type(Square::B2, Square::B4, MoveType::DoublePush);
|
||||
let b2b4 = Move::with_type(Square::B2, Square::B4, MoveType::DoublePush);
|
||||
game.make_move(&b2b4);
|
||||
assert_eq!(game, from_fen(FEN_DOUBLE_PUSH)?);
|
||||
|
||||
@@ -323,7 +323,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_make_move_promotion() -> Result<(), String> {
|
||||
let mut game = from_fen(FEN)?;
|
||||
let c7c8 = Move::new_with_type(Square::C7, Square::C8, MoveType::Promotion(Promote::Queen));
|
||||
let c7c8 = Move::with_type(Square::C7, Square::C8, MoveType::Promotion(Promote::Queen));
|
||||
game.make_move(&c7c8);
|
||||
assert_eq!(game, from_fen(FEN_PROMOTION)?);
|
||||
|
||||
@@ -336,7 +336,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_make_move_promotion_capture() -> Result<(), String> {
|
||||
let mut game = from_fen(FEN)?;
|
||||
let c7b8 = Move::new_with_type(
|
||||
let c7b8 = Move::with_type(
|
||||
Square::C7,
|
||||
Square::B8,
|
||||
MoveType::PromotionCapture(Promote::Queen),
|
||||
@@ -352,7 +352,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_make_move_castle() -> Result<(), String> {
|
||||
let mut game = from_fen(FEN)?;
|
||||
let e1g1 = Move::new_with_type(Square::E1, Square::G1, MoveType::Castle);
|
||||
let e1g1 = Move::with_type(Square::E1, Square::G1, MoveType::Castle);
|
||||
game.make_move(&e1g1);
|
||||
assert_eq!(game, from_fen(FEN_CASTLE)?);
|
||||
Ok(())
|
||||
@@ -365,13 +365,13 @@ mod tests {
|
||||
fn test_unmake_quiet_and_double_push() -> Result<(), String> {
|
||||
let mut game = from_fen(FEN_1)?;
|
||||
let game_before_make = game.clone();
|
||||
let mv = Move::new_with_type(Square::B2, Square::B3, MoveType::Quiet);
|
||||
let mv = Move::with_type(Square::B2, Square::B3, MoveType::Quiet);
|
||||
game.make_move(&mv);
|
||||
game.unmake_move();
|
||||
|
||||
assert_eq!(game_before_make, game);
|
||||
|
||||
let mv = Move::new_with_type(Square::B2, Square::B4, MoveType::DoublePush);
|
||||
let mv = Move::with_type(Square::B2, Square::B4, MoveType::DoublePush);
|
||||
game.make_move(&mv);
|
||||
game.unmake_move();
|
||||
|
||||
@@ -384,19 +384,19 @@ mod tests {
|
||||
fn test_unmake_capture_and_promotion() -> Result<(), String> {
|
||||
let mut game = from_fen(FEN_1)?;
|
||||
let game_before_make = game.clone();
|
||||
let mv = Move::new_with_type(Square::D3, Square::B5, MoveType::Capture);
|
||||
let mv = Move::with_type(Square::D3, Square::B5, MoveType::Capture);
|
||||
game.make_move(&mv);
|
||||
game.unmake_move();
|
||||
|
||||
assert_eq!(game_before_make, game);
|
||||
|
||||
let mv = Move::new_with_type(Square::C7, Square::C8, MoveType::Promotion(Promote::Queen));
|
||||
let mv = Move::with_type(Square::C7, Square::C8, MoveType::Promotion(Promote::Queen));
|
||||
game.make_move(&mv);
|
||||
game.unmake_move();
|
||||
|
||||
assert_eq!(game_before_make, game);
|
||||
|
||||
let mv = Move::new_with_type(
|
||||
let mv = Move::with_type(
|
||||
Square::C7,
|
||||
Square::B8,
|
||||
MoveType::PromotionCapture(Promote::Queen),
|
||||
@@ -413,7 +413,7 @@ mod tests {
|
||||
fn test_unmake_en_passant() -> Result<(), String> {
|
||||
let mut game = from_fen(FEN_2)?;
|
||||
let game_before_make = game.clone();
|
||||
let mv = Move::new_with_type(Square::A4, Square::B3, MoveType::EnPassant);
|
||||
let mv = Move::with_type(Square::A4, Square::B3, MoveType::EnPassant);
|
||||
game.make_move(&mv);
|
||||
game.unmake_move();
|
||||
|
||||
@@ -426,7 +426,7 @@ mod tests {
|
||||
fn test_unmake_castle() -> Result<(), String> {
|
||||
let mut game = from_fen(FEN_1)?;
|
||||
let game_before_make = game.clone();
|
||||
let mv = Move::new_with_type(Square::E1, Square::C1, MoveType::Castle);
|
||||
let mv = Move::with_type(Square::E1, Square::C1, MoveType::Castle);
|
||||
game.make_move(&mv);
|
||||
game.unmake_move();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user