Better utility function for minimax