I Wrote the code for self avoiding random walk but when i ran in Terminal of PyCharm, the result was 0.0 for any parameters.What is the problem? anyone can help? The code is :
import sys
import random
n = int(sys.argv[1])
trials = int(sys.argv[2])
Dead_ends = 0
for t in range(trials):
a = [[False] * n] * n
x, y = n // 2, n // 2
while 0 < x < n - 1 and 0 < y < n - 1:
if a[x - 1][y] and a[x + 1][y] and a[x][y + 1] and a[x][y - 1]:
Dead_ends += 1
break
a[x][y] = True
r = random.random()
if r < 0.25:
if not a[x + 1][y]: x += 1
elif r < 0.5:
if not a[x - 1][y]: x -= 1
elif r < 0.75:
if not a[x][y + 1]: y += 1
else:
if not a[x][y - 1]: y -= 1
print(100 * Dead_ends // trials)