Browse Source

Better?

master
iamsosmart19 3 years ago
parent
commit
26700f2a8d
  1. 30
      main.py

30
main.py

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

Loading…
Cancel
Save