Try this one without hints. If you get stuck or frustrated, then come back here and scroll down.
The hard way is to keep track of the rooms that you have been in already. You can use a vector for that. If you visit a room twice, return "Lose".
The easy way is to realize that if you win, you will do it in within a threshhold of steps. Count your steps, while you are simulating the game, and if you exceed the threshhold, then you have to be in an infinite loop: Return "Lose".
I'm not providing a solution for this one, because I assign it as an in-lab problem. You should shoot for getting this one in under 7 minutes or so.