I have a random walk on a 2D grid with randomly initialised positions. I am looking for a condition, where if the random walk is within some range of the initial positions of the other random walks, it will stop.
While I found this easy to implement in the simple case, I am having trouble implementing it in the case of N random walks. This is due to the fact, that the code needs to check for a range of values around every initial position, except for the one, which is around the current random walk.
P.S This is my first post on stack overflow. Please, let me know if I was being too vague or did not follow the guidelines for asking questions on here.
import numpy.random as rd #importing libraries
import numpy as np
import matplotlib.pyplot as plt
import matplotlib
import numpy.ma as ma
lsize=100
T=1000 #n of steps
N=5 #n of walks
xvec=np.zeros(N)
yvec=np.zeros(N)
xstore=np.zeros(T+1)
ystore=np.zeros(T+1)
xmat=np.zeros((T+1,N))
ymat=np.zeros((T+1,N))
for i in range(N): #randomly assigns initial position
xcor=rd.randint(1,lsize)
ycor=rd.randint(1,lsize)
xvec[i]=xcor
yvec[i]=ycor
for i in range(N):
xstore[0]=xvec[i]
ystore[0]=yvec[i]
for j in range(T):
A=[0,1,2,3]
temp=rd.choice(A)
if temp==0:
ystore[j+1]=ystore[j]+1 #up
xstore[j+1]=xstore[j]
elif temp==1:
xstore[j+1]=xstore[j]+1 #right
ystore[j+1]=ystore[j]
elif temp==2:
ystore[j+1]=ystore[j]-1 #down
xstore[j+1]=xstore[j]
elif temp==3:
xstore[j+1]=xstore[j]-1 #left
ystore[j+1]=ystore[j]
xstore[j+1]=np.mod(xstore[j+1], lsize+1)
ystore[j+1]=np.mod(ystore[j+1], lsize+1)
xmat[:,i]=xstore
ymat[:,i]=ystore
plt.plot(xmat,ymat)
plt.show()