fixed optimal_move method