#python code
import random;
import time;
import os;
steps=10;
startx=0;
starty=0;
currentPosX=startx+steps;
currentPosY=starty+steps;
N=2*steps+1;
Matrix = [[0 for x in xrange(N)] for x in xrange(N)];
# this matrix is for a 2d array representing
# if the position was walked visited in the RW or not
def printMatrix(x, y):
matString="";
for i in xrange(N):
for j in xrange(N):
if i == x and j == y :
matString=matString+" "+"\x1B[31;48m" + str(Matrix[i][j]) + "\x1B[0m";
else:
# print the visited elements in blue
if Matrix[i][j] > 0 :
matString=matString+" "+"\x1B[34;48m" +str(Matrix[i][j]) + "\x1B[0m";
else:
matString=matString+" "+str(Matrix[i][j]);
matString=matString+"\n";
print matString;
iterations=1000;
for cntr in range(iterations):
Matrix[currentPosX][currentPosY]+=1;
os.system('clear');
printMatrix(currentPosX, currentPosY);
rnd = random.randint(0,3);
if rnd == 0:
currentPosX -= 1;
elif rnd == 1:
currentPosX += 1;
elif rnd == 2:
currentPosY -= 1;
elif rnd == 3:
currentPosY += 1;
# ensure the bounds
# not keeping it perfectly uniform, but just going in the other direction if the bounds are cross -- this is a hack
if currentPosX == -1:
currentPosX = 1;
if currentPosY == -1:
currentPosY = 1;
if currentPosX == N:
currentPosX = N-2;
if currentPosY == N:
currentPosY = N-2;
time.sleep(0.1);