Compare commits

...

4 Commits

  1. 19
      main.py

19
main.py

@ -36,16 +36,16 @@ def manhattanDistance(pos1, pos2):
def mooreNeighbourhood(pos):
return [i for i in [(pos[0], pos[1]+1), (pos[0]+1, pos[1]), (pos[0]-1, pos[1]), (pos[0], pos[1]-1)] if
i[0] >= 0 and i[1] >= 0 and i[0] < width and i[1] < height]
i[0] >= 0 and i[1] >= 0 and i[0] < height and i[1] < width]
def nextSquare(passenger, grid):
#simple behaviour for now
candidati = []
for i in mooreNeighbourhood(passenger.curr):
if manhattanDistance(passenger.dest, i) < manhattanDistance(passenger.dest, passenger.curr):
if grid[passenger.curr[0]][passenger.curr[1]].typ == SquareType.SEAT:
candidati.append(passenger.curr[0], passenger.curr[1] + 1)
candidati.append(passenger.curr[0], passenger.curr[1] - 1)
# if grid[passenger.curr[0]][passenger.curr[1]].typ == SquareType.SEAT and i[1] != passenger.curr[1] and False:
if grid[passenger.curr[0]][passenger.curr[1]].typ == SquareType.SEAT and i[1] != passenger.curr[1]:
pass
else:
candidati.append(i)
for i in candidati:
@ -62,7 +62,7 @@ def GenPassList(grid):
border += [Passenger((a, x),(-1,-1)) for a in range(0,3)]
for a in range(0,3):
grid[a][x].typ = SquareType.SEAT
border += [Passenger((a, x),(-1,-1)) for a in range(4,7)]
border += reversed([Passenger((a, x),(-1,-1)) for a in range(4,7)])
for a in range(4,7):
grid[a][x].typ = SquareType.SEAT
return border
@ -74,7 +74,9 @@ passengers = GenPassList(grid)
toad = 0
def tick():
done=True
global toad
# print grid
for row in grid:
@ -88,19 +90,22 @@ def tick():
print()
print("---")
if toad < len(passengers):
grid[4][0].occupant = toad #added
passengers[toad].curr = (4, 0)
grid[3][0].occupant = toad #added
passengers[toad].curr = (3, 0)
toad += 1
for (i, man) in enumerate(passengers):
if man.curr == man.dest:
continue
if man.curr == (-1, -1):
continue
done=False
#im sexist
cp = man.curr
man.curr = nextSquare(man, grid)
grid[cp[0]][cp[1]].occupant = None #they move out of there
grid[man.curr[0]][man.curr[1]].occupant = i
if done:
exit()
def run():
while 1:

Loading…
Cancel
Save