added code for optimal_move