Advertisement
Guest User

Untitled

a guest
Apr 26th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1.  
  2. #Import modules
  3. import numpy as np
  4. import random
  5. from random import random as nprnd
  6. import matplotlib.pyplot as plt
  7.  
  8. #Initialization - definition of variables
  9. L = 8 # this is the side length of the matrix
  10. center = int(L*(1/2))
  11. mat = np.zeros((L, L)) #matrix of 60 by 60
  12. mat [center, center] = 1 #define center as 1
  13. #walker = (x, y) #where the walker will be
  14. Nwalker_max = 10 #this is what we called “max required stationary points” -- how many dots total
  15. n = 1 #Intial number of walkers (the stationary dot)
  16.  
  17. def create(): #func that creates a walker, and converts randomly generated side and position within that side to an ORIGINAL position x and y
  18. 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
  19. pos = random.randint(0, L-1) #choose a random position
  20.  
  21. if (side == 0):
  22. x = pos
  23. y = 0
  24. elif (side == 1):
  25. x = 0
  26. y = pos
  27. elif (side == 2):
  28. x = pos
  29. y = L-1
  30. else:
  31. x = L -1
  32. y = pos
  33. return (x, y)
  34.  
  35.  
  36. for i in (1, Nwalker_max): #a for loop that keeps adding walkers (walkers = new dots)
  37. walker = create() #matches the walker’s position x, y as that generated by the function create
  38. x,y = walker
  39. print(x,y)
  40. while (True): #
  41. walker_direction = random.randint(0, 3)# walker direction -- important for boundary verification
  42. print(walker_direction)
  43. if walker_direction == 0:
  44. delta_x, delta_y = 0, 1
  45. elif walker_direction == 1:
  46. delta_x, delta_y = 0, -1
  47. elif walker_direction == 2:
  48. delta_x, delta_y = 1, 0
  49. else:
  50. delta_x, delta_y = -1, 0
  51. #print(delta_x, delta_y)
  52.  
  53.  
  54.  
  55. 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
  56. if mat[x+delta_x, y+delta_y] == 1:
  57. mat[x, y] = 1
  58. break
  59. x, y = x+delta_x, y+delta_y
  60. print(x+delta_x, y+delta_y)
  61. continue
  62. else:
  63. delta_x, delta_y = 0, 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement