Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Import modules
- import numpy as np
- import random
- from random import random as nprnd
- import matplotlib.pyplot as plt
- #Initialization - definition of variables
- L = 8 # this is the side length of the matrix
- center = int(L*(1/2))
- mat = np.zeros((L, L)) #matrix of 60 by 60
- mat [center, center] = 1 #define center as 1
- #walker = (x, y) #where the walker will be
- Nwalker_max = 10 #this is what we called “max required stationary points” -- how many dots total
- n = 1 #Intial number of walkers (the stationary dot)
- def create(): #func that creates a walker, and converts randomly generated side and position within that side to an ORIGINAL position x and y
- side = random.randint(0, 3) # Choose side. This is not done. he said we have to make python know which side is which, so that it know that leftmost column is side =0, upmost row is side 1, rightmost column is side 2, downmost row is side 3
- pos = random.randint(0, L-1) #choose a random position
- if (side == 0):
- x = pos
- y = 0
- elif (side == 1):
- x = 0
- y = pos
- elif (side == 2):
- x = pos
- y = L-1
- else:
- x = L -1
- y = pos
- return (x, y)
- for i in (1, Nwalker_max): #a for loop that keeps adding walkers (walkers = new dots)
- walker = create() #matches the walker’s position x, y as that generated by the function create
- x,y = walker
- print(x,y)
- while (True): #
- walker_direction = random.randint(0, 3)# walker direction -- important for boundary verification
- print(walker_direction)
- if walker_direction == 0:
- delta_x, delta_y = 0, 1
- elif walker_direction == 1:
- delta_x, delta_y = 0, -1
- elif walker_direction == 2:
- delta_x, delta_y = 1, 0
- else:
- delta_x, delta_y = -1, 0
- #print(delta_x, delta_y)
- if x + delta_x in range (0, L) and y+delta_y in range (0, L): #if the motion is allowed, continue; if not, interrupt
- if mat[x+delta_x, y+delta_y] == 1:
- mat[x, y] = 1
- break
- x, y = x+delta_x, y+delta_y
- print(x+delta_x, y+delta_y)
- continue
- else:
- delta_x, delta_y = 0, 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement