Act 3 scene iv, lines 207 ff
Hamlet kills Polonius in Gertrude's room and reminds her that he has to go to England. He willingly heads for the ship with a pair of friends whom he considers no better than rattlesnakes, on the orders of a king whom he now knows to be a murderer. Oh, no prob, he says. "I'm just going for the sport of outsmarting them and blowing up their plans."
Pretty high opinion of his own abilities. THIS from a guy who has just ignored his target, accidentally killed the wrong guy, hidden the body for no good reason, and then revealed it upon a few minutes of questioning. This from a guy who was just told by the ghost to get on with killing Claudius.
Is that hoist on his own petard speech another of Hamlet's avoidance techniques? He does wind up eliminating two threats to his life while at sea (R&G), but that's only thanks to a lucky pirate attack. **********
[Even when he's on his way to the ship, he runs across someone who reminds him yet again that he's dawdling. So he swears and swears he's set on revenge -- and then gets on the ship for England.]
WOOPS, wait, I got the timing wrong. The pirate attack occurs after Hamlet foils the R&G plot. But still, it was sort of an accident that he went stumbling around while everyone else was sleeping and happened on the death warrant.