def move_all(self): moved = list() for m in self.members: if type(m) == Passenger: moved.append(m) if m.path is not None: x = m.xpos y = m.ypos step = m.next_move(self) #this updates pos within m ! # Has exited the grid, remove: if step == (-1, -1): self.pop(x, y) #TODO:Should I really be returning here? #return moved else: # Replace old tile with a floor tile self.__put(Point('.', x, y), x, y) # Put the passenger in the next move self.__put(m, step[0], step[1]) return moved
def build_vertical_wall(self, top_left_position, length): walls = list() for i in range(0, length): wall = Point('#', top_left_position[0], top_left_position[1]+i, passable=False) walls.append(wall) self.load_elements(walls) return walls
def __initMap(self, w, h): a = list() for i in range(0, h): b = list() for j in range(0, w): b.append(Point('.', x=j, y=i)) a.append(b) return a
def pop(self, xpos, ypos): ''' Returns element at that location and replaces it with floor Point ''' element = self.get(xpos, ypos) if type(element) == Passenger: self.members.remove(element) self.__map[ypos][xpos] = Point('.', xpos, ypos) return element
def getMapFromFile(file_name): f = open(file_name, 'r') whole_file = f.readlines() for pos in range(0, len(whole_file)): whole_file[pos] = whole_file[pos].rstrip() grid = Gridmap(width=len(whole_file[0]), height=len(whole_file)) row_num = 0 column_num = 0 for row in whole_file: #start of new row, reset column column_num = 0 for e in row: if e == FLOOR: #floor single_floor_tile_list = [Point(name=FLOOR, x=column_num, y=row_num),] grid.load_elements(single_floor_tile_list) elif e == WALLS: single_wall_tile_list = [Point(name=WALLS, x=column_num, y=row_num, passable=False),] grid.load_elements(single_wall_tile_list) elif e == EXITS: single_exit_tile_list = [Point(name=EXITS, x=column_num, y=row_num),] grid.load_elements(single_exit_tile_list) elif e == SHOPS: single_shop_tile_list = [ShopFloor(x=column_num, y=row_num),] grid.load_elements(single_shop_tile_list) column_num += 1 row_num += 1 f.close() return grid
from Grid.Grid import Gridmap from Grid.GridElements import Passenger, Point import time from kafka import KafkaProducer import json producer = KafkaProducer(bootstrap_servers=['localhost:9092']) producer = KafkaProducer( value_serializer=lambda m: json.dumps(m).encode('ascii')) producer.send('test', {'Just': 'Connected'}) airport = Gridmap(50, 50) target = Point('x', 0, 39) airport.build_horizontal_wall((0, 4), 50) door1 = [ Point('.', 10, 4), Point('#', 9, 5, 1, False), Point('#', 11, 5, 1, False) ] door2 = [ Point('.', 35, 4), Point('#', 34, 5, 1, False), Point('#', 36, 5, 1, False) ] # # Shop 1 airport.build_vertical_wall((15, 15), 15)