For the most part, "adivinar" is used pretty much the same way it is in English. You can say "The man is guessing" or "The man is trying to guess;" depends on what you are trying to say.
I would have to say the second sentence is awkward, in either language: "The boy is trying to guess if the bean is under the pink cap." He either guesses it's under the pink cap or not; he's not standing there, brow furrowed in concentration, attempting to guess it's under the pink cap.
He could try to guess under which cap the bean is, or he'd just guess it's under the pink cap ("El niño adivina que el guisante está debajo de la gorra rosada").
I hope this sort of answers your question... "adivinar" can be used with "tratar" or "inventar," but I wouldn't say it's typically used with one of them.