def test_castling_queen_side(): g = Game() g.move(("B", 1), ("A", 3)) g.move(("B", 8), ("A", 6)) g.move(("D", 2), ("D", 3)) g.move(("D", 7), ("D", 6)) g.move(("C", 2), ("C", 3)) g.move(("C", 7), ("C", 6)) g.move(("C", 1), ("D", 2)) g.move(("C", 8), ("D", 7)) g.move(("D", 1), ("C", 2)) g.move(("D", 8), ("C", 7)) g.update_all_pieces() assert (g.is_legal_move("WHITE", ("E", 1), ("C", 1))) g.move(("E", 1), ("C", 1)) assert (not g.board.is_empty(("C", 1))) assert (g.board.piece_at(("C", 1)).piece_type == "King") assert (not g.board.is_empty(("D", 1))) assert (g.board.piece_at(("D", 1)).piece_type == "Rook") ## Now have black do the same assert (g.is_legal_move("BLACK", ("E", 8), ("C", 8))) g.move(("E", 8), ("C", 8)) assert (not g.board.is_empty(("C", 8))) assert (g.board.piece_at(("C", 8)).piece_type == "King") assert (not g.board.is_empty(("D", 8))) assert (g.board.piece_at(("D", 8)).piece_type == "Rook")
def test_promotion(): g = Game() g.clear() g.add_piece(Pawn("WHITE"), ("B", 7)) g.add_piece(King("WHITE"), ("E", 1)) g.add_piece(Pawn("BLACK"), ("G", 2)) g.add_piece(King("BLACK"), ("E", 7)) g.update_all_pieces() assert (g.is_legal_move("WHITE", ("B", 7), ("B", 8))) g.move(("B", 7), ("B", 8)) assert (g.board.piece_at(("B", 8)).piece_type == "Queen") g.update_all_pieces() assert (g.is_legal_move("BLACK", ("G", 2), ("G", 1))) g.move(("G", 2), ("G", 1)) assert (g.board.piece_at(("G", 1)).piece_type == "Queen")
def test_cant_castle_after_moving(): g = Game() g.move(("G", 1), ("H", 3)) g.move(("G", 8), ("H", 6)) g.move(("E", 2), ("D", 3)) g.move(("E", 7), ("D", 6)) g.move(("F", 1), ("E", 2)) g.move(("F", 8), ("E", 7)) ## move white king g.move(("E", 1), ("F", 1)) ## and black rook g.move(("H", 8), ("G", 8)) ## and move both back again g.move(("F", 1), ("E", 1)) g.move(("G", 8), ("H", 8)) g.update_all_pieces() assert (not g.is_legal_move("WHITE", ("E", 1), ("G", 1))) ## Now have black do the same assert (not g.is_legal_move("BLACK", ("E", 8), ("G", 8)))
def test_black_pawn_move(): g = Game() assert (not g.is_legal_move("BLACK", ("A", 7), ("A", 5)))