Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- import numpy as np
- #cs is grid size or seats, ns is number of agents
- class Seats():
- def __init__(self, cs, ns):
- self.cs = cs
- self.ns = ns
- self.seats = np.zeros([self.cs, self.cs],dtype=int)
- def foundseat(self):
- foundseat = False
- tries = 0
- while foundseat == False and tries <= 3:
- x = random.randint(0, self.cs)
- y = random.randint(0, self.cs)
- if self.seats[x][y] < 1:
- self.seats[x][y] = 1
- foundseat = True
- else:
- tries += 1
- def goodseat(self, x,y):
- empty_neighbors = 0
- for neighbor_x in range(x-1,x+1):
- for neighbor_y in range(y-1,y+1):
- if self.seats[neighbor_x][neighbor_y] == 0:
- empty_neighbors = empty_neighbors + 1
Add Comment
Please, Sign In to add comment