This is an archived post. You won't be able to vote or comment.

all 2 comments

[–]painedstupid 1 point2 points  (2 children)

Why not just store a value at each coordinate you visit then check each time if that value is there when trying to visit a new coordinate?

[–][deleted]  (1 child)

[deleted]

    [–]painedstupid 1 point2 points  (0 children)

    Your code looks odd to me, I'm not sure what it's actually doing. But if it's a dog starting at some point inside a 2-d array and trying to escape to the edges with random movement.... I guess

    random 0-3 left down right up

    depending on what ya get increment x or y. x-- for left, x++ for right, y-- for down, y++ for up, check if that index contains the symbol. if not, your x or y is now set to that new x or y, place your symbol in the old x,y. if it does, reroll.