Compare commits

...

4 Commits

  1. 19
      main.py

19
main.py

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

Loading…
Cancel
Save