diff --git a/main.py b/main.py index 75f038b..635f743 100644 --- a/main.py +++ b/main.py @@ -8,8 +8,8 @@ import time import math from queue import PriorityQueue as pq -# DEBUG=True -DEBUG=False +DEBUG=True +# DEBUG=False class SquareType(Enum): AISLE = 0 @@ -62,6 +62,7 @@ def mooreNeighbourhood(pos): i[0] >= 0 and i[1] >= 0 and i[0] < height and i[1] < width] def nextSquare(passenger, grid): + passenger.recalc = False passenger.path=[] dist=[[0 for x in range(0,width)] for y in range(0,height)] prev=[[None for x in range(0,width)] for y in range(0,height)] @@ -95,10 +96,14 @@ def nextSquare(passenger, grid): u=prev[u[1][0]][u[1][1]] return for x in mooreNeighbourhood(u[1]): + # if not( grid[x[0]][x[1]].typ == SquareType.SEAT and u[1][1] != x[1]) and grid[x[0]][x[1]].typ != SquareType.WALL and (grid[x[0]][x[1]].occupant == None or grid[x[0]][x[1]].typ == SquareType.SEAT): if not( grid[x[0]][x[1]].typ == SquareType.SEAT and u[1][1] != x[1]) and grid[x[0]][x[1]].typ != SquareType.WALL: alt = 0 if grid[x[0]][x[1]].typ == SquareType.SEAT or grid[u[1][0]][u[1][1]].typ == SquareType.SEAT: - alt = dist[u[1][0]][u[1][1]] + 5 + if grid[x[0]][x[1]].occupant != None: + alt = dist[u[1][0]][u[1][1]] + 5 + 10 + else: + alt = dist[u[1][0]][u[1][1]] + 5 else: alt = dist[u[1][0]][u[1][1]] + 1 # if alt == 0: @@ -204,31 +209,20 @@ def tick(t, toad): if man.inter is not None and man.curr == man.inter: man.shuffled = 3 man.inter = None - man.recalc = True + # man.recalc = True if man.curr == (-1, -1): continue # if i == 36 and DEBUG: # print(nextSquare(man, grid)) done=False #im sexist - if man.recalc: - # if DEBUG: - # print("Recalculating: " + str(man.curr)) - nextSquare(man, grid) - man.recalc = False - if len(man.path) == 0: + if len(man.path) == 0 or man.recalc: # if DEBUG: # print("Recalculating: " + str(man.curr)) nextSquare(man, grid) nextS = man.path.pop() - if manhattanDistance(nextS, man.curr) > 1: - # if DEBUG: - # print("Recalculating: " + str(man.curr)) - nextSquare(man, grid) - nextS = man.path.pop() - if DEBUG: print(str(man.curr) + ", " + str(man.interback) + ", " + str(man.dest) + ", " + str(nextS) + ", " + str(man.inter)) @@ -240,6 +234,8 @@ def tick(t, toad): if other.occupant is not None: passengers[other.occupant].curr = cp passengers[other.occupant].shuffled = 5 + passengers[other.occupant].recalc = True + man.recalc = True grid[man.curr[0]][man.curr[1]].occupant = i for man in passengers: if man.shuffled != 0: @@ -250,7 +246,7 @@ def tick(t, toad): # time.sleep(0.1) # time.sleep(0.05) # time.sleep(0.02) - # time.sleep(0.01) + time.sleep(0.01) # time.sleep(0.001) os.system("clear") if done and toad >= len(passengers): @@ -271,7 +267,7 @@ def main(): global passengers #boarding order - for seediter in range(0,200): + for seediter in range(43,2000): passengers = GenPassList() print("Seed: " + str(seediter)) rnd.seed(seediter)