def __init__(self, velocity=1, position=Vec2D(), idx=-1): self.position = position self.velocity = velocity self.oldDirection = Vec2D() self.defaultvelocity = velocity self.idx = idx self.flag = False
def find_starting_point(self): # działa self.starting_point = [] for x in range(self.cellmap.shape[0]): for y in range(self.cellmap.shape[1]): if self.cellmap[x, y].kind == "road": if len(self.cellmap[x, y].direction) == 1: newPos = Vec2D(x, y).add( self.cellmap[x, y].direction[0].mul_int(-1)) if (0 > newPos.x > self.cellmap.shape[0] or 0 > newPos.y > self.cellmap.shape[1]): continue else: if self.cellmap[newPos.x, newPos.y].kind != "road": self.starting_point.append(Vec2D(x, y)) to_remove = [] for pos in self.starting_point: for i in range(-1, 2): for j in range(-1, 2): cell = self.cellmap[pos.x + i, pos.y + j] if any( Vec2D(pos.x + i + dire.x, pos.y + j + dire.y).equal(pos) for dire in cell.direction): to_remove.append(pos) try: for pos in to_remove: self.starting_point.remove(pos) except ValueError: pass
def create_cross_section(mp): for cell in mp.cellmap[25, :]: cell.kind = "road" cell.direction.append(Vec2D(0, 1)) for cell in mp.cellmap[:, 25]: cell.kind = "road" cell.direction.append(Vec2D(1, 0))
def __init__(self, N=7, offset=0, dir=Vec2D(), position=Vec2D()): self.N = N self.offset = offset self.currentColor = None self.position = position self.direction = dir if self.offset % self.N < math.ceil(3 * self.N / 7): self.currentColor = GREEN elif self.offset % self.N < math.ceil(4 * self.N / 7): self.currentColor = ORANGE else: self.currentColor = RED
def create_cross_section_t_left(mp): for cell in mp.cellmap[49, 1:]: cell.kind = "road" cell.direction.append(Vec2D(0, -1)) for cell in mp.cellmap[:, 0]: cell.kind = "road" cell.direction.append(Vec2D(1, 0)) for cell in mp.cellmap[51, 1:]: cell.kind = "road" cell.direction.append(Vec2D(0, 1)) for cell in mp.cellmap[:, 2]: cell.kind = "road" cell.direction.append(Vec2D(-1, 0))
def create_cross_section_t_right(mp): for cell in mp.cellmap[49, :99]: cell.kind = "road" cell.direction.append(Vec2D(0, -1)) for cell in mp.cellmap[:, 97]: cell.kind = "road" cell.direction.append(Vec2D(1, 0)) for cell in mp.cellmap[51, :99]: cell.kind = "road" cell.direction.append(Vec2D(0, 1)) for cell in mp.cellmap[:, 99]: cell.kind = "road" cell.direction.append(Vec2D(-1, 0))
def create_cross_section_t_up(mp): for cell in mp.cellmap[0, :]: cell.kind = "road" cell.direction.append(Vec2D(0, -1)) for cell in mp.cellmap[1:, 49]: cell.kind = "road" cell.direction.append(Vec2D(1, 0)) for cell in mp.cellmap[2, :]: cell.kind = "road" cell.direction.append(Vec2D(0, 1)) for cell in mp.cellmap[1:, 51]: cell.kind = "road" cell.direction.append(Vec2D(-1, 0))
def create_cross_section_t_down(mp): for cell in mp.cellmap[97, :]: cell.kind = "road" cell.direction.append(Vec2D(0, -1)) for cell in mp.cellmap[:99, 49]: cell.kind = "road" cell.direction.append(Vec2D(1, 0)) for cell in mp.cellmap[99, :]: cell.kind = "road" cell.direction.append(Vec2D(0, 1)) for cell in mp.cellmap[:99, 51]: cell.kind = "road" cell.direction.append(Vec2D(-1, 0))
def create_cross_section_x(mp): for cell in mp.cellmap[49, :]: cell.kind = "road" cell.direction.append(Vec2D(0, -1)) for cell in mp.cellmap[:, 49]: cell.kind = "road" cell.direction.append(Vec2D(1, 0)) for cell in mp.cellmap[51, :]: cell.kind = "road" cell.direction.append(Vec2D(0, 1)) for cell in mp.cellmap[:, 51]: cell.kind = "road" cell.direction.append(Vec2D(-1, 0))
def create_cross_section_x_light(mp): for cell in mp.cellmap[49, :]: cell.kind = "road" cell.direction.append(Vec2D(0, -1)) for cell in mp.cellmap[:, 49]: cell.kind = "road" cell.direction.append(Vec2D(1, 0)) for cell in mp.cellmap[51, :]: cell.kind = "road" cell.direction.append(Vec2D(0, 1)) for cell in mp.cellmap[:, 51]: cell.kind = "road" cell.direction.append(Vec2D(-1, 0)) mp.cellmap[48, 52].trafficLight = TrafficLight(98, 58, Vec2D(0, -1)) mp.cellmap[52, 48].trafficLight = TrafficLight(98, 58, Vec2D(0, 1)) mp.cellmap[48, 48].trafficLight = TrafficLight(98, 0, Vec2D(1, 0)) mp.cellmap[52, 52].trafficLight = TrafficLight(98, 0, Vec2D(-1, 0))
def create_cross_section_t_left_light(mp): for cell in mp.cellmap[49, 2:]: cell.kind = "road" cell.direction.append(Vec2D(0, -1)) for cell in mp.cellmap[:, 1]: cell.kind = "road" cell.direction.append(Vec2D(1, 0)) for cell in mp.cellmap[51, 2:]: cell.kind = "road" cell.direction.append(Vec2D(0, 1)) for cell in mp.cellmap[:, 3]: cell.kind = "road" cell.direction.append(Vec2D(-1, 0)) mp.cellmap[48, 0].trafficLight = TrafficLight(98, 0, Vec2D(1, 0)) mp.cellmap[48, 4].trafficLight = TrafficLight(98, 58, Vec2D(0, -1)) mp.cellmap[52, 4].trafficLight = TrafficLight(98, 0, Vec2D(-1, 0))
def create_cross_section_t_up_light(mp): for cell in mp.cellmap[1, :]: cell.kind = "road" cell.direction.append(Vec2D(0, -1)) for cell in mp.cellmap[2:, 49]: cell.kind = "road" cell.direction.append(Vec2D(1, 0)) for cell in mp.cellmap[3, :]: cell.kind = "road" cell.direction.append(Vec2D(0, 1)) for cell in mp.cellmap[2:, 51]: cell.kind = "road" cell.direction.append(Vec2D(-1, 0)) mp.cellmap[0, 52].trafficLight = TrafficLight(98, 58, Vec2D(0, -1)) mp.cellmap[4, 48].trafficLight = TrafficLight(98, 58, Vec2D(0, 1)) mp.cellmap[4, 52].trafficLight = TrafficLight(98, 0, Vec2D(-1, 0))
def create_cross_section_t_down_light(mp): for cell in mp.cellmap[96, :]: cell.kind = "road" cell.direction.append(Vec2D(0, -1)) for cell in mp.cellmap[:98, 49]: cell.kind = "road" cell.direction.append(Vec2D(1, 0)) for cell in mp.cellmap[98, :]: cell.kind = "road" cell.direction.append(Vec2D(0, 1)) for cell in mp.cellmap[:98, 51]: cell.kind = "road" cell.direction.append(Vec2D(-1, 0)) mp.cellmap[95, 52].trafficLight = TrafficLight(98, 58, Vec2D(0, -1)) mp.cellmap[99, 48].trafficLight = TrafficLight(98, 58, Vec2D(0, 1)) mp.cellmap[95, 48].trafficLight = TrafficLight(98, 0, Vec2D(1, 0))
def create_cross_section_t_right_light(mp): for cell in mp.cellmap[49, :98]: cell.kind = "road" cell.direction.append(Vec2D(0, -1)) for cell in mp.cellmap[:, 96]: cell.kind = "road" cell.direction.append(Vec2D(1, 0)) for cell in mp.cellmap[51, :98]: cell.kind = "road" cell.direction.append(Vec2D(0, 1)) for cell in mp.cellmap[:, 98]: cell.kind = "road" cell.direction.append(Vec2D(-1, 0)) mp.cellmap[52, 95].trafficLight = TrafficLight(98, 58, Vec2D(0, 1)) mp.cellmap[52, 99].trafficLight = TrafficLight(98, 0, Vec2D(-1, 0)) mp.cellmap[48, 95].trafficLight = TrafficLight(98, 0, Vec2D(1, 0))
def step(self, cars_number): # działa if self.car_distances is None: self.car_distances = [0] * cars_number self.currentIteration += 1 toRemove = [] self.slow_cars = 0 [light.update(self.currentIteration) for light in self.trafficLights] for light in self.trafficLights: self.colormap[light.position.x, light.position.y] = np.array(light.currentColor, dtype=np.uint8) for car in self.cars: jumps = 0 nextCellPos = car.position.add(car.oldDirection) potentialTrafficLightPosition = [ car.position.x + car.oldDirection.y, car.position.y - car.oldDirection.x, ] try: if car.velocity == 0 and ( (self.cellmap[nextCellPos.x, nextCellPos.y].car is None and car.flag is False) or (car.flag is True and self.cellmap[potentialTrafficLightPosition[0], potentialTrafficLightPosition[1], ]. trafficLight.currentColor != RED)): car.velocity = car.defaultvelocity car.flag = False except AttributeError: car.velocity = car.defaultvelocity car.flag = False for _ in range(car.velocity): # run nextCellPos = car.position.add(car.oldDirection) # if abs(car.oldDirection.y) == 1: # potentialTrafficLightPosition = [ # nextCellPos.x + car.oldDirection.y, # nextCellPos.y + car.oldDirection.x, # ] # else: # potentialTrafficLightPosition = [ # nextCellPos.x - car.oldDirection.y, # nextCellPos.y - car.oldDirection.x, # ] perp = car.oldDirection.perpendicular_clockwise() tr = nextCellPos.add(perp) potentialTrafficLightPosition = [tr.x, tr.y] cell = self.cellmap[car.position.x, car.position.y] if (self.cellmap[potentialTrafficLightPosition[0], potentialTrafficLightPosition[1], ]. trafficLight is not None and self.cellmap[potentialTrafficLightPosition[0], potentialTrafficLightPosition[1], ]. trafficLight.direction.equal(car.oldDirection) and self.cellmap[potentialTrafficLightPosition[0], potentialTrafficLightPosition[1], ]. trafficLight.currentColor == RED and self.cellmap[nextCellPos.x, nextCellPos.y].car is None): cell.car = None car.flag = True car.velocity = 0 self.colormap[car.position.x, car.position.y] = self.roadcolor car.position = nextCellPos self.colormap[car.position.x, car.position.y] = self.slowcolor self.cellmap[car.position.x, car.position.y].car = car self.slow_cars += 1 cell.jammed += 1 if self.slow_cars > self.max_slow_cars: self.max_slow_cars = self.slow_cars break # początek reguł tutaj self.cellmap[car.position.x, car.position.y].visited += 1 cell = self.cellmap[car.position.x, car.position.y] if (all(dire.equal(Vec2D(0, 0)) for dire in cell.direction) or cell.direction is None): self.colormap[car.position.x, car.position.y] = self.sidecolor cell.car = None toRemove.append(car) break direction = car.oldDirection if len(cell.direction) == 1: direction = cell.direction[0] elif len(cell.direction) == 2: random = randrange(0, 100) p = (self.probabilityOfTurn if cell.probability is None else cell.probability) if random > p: direction = cell.direction[0] else: direction = cell.direction[1] newpos = car.position.add(direction) if (newpos.x < 0 or newpos.x >= self.cellmap.shape[0] - 1 or newpos.y < 0 or newpos.y >= self.cellmap.shape[1] - 1): cell.car = None toRemove.append(car) break try: wrong = [] c = [] if len(self.cellmap[newpos.x, newpos.y].direction) == 1: d = self.cellmap[newpos.x, newpos.y].direction[0] if d.equal(Vec2D(-1, -1)) or d.equal(Vec2D(1, 1)): c = [ Vec2D(newpos.x + 1, newpos.y - 1), Vec2D(newpos.x - 1, newpos.y + 1), ] for v in c: if (self.cellmap[v.x, v.y].kind != "road" or len(self.cellmap[v.x, v.y].direction) != 1 or not self.cellmap[ v.x, v.y].direction[0].equal(d)): wrong.append(v) elif d.equal(Vec2D(0, -1)) or d.equal(Vec2D(0, 1)): c = [ Vec2D(newpos.x + 1, newpos.y), Vec2D(newpos.x - 1, newpos.y), ] for v in c: if (self.cellmap[v.x, v.y].kind != "road" or len(self.cellmap[v.x, v.y].direction) != 1 or not self.cellmap[ v.x, v.y].direction[0].equal(d)): wrong.append(v) elif d.equal(Vec2D(1, -1)) or d.equal(Vec2D(-1, 1)): c = [ Vec2D(newpos.x - 1, newpos.y - 1), Vec2D(newpos.x + 1, newpos.y + 1), ] for v in c: if (self.cellmap[v.x, v.y].kind != "road" or len(self.cellmap[v.x, v.y].direction) != 1 or not self.cellmap[ v.x, v.y].direction[0].equal(d)): wrong.append(v) elif d.equal(Vec2D(1, 0)) or d.equal(Vec2D(-1, 0)): c = [ Vec2D(newpos.x, newpos.y - 1), Vec2D(newpos.x, newpos.y + 1), ] for v in c: if (self.cellmap[v.x, v.y].kind != "road" or len(self.cellmap[v.x, v.y].direction) != 1 or not self.cellmap[ v.x, v.y].direction[0].equal(d)): wrong.append(v) for w in wrong: c.remove(w) if len(c) > 0: r2 = randrange(0, 100) if r2 < 10: newpos = choice(c) except IndexError: pass # priority_check priorityflag = False if self.cellmap[car.position.x, car.position.y].priority is not True: if self.cellmap[newpos.x, newpos.y].priority is True: # for dir in self.cellmap[newpos.x, newpos.y].direction: # currX = deepcopy(newpos.x) - dir.x # currY = deepcopy(newpos.y) - dir.y # for _ in range(4): # if self.cellmap[currX, currY].priority is False: # break # elif self.cellmap[currX, currY].car is not None: # priorityflag = True # break # currX -= self.cellmap[currX, currY].direction[0].x # currY -= self.cellmap[currX, currY].direction[0].y priorityflag = recursive_priority_search( self.cellmap, newpos, 0) if priorityflag is True: self.colormap[car.position.x, car.position.y] = self.slowcolor self.slow_cars += 1 cell.jammed += 1 if self.slow_cars > self.max_slow_cars: self.max_slow_cars = self.slow_cars break if self.cellmap[newpos.x, newpos.y].car is not None: cl = direction.perpendicular_clockwise() ccl = direction.perpendicular_counterclockwise() potential1 = car.position.add(cl) potential1cell = self.cellmap[potential1.x, potential1.y] potential2 = car.position.add(ccl) potential2cell = self.cellmap[potential2.x, potential2.y] if potential1cell.kind == "road" \ and any(d == direction for d in potential1cell.direction) \ and potential1cell.car is None: newpos = potential1 elif potential2cell.kind == "road" \ and any(d == direction for d in potential2cell.direction) \ and potential2cell.car is None: newpos = potential2 else: car.velocity = self.cellmap[newpos.x, newpos.y].car.velocity self.colormap[car.position.x, car.position.y] = self.slowcolor self.slow_cars += 1 cell.jammed += 1 if self.slow_cars > self.max_slow_cars: self.max_slow_cars = self.slow_cars break else: car.velocity = car.defaultvelocity jumps += 1 # checking flags for fl in self.flow_flags: if any(car.position.equal(entry) for entry in fl.entries): fl.total_entered += 1 if any(car.position.equal(ex) for ex in fl.exits): fl.total_exit += 1 if self.cellmap[car.position.x, car.position.y].priority is False: self.colormap[car.position.x, car.position.y] = self.roadcolor else: self.colormap[car.position.x, car.position.y] = self.prioritycolor cell.car = None car.position = newpos self.colormap[car.position.x, car.position.y] = self.carcolor self.cellmap[car.position.x, car.position.y].car = car car.oldDirection = direction self.car_distances[car.idx] += jumps if self.currentIteration >= cars_number: file_handle_quiver = open(self.dt_string + "\\quiverdata.csv", "a") file_handle_quiver.write( str(car.idx * 4 + self.car_distances[car.idx]) + "," + str(self.currentIteration) + "," + str(car.oldDirection.x) + "," + str(car.oldDirection.y) + "\n") file_handle_quiver.close() if car.idx != -1: file_handle = open(self.dt_string + "\\car" + str(car.idx) + ".csv", "a") # append only write mode file_handle.write(str(jumps) + ", ") file_handle.close() for cartoremove in toRemove: self.cars.remove(cartoremove)
def create_roundabout_double(mp): # Down for cell in mp.cellmap[21:28, 10]: cell.kind = "road" cell.direction.append(Vec2D(1, 0)) for cell in mp.cellmap[18:20, 11]: cell.kind = "road" cell.direction.append(Vec2D(1, 0)) for cell in mp.cellmap[21:28, 11]: cell.kind = "road" cell.direction.append(Vec2D(1, 0)) for cell in mp.cellmap[29:31, 11]: cell.kind = "road" cell.direction.append(Vec2D(1, 0)) for cell in mp.cellmap[19:20, 12]: cell.kind = "road" cell.direction.append(Vec2D(1, 0)) for cell in mp.cellmap[29:30, 12]: cell.kind = "road" cell.direction.append(Vec2D(1, 0)) for cell in mp.cellmap[15:16, 13]: cell.kind = "road" cell.direction.append(Vec2D(1, 0)) for cell in mp.cellmap[17:18, 13]: cell.kind = "road" cell.direction.append(Vec2D(1, 0)) for cell in mp.cellmap[31:32, 13]: cell.kind = "road" cell.direction.append(Vec2D(1, 0)) for cell in mp.cellmap[33:34, 13]: cell.kind = "road" cell.direction.append(Vec2D(1, 0)) # Up for cell in mp.cellmap[22:29, 39]: cell.kind = "road" cell.direction.append(Vec2D(-1, 0)) for cell in mp.cellmap[19:21, 38]: cell.kind = "road" cell.direction.append(Vec2D(-1, 0)) for cell in mp.cellmap[22:29, 38]: cell.kind = "road" cell.direction.append(Vec2D(-1, 0)) for cell in mp.cellmap[30:32, 38]: cell.kind = "road" cell.direction.append(Vec2D(-1, 0)) for cell in mp.cellmap[20:21, 37]: cell.kind = "road" cell.direction.append(Vec2D(-1, 0)) for cell in mp.cellmap[30:31, 37]: cell.kind = "road" cell.direction.append(Vec2D(-1, 0)) for cell in mp.cellmap[16:17, 36]: cell.kind = "road" cell.direction.append(Vec2D(-1, 0)) for cell in mp.cellmap[18:19, 36]: cell.kind = "road" cell.direction.append(Vec2D(-1, 0)) for cell in mp.cellmap[32:33, 36]: cell.kind = "road" cell.direction.append(Vec2D(-1, 0)) for cell in mp.cellmap[34:35, 36]: cell.kind = "road" cell.direction.append(Vec2D(-1, 0)) # left for cell in mp.cellmap[10, 22:29]: cell.kind = "road" cell.direction.append(Vec2D(0, -1)) for cell in mp.cellmap[11, 19:21]: cell.kind = "road" cell.direction.append(Vec2D(0, -1)) for cell in mp.cellmap[11, 22:29]: cell.kind = "road" cell.direction.append(Vec2D(0, -1)) for cell in mp.cellmap[11, 30:32]: cell.kind = "road" cell.direction.append(Vec2D(0, -1)) for cell in mp.cellmap[12, 20:21]: cell.kind = "road" cell.direction.append(Vec2D(0, -1)) for cell in mp.cellmap[12, 30:31]: cell.kind = "road" cell.direction.append(Vec2D(0, -1)) for cell in mp.cellmap[13, 16:17]: cell.kind = "road" cell.direction.append(Vec2D(0, -1)) for cell in mp.cellmap[13, 18:19]: cell.kind = "road" cell.direction.append(Vec2D(0, -1)) for cell in mp.cellmap[13, 32:33]: cell.kind = "road" cell.direction.append(Vec2D(0, -1)) for cell in mp.cellmap[13, 34:35]: cell.kind = "road" cell.direction.append(Vec2D(0, -1)) # right for cell in mp.cellmap[39, 21:28]: cell.kind = "road" cell.direction.append(Vec2D(0, 1)) for cell in mp.cellmap[38, 18:20]: cell.kind = "road" cell.direction.append(Vec2D(0, 1)) for cell in mp.cellmap[38, 21:28]: cell.kind = "road" cell.direction.append(Vec2D(0, 1)) for cell in mp.cellmap[38, 29:31]: cell.kind = "road" cell.direction.append(Vec2D(0, 1)) for cell in mp.cellmap[37, 19:20]: cell.kind = "road" cell.direction.append(Vec2D(0, 1)) for cell in mp.cellmap[37, 29:30]: cell.kind = "road" cell.direction.append(Vec2D(0, 1)) for cell in mp.cellmap[36, 15:16]: cell.kind = "road" cell.direction.append(Vec2D(0, 1)) for cell in mp.cellmap[36, 17:18]: cell.kind = "road" cell.direction.append(Vec2D(0, 1)) for cell in mp.cellmap[36, 31:32]: cell.kind = "road" cell.direction.append(Vec2D(0, 1)) for cell in mp.cellmap[36, 33:34]: cell.kind = "road" cell.direction.append(Vec2D(0, 1)) # left down for cell in mp.cellmap[10, 21:22]: cell.kind = "road" cell.direction.append(Vec2D(1, -1)) for cell in mp.cellmap[11, 21:22]: cell.kind = "road" cell.direction.append(Vec2D(1, -1)) for cell in mp.cellmap[11, 18:19]: cell.kind = "road" cell.direction.append(Vec2D(1, -1)) for cell in mp.cellmap[12, 17:18]: cell.kind = "road" cell.direction.append(Vec2D(1, -1)) for cell in mp.cellmap[12, 19:20]: cell.kind = "road" cell.direction.append(Vec2D(1, -1)) for cell in mp.cellmap[13, 15:16]: cell.kind = "road" cell.direction.append(Vec2D(1, -1)) for cell in mp.cellmap[13, 17:18]: cell.kind = "road" cell.direction.append(Vec2D(1, -1)) for cell in mp.cellmap[14, 14:15]: cell.kind = "road" cell.direction.append(Vec2D(1, -1)) for cell in mp.cellmap[14, 16:17]: cell.kind = "road" cell.direction.append(Vec2D(1, -1)) for cell in mp.cellmap[15, 15:16]: cell.kind = "road" cell.direction.append(Vec2D(1, -1)) for cell in mp.cellmap[16, 13:15]: cell.kind = "road" cell.direction.append(Vec2D(1, -1)) for cell in mp.cellmap[17, 12:13]: cell.kind = "road" cell.direction.append(Vec2D(1, -1)) for cell in mp.cellmap[18, 13:14]: cell.kind = "road" cell.direction.append(Vec2D(1, -1)) for cell in mp.cellmap[20, 11:13]: cell.kind = "road" cell.direction.append(Vec2D(1, -1)) # right up for cell in mp.cellmap[39, 28:29]: cell.kind = "road" cell.direction.append(Vec2D(-1, 1)) for cell in mp.cellmap[38, 28:29]: cell.kind = "road" cell.direction.append(Vec2D(-1, 1)) for cell in mp.cellmap[38, 31:32]: cell.kind = "road" cell.direction.append(Vec2D(-1, 1)) for cell in mp.cellmap[37, 30:31]: cell.kind = "road" cell.direction.append(Vec2D(-1, 1)) for cell in mp.cellmap[37, 32:33]: cell.kind = "road" cell.direction.append(Vec2D(-1, 1)) for cell in mp.cellmap[36, 32:33]: cell.kind = "road" cell.direction.append(Vec2D(-1, 1)) for cell in mp.cellmap[36, 34:35]: cell.kind = "road" cell.direction.append(Vec2D(-1, 1)) for cell in mp.cellmap[35, 33:34]: cell.kind = "road" cell.direction.append(Vec2D(-1, 1)) for cell in mp.cellmap[35, 35:36]: cell.kind = "road" cell.direction.append(Vec2D(-1, 1)) for cell in mp.cellmap[34, 34:35]: cell.kind = "road" cell.direction.append(Vec2D(-1, 1)) for cell in mp.cellmap[33, 35:37]: cell.kind = "road" cell.direction.append(Vec2D(-1, 1)) for cell in mp.cellmap[32, 37:38]: cell.kind = "road" cell.direction.append(Vec2D(-1, 1)) for cell in mp.cellmap[31, 36:37]: cell.kind = "road" cell.direction.append(Vec2D(-1, 1)) for cell in mp.cellmap[29, 37:39]: cell.kind = "road" cell.direction.append(Vec2D(-1, 1)) # right down for cell in mp.cellmap[28:29, 10]: cell.kind = "road" cell.direction.append(Vec2D(1, 1)) for cell in mp.cellmap[28:29, 11]: cell.kind = "road" cell.direction.append(Vec2D(1, 1)) for cell in mp.cellmap[31:32, 11]: cell.kind = "road" cell.direction.append(Vec2D(1, 1)) for cell in mp.cellmap[30:31, 12]: cell.kind = "road" cell.direction.append(Vec2D(1, 1)) for cell in mp.cellmap[32:33, 12]: cell.kind = "road" cell.direction.append(Vec2D(1, 1)) for cell in mp.cellmap[32:33, 13]: cell.kind = "road" cell.direction.append(Vec2D(1, 1)) for cell in mp.cellmap[34:35, 13]: cell.kind = "road" cell.direction.append(Vec2D(1, 1)) for cell in mp.cellmap[33:34, 14]: cell.kind = "road" cell.direction.append(Vec2D(1, 1)) for cell in mp.cellmap[35:36, 14]: cell.kind = "road" cell.direction.append(Vec2D(1, 1)) for cell in mp.cellmap[34:35, 15]: cell.kind = "road" cell.direction.append(Vec2D(1, 1)) for cell in mp.cellmap[35:37, 16]: cell.kind = "road" cell.direction.append(Vec2D(1, 1)) for cell in mp.cellmap[37:38, 17]: cell.kind = "road" cell.direction.append(Vec2D(1, 1)) for cell in mp.cellmap[36:37, 18]: cell.kind = "road" cell.direction.append(Vec2D(1, 1)) for cell in mp.cellmap[37:39, 20]: cell.kind = "road" cell.direction.append(Vec2D(1, 1)) # left up for cell in mp.cellmap[21:22, 39]: cell.kind = "road" cell.direction.append(Vec2D(-1, -1)) for cell in mp.cellmap[21:22, 38]: cell.kind = "road" cell.direction.append(Vec2D(-1, -1)) for cell in mp.cellmap[18:19, 38]: cell.kind = "road" cell.direction.append(Vec2D(-1, -1)) for cell in mp.cellmap[17:18, 37]: cell.kind = "road" cell.direction.append(Vec2D(-1, -1)) for cell in mp.cellmap[19:20, 37]: cell.kind = "road" cell.direction.append(Vec2D(-1, -1)) for cell in mp.cellmap[15:16, 36]: cell.kind = "road" cell.direction.append(Vec2D(-1, -1)) for cell in mp.cellmap[17:18, 36]: cell.kind = "road" cell.direction.append(Vec2D(-1, -1)) for cell in mp.cellmap[14:15, 35]: cell.kind = "road" cell.direction.append(Vec2D(-1, -1)) for cell in mp.cellmap[16:17, 35]: cell.kind = "road" cell.direction.append(Vec2D(-1, -1)) for cell in mp.cellmap[15:16, 34]: cell.kind = "road" cell.direction.append(Vec2D(-1, -1)) for cell in mp.cellmap[13:15, 33]: cell.kind = "road" cell.direction.append(Vec2D(-1, -1)) for cell in mp.cellmap[12:13, 32]: cell.kind = "road" cell.direction.append(Vec2D(-1, -1)) for cell in mp.cellmap[13:14, 31]: cell.kind = "road" cell.direction.append(Vec2D(-1, -1)) for cell in mp.cellmap[11:13, 29]: cell.kind = "road" cell.direction.append(Vec2D(-1, -1))
def create_roundabout(mp): # Down for cell in mp.cellmap[18:31, 0]: cell.kind = "road" cell.direction.append(Vec2D(1, 0)) for cell in mp.cellmap[15:18, 1]: cell.kind = "road" cell.direction.append(Vec2D(1, 0)) for cell in mp.cellmap[31:34, 1]: cell.kind = "road" cell.direction.append(Vec2D(1, 0)) for cell in mp.cellmap[13:15, 2]: cell.kind = "road" cell.direction.append(Vec2D(1, 0)) for cell in mp.cellmap[34:36, 2]: cell.kind = "road" cell.direction.append(Vec2D(1, 0)) for cell in mp.cellmap[11:13, 3]: cell.kind = "road" cell.direction.append(Vec2D(1, 0)) for cell in mp.cellmap[36:38, 3]: cell.kind = "road" cell.direction.append(Vec2D(1, 0)) for cell in mp.cellmap[10:11, 4]: cell.kind = "road" cell.direction.append(Vec2D(1, 0)) for cell in mp.cellmap[38:39, 4]: cell.kind = "road" cell.direction.append(Vec2D(1, 0)) for cell in mp.cellmap[9:10, 5]: cell.kind = "road" cell.direction.append(Vec2D(1, 0)) for cell in mp.cellmap[39:40, 5]: cell.kind = "road" cell.direction.append(Vec2D(1, 0)) for cell in mp.cellmap[8:9, 6]: cell.kind = "road" cell.direction.append(Vec2D(1, 0)) for cell in mp.cellmap[40:41, 6]: cell.kind = "road" cell.direction.append(Vec2D(1, 0)) for cell in mp.cellmap[7:8, 7]: cell.kind = "road" cell.direction.append(Vec2D(1, 0)) for cell in mp.cellmap[41:42, 7]: cell.kind = "road" cell.direction.append(Vec2D(1, 0)) for cell in mp.cellmap[6:7, 8]: cell.kind = "road" cell.direction.append(Vec2D(1, 0)) for cell in mp.cellmap[42:43, 8]: cell.kind = "road" cell.direction.append(Vec2D(1, 0)) for cell in mp.cellmap[5:6, 9]: cell.kind = "road" cell.direction.append(Vec2D(1, 0)) for cell in mp.cellmap[43:44, 9]: cell.kind = "road" cell.direction.append(Vec2D(1, 0)) for cell in mp.cellmap[4:5, 10]: cell.kind = "road" cell.direction.append(Vec2D(1, 0)) for cell in mp.cellmap[44:45, 10]: cell.kind = "road" cell.direction.append(Vec2D(1, 0)) for cell in mp.cellmap[3:4, 11]: cell.kind = "road" cell.direction.append(Vec2D(1, 0)) for cell in mp.cellmap[45:46, 11]: cell.kind = "road" cell.direction.append(Vec2D(1, 0)) for cell in mp.cellmap[2:3, 13]: cell.kind = "road" cell.direction.append(Vec2D(1, 0)) for cell in mp.cellmap[46:47, 13]: cell.kind = "road" cell.direction.append(Vec2D(1, 0)) for cell in mp.cellmap[1:2, 15]: cell.kind = "road" cell.direction.append(Vec2D(1, 0)) for cell in mp.cellmap[47:48, 15]: cell.kind = "road" cell.direction.append(Vec2D(1, 0)) for cell in mp.cellmap[0:1, 18]: cell.kind = "road" cell.direction.append(Vec2D(1, 0)) for cell in mp.cellmap[48:49, 18]: cell.kind = "road" cell.direction.append(Vec2D(1, 0)) # Up for cell in mp.cellmap[19:32, 49]: cell.kind = "road" cell.direction.append(Vec2D(-1, 0)) for cell in mp.cellmap[16:19, 48]: cell.kind = "road" cell.direction.append(Vec2D(-1, 0)) for cell in mp.cellmap[32:35, 48]: cell.kind = "road" cell.direction.append(Vec2D(-1, 0)) for cell in mp.cellmap[14:16, 47]: cell.kind = "road" cell.direction.append(Vec2D(-1, 0)) for cell in mp.cellmap[35:37, 47]: cell.kind = "road" cell.direction.append(Vec2D(-1, 0)) for cell in mp.cellmap[12:14, 46]: cell.kind = "road" cell.direction.append(Vec2D(-1, 0)) for cell in mp.cellmap[37:39, 46]: cell.kind = "road" cell.direction.append(Vec2D(-1, 0)) for cell in mp.cellmap[11:12, 45]: cell.kind = "road" cell.direction.append(Vec2D(-1, 0)) for cell in mp.cellmap[39:40, 45]: cell.kind = "road" cell.direction.append(Vec2D(-1, 0)) for cell in mp.cellmap[10:11, 44]: cell.kind = "road" cell.direction.append(Vec2D(-1, 0)) for cell in mp.cellmap[40:41, 44]: cell.kind = "road" cell.direction.append(Vec2D(-1, 0)) for cell in mp.cellmap[9:10, 43]: cell.kind = "road" cell.direction.append(Vec2D(-1, 0)) for cell in mp.cellmap[41:42, 43]: cell.kind = "road" cell.direction.append(Vec2D(-1, 0)) for cell in mp.cellmap[8:9, 42]: cell.kind = "road" cell.direction.append(Vec2D(-1, 0)) for cell in mp.cellmap[42:43, 42]: cell.kind = "road" cell.direction.append(Vec2D(-1, 0)) for cell in mp.cellmap[7:8, 41]: cell.kind = "road" cell.direction.append(Vec2D(-1, 0)) for cell in mp.cellmap[43:44, 41]: cell.kind = "road" cell.direction.append(Vec2D(-1, 0)) for cell in mp.cellmap[6:7, 40]: cell.kind = "road" cell.direction.append(Vec2D(-1, 0)) for cell in mp.cellmap[44:45, 40]: cell.kind = "road" cell.direction.append(Vec2D(-1, 0)) for cell in mp.cellmap[5:6, 39]: cell.kind = "road" cell.direction.append(Vec2D(-1, 0)) for cell in mp.cellmap[45:46, 39]: cell.kind = "road" cell.direction.append(Vec2D(-1, 0)) for cell in mp.cellmap[4:5, 38]: cell.kind = "road" cell.direction.append(Vec2D(-1, 0)) for cell in mp.cellmap[46:47, 38]: cell.kind = "road" cell.direction.append(Vec2D(-1, 0)) for cell in mp.cellmap[3:4, 36]: cell.kind = "road" cell.direction.append(Vec2D(-1, 0)) for cell in mp.cellmap[47:48, 36]: cell.kind = "road" cell.direction.append(Vec2D(-1, 0)) for cell in mp.cellmap[2:3, 34]: cell.kind = "road" cell.direction.append(Vec2D(-1, 0)) for cell in mp.cellmap[48:49, 34]: cell.kind = "road" cell.direction.append(Vec2D(-1, 0)) for cell in mp.cellmap[1:2, 31]: cell.kind = "road" cell.direction.append(Vec2D(-1, 0)) for cell in mp.cellmap[49:50, 31]: cell.kind = "road" cell.direction.append(Vec2D(-1, 0)) # left for cell in mp.cellmap[0, 19:32]: cell.kind = "road" cell.direction.append(Vec2D(0, -1)) for cell in mp.cellmap[1, 16:19]: cell.kind = "road" cell.direction.append(Vec2D(0, -1)) for cell in mp.cellmap[1, 32:35]: cell.kind = "road" cell.direction.append(Vec2D(0, -1)) for cell in mp.cellmap[2, 14:16]: cell.kind = "road" cell.direction.append(Vec2D(0, -1)) for cell in mp.cellmap[2, 35:37]: cell.kind = "road" cell.direction.append(Vec2D(0, -1)) for cell in mp.cellmap[3, 12:14]: cell.kind = "road" cell.direction.append(Vec2D(0, -1)) for cell in mp.cellmap[3, 37:39]: cell.kind = "road" cell.direction.append(Vec2D(0, -1)) for cell in mp.cellmap[4, 11:12]: cell.kind = "road" cell.direction.append(Vec2D(0, -1)) for cell in mp.cellmap[4, 39:40]: cell.kind = "road" cell.direction.append(Vec2D(0, -1)) for cell in mp.cellmap[5, 10:11]: cell.kind = "road" cell.direction.append(Vec2D(0, -1)) for cell in mp.cellmap[5, 40:41]: cell.kind = "road" cell.direction.append(Vec2D(0, -1)) for cell in mp.cellmap[6, 9:10]: cell.kind = "road" cell.direction.append(Vec2D(0, -1)) for cell in mp.cellmap[6, 41:42]: cell.kind = "road" cell.direction.append(Vec2D(0, -1)) for cell in mp.cellmap[7, 8:9]: cell.kind = "road" cell.direction.append(Vec2D(0, -1)) for cell in mp.cellmap[7, 42:43]: cell.kind = "road" cell.direction.append(Vec2D(0, -1)) for cell in mp.cellmap[8, 7:8]: cell.kind = "road" cell.direction.append(Vec2D(0, -1)) for cell in mp.cellmap[8, 43:44]: cell.kind = "road" cell.direction.append(Vec2D(0, -1)) for cell in mp.cellmap[9, 6:7]: cell.kind = "road" cell.direction.append(Vec2D(0, -1)) for cell in mp.cellmap[9, 44:45]: cell.kind = "road" cell.direction.append(Vec2D(0, -1)) for cell in mp.cellmap[10, 5:6]: cell.kind = "road" cell.direction.append(Vec2D(0, -1)) for cell in mp.cellmap[10, 45:46]: cell.kind = "road" cell.direction.append(Vec2D(0, -1)) for cell in mp.cellmap[11, 4:5]: cell.kind = "road" cell.direction.append(Vec2D(0, -1)) for cell in mp.cellmap[11, 46:47]: cell.kind = "road" cell.direction.append(Vec2D(0, -1)) for cell in mp.cellmap[13, 3:4]: cell.kind = "road" cell.direction.append(Vec2D(0, -1)) for cell in mp.cellmap[13, 47:48]: cell.kind = "road" cell.direction.append(Vec2D(0, -1)) for cell in mp.cellmap[15, 2:3]: cell.kind = "road" cell.direction.append(Vec2D(0, -1)) for cell in mp.cellmap[15, 48:49]: cell.kind = "road" cell.direction.append(Vec2D(0, -1)) for cell in mp.cellmap[18, 1:2]: cell.kind = "road" cell.direction.append(Vec2D(0, -1)) for cell in mp.cellmap[18, 49:50]: cell.kind = "road" cell.direction.append(Vec2D(0, -1)) # right for cell in mp.cellmap[49, 18:31]: cell.kind = "road" cell.direction.append(Vec2D(0, 1)) for cell in mp.cellmap[48, 15:18]: cell.kind = "road" cell.direction.append(Vec2D(0, 1)) for cell in mp.cellmap[48, 31:34]: cell.kind = "road" cell.direction.append(Vec2D(0, 1)) for cell in mp.cellmap[47, 13:15]: cell.kind = "road" cell.direction.append(Vec2D(0, 1)) for cell in mp.cellmap[47, 34:36]: cell.kind = "road" cell.direction.append(Vec2D(0, 1)) for cell in mp.cellmap[46, 11:13]: cell.kind = "road" cell.direction.append(Vec2D(0, 1)) for cell in mp.cellmap[46, 36:38]: cell.kind = "road" cell.direction.append(Vec2D(0, 1)) for cell in mp.cellmap[45, 10:11]: cell.kind = "road" cell.direction.append(Vec2D(0, 1)) for cell in mp.cellmap[45, 38:39]: cell.kind = "road" cell.direction.append(Vec2D(0, 1)) for cell in mp.cellmap[44, 9:10]: cell.kind = "road" cell.direction.append(Vec2D(0, 1)) for cell in mp.cellmap[44, 39:40]: cell.kind = "road" cell.direction.append(Vec2D(0, 1)) for cell in mp.cellmap[43, 8:9]: cell.kind = "road" cell.direction.append(Vec2D(0, 1)) for cell in mp.cellmap[43, 40:41]: cell.kind = "road" cell.direction.append(Vec2D(0, 1)) for cell in mp.cellmap[42, 7:8]: cell.kind = "road" cell.direction.append(Vec2D(0, 1)) for cell in mp.cellmap[42, 41:42]: cell.kind = "road" cell.direction.append(Vec2D(0, 1)) for cell in mp.cellmap[41, 6:7]: cell.kind = "road" cell.direction.append(Vec2D(0, 1)) for cell in mp.cellmap[41, 42:43]: cell.kind = "road" cell.direction.append(Vec2D(0, 1)) for cell in mp.cellmap[40, 5:6]: cell.kind = "road" cell.direction.append(Vec2D(0, 1)) for cell in mp.cellmap[40, 43:44]: cell.kind = "road" cell.direction.append(Vec2D(0, 1)) for cell in mp.cellmap[39, 4:5]: cell.kind = "road" cell.direction.append(Vec2D(0, 1)) for cell in mp.cellmap[39, 44:45]: cell.kind = "road" cell.direction.append(Vec2D(0, 1)) for cell in mp.cellmap[38, 3:4]: cell.kind = "road" cell.direction.append(Vec2D(0, 1)) for cell in mp.cellmap[38, 45:46]: cell.kind = "road" cell.direction.append(Vec2D(0, 1)) for cell in mp.cellmap[36, 2:3]: cell.kind = "road" cell.direction.append(Vec2D(0, 1)) for cell in mp.cellmap[36, 46:47]: cell.kind = "road" cell.direction.append(Vec2D(0, 1)) for cell in mp.cellmap[34, 1:2]: cell.kind = "road" cell.direction.append(Vec2D(0, 1)) for cell in mp.cellmap[34, 47:48]: cell.kind = "road" cell.direction.append(Vec2D(0, 1)) for cell in mp.cellmap[31, 0:1]: cell.kind = "road" cell.direction.append(Vec2D(0, 1)) for cell in mp.cellmap[31, 48:49]: cell.kind = "road" cell.direction.append(Vec2D(0, 1))