Im trying to write a random walk sim where the field size is limited to 10 x 10 m. My idea was to limit x and y to -10 to +10 in a while loop, but it does not work. x and/or y keeps getting bigger than 10 or less than -10.
I have tried to break up the while loop parameters to something easier but it still didnt work
what am i doing wrong?
def move(self, steps):
global lastStep
x = 0.0
y = 0.0
while -10 <= x <= 10 and -10 <= y <= 10 :
for i in range(steps):
# print("before field test; ", x, y)
step = random.choice(['N', 'W', 'S', 'E'])
if step == 'N':
y += 0.5
elif step == 'S':
y -= 0.5
elif step == 'E':
x += 0.5
elif step == 'W':
x -= 0.5
else:
raise ValueError ("In Drunk.move")
lastStep = step
return x, y
return x, y