def test_points_queen_escape(): g = Game() g.clear() g.add_piece(Pawn("BLACK"), ("C", 3)) g.add_piece(Queen("WHITE"), ("B", 2)) assert (len(g.board.pieces) == 2) g.update_all_pieces() player = BestNextPointsPlayer("WHITE") points = player.potential_points_for_move(g, "WHITE", (("B", 2), ("B", 3))) assert (points == 9)
def test_points_rook_threaten(): g = Game() g.clear() g.add_piece(Pawn("WHITE"), ("A", 3)) g.add_piece(Rook("BLACK"), ("B", 8)) assert (len(g.board.pieces) == 2) g.next_to_play = "BLACK" g.update_all_pieces() player = BestNextPointsPlayer("BLACK") points = player.potential_points_for_move(g, "BLACK", (("B", 8), ("B", 4))) assert (points == -5)
def test_checkmate(): g = Game() g.clear() g.add_piece(King("BLACK"), ("H", 8)) g.add_piece(Queen("WHITE"), ("G", 7)) g.add_piece(Rook("WHITE"), ("G", 6)) assert (len(g.board.pieces) == 3) g.update_all_pieces() g.next_player_turn() assert (g.is_check("BLACK")) assert (g.is_checkmate("BLACK"))
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_no_checkmate_king_takes(): """ Problem seen when game declared checkmate even though king could have taken the piece threatening it - check this is fixed. """ g = Game() g.clear() g.add_piece(King("BLACK"), ("H", 8)) g.add_piece(King("WHITE"), ("E", 1)) g.add_piece(Pawn("WHITE"), ("E", 2)) g.add_piece(Pawn("WHITE"), ("F", 2)) g.add_piece(Queen("BLACK"), ("D", 5)) g.update_all_pieces() g.next_player_turn() g.move(("D", 5), ("D", 1)) assert (not g.is_checkmate("WHITE"))