def portal_generator(self):
if self.n_doors % 2 != 0:
raise Exception("Number of doors needs to be even.")
# this is because every door needs a connecting door
doors = list(range(self.n_doors)) # make array list of size n_doors
doors = [i + 1 for i in doors] # add 1 to each array item to account for index zero
portal_connections = {}
# for connection in range(1, n_connections):
while len(doors) > 0:
random.shuffle(doors)
point_a = doors[0]
doors.remove(point_a)
point_b = doors[0]
doors.remove(point_b)
portal_connections[point_a] = point_b
portal_connections[point_b] = point_a
floors_n_doors = {}
n_doorsperfloor = math.ceil(self.n_doors / self.n_floors) # round up to nearest integer
# assign doors to each floor
doors_list = list(range(1, self.n_doors+1))
for floor in range(1, self.n_floors+1): # 1 thru 4 floors floorsndoors[4] = range 3*3+1, 10
doors = doors_list[:n_doorsperfloor]
floors_n_doors[floor] = doors # assign doors to floor
doors_list = doors_list[n_doorsperfloor:] # remove doors of that floor from doors_list
assignments = [portal_connections, floors_n_doors]
return assignments