diff --git a/main.py b/main.py index 6c2d58b..785dabf 100644 --- a/main.py +++ b/main.py @@ -13,10 +13,12 @@ class GridSquare: self.typ = typ self.occupant = occupant def __str__(self): - return "(%s|%s)" % (str(typ), str(occupant)) + return "(%s|%s)" % (str(self.typ), str(self.occupant)) + def __repr__(self): + return str(self) -def makeGrid(): - return [[GridSquare(SquareType.AISLE, 0) for x in range(0,width)] for y in range(0,height)] +def makeGrid(height, width): + return [[GridSquare(SquareType.AISLE, None) for x in range(0,width)] for y in range(0,height)] class Passenger: #dest and curr are both 2-tuples @@ -30,11 +32,19 @@ def manhattanDistance(pos1, pos2): return abs(pos1[0] - pos2[0]) + abs(pos1[1] - pos2[1]) def mooreNeighbourhood(pos): - + return [(pos[0], pos[1]+1), (pos[0]+1, pos[1]), (pos[0]-1, pos[1]), (pos[0], pos[1]-1)] def nextSquare(passenger, grid): #simple behaviour for now - for i in + candidati = [] + for i in mooreNeighbourhood(passenger.curr): + if manhattanDistance(passenger.dest, i) < manhattanDistance(passenger.dest, passenger.curr): + candidati.append(i) + for i in candidati: + if grid[i[0]][i[1]].typ == SquareType.AISLE: #this should work well enough for one aisle plane + return i + #todo: implement shufflin' + return candidati[0] def GenPassList(): return [] @@ -42,7 +52,30 @@ def GenPassList(): grid=makeGrid() passengers = GenPassList() +for index, i in enumerate(passengers): + grid[i.curr[0]][i.curr[1]] = index def tick(): # print grid - print(grid) \ No newline at end of file + print(grid) + for row in grid: + for guy in row: + if guy.occupant is not None: + print("X", end="") + elif guy.typ == SquareType.SEAT: + print("_", end="") + else: + print(" ", end="") + print() + for (i, man) in enumerate(passengers): + #im sexist + cp = man.curr + man.curr = nextSquare(man, grid) + grid[cp[0]][cp[1]] = None #they move out of there + grid[man.curr[0]][man.curr[1]] = i + +def run(): + while 1: + tick() + +run()