Guest User

Untitled

a guest
Apr 29th, 2016
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. import random
  2. import numpy as np
  3. #cs is grid size or seats, ns is number of agents
  4. class Seats():
  5. def __init__(self, cs, ns):
  6. self.cs = cs
  7. self.ns = ns
  8. self.seats = np.zeros([self.cs, self.cs],dtype=int)
  9.  
  10.  
  11. def foundseat(self):
  12. foundseat = False
  13. tries = 0
  14. while foundseat == False and tries <= 3:
  15. x = random.randint(0, self.cs)
  16. y = random.randint(0, self.cs)
  17. if self.seats[x][y] < 1:
  18. self.seats[x][y] = 1
  19. foundseat = True
  20. else:
  21. tries += 1
  22.  
  23. def goodseat(self, x,y):
  24. empty_neighbors = 0
  25. for neighbor_x in range(x-1,x+1):
  26. for neighbor_y in range(y-1,y+1):
  27.   if self.seats[neighbor_x][neighbor_y] == 0:
  28. empty_neighbors = empty_neighbors + 1
Add Comment
Please, Sign In to add comment