Browse Source

Fixed shuffling

master
iamsosmart19 3 years ago
parent
commit
67fffac0f7
  1. 37
      main.py

37
main.py

@ -25,6 +25,7 @@ def makeGrid():
return [[GridSquare(SquareType.AISLE, None) for x in range(0,width)] for y in range(0,height)]
class Passenger:
shuffled = 0
#dest and curr are both 2-tuples
def __init__(self, dest, curr):
self.dest = dest
@ -56,8 +57,8 @@ def nextSquare(passenger, grid):
return candidati[0]
def GenPassList(grid):
border = [Passenger((a, 0),(-1,-1)) for a in range(0,3)]
for a in range(0,3):
border = [Passenger((a, 0),(-1,-1)) for a in range(4,7)]
for a in range(4,7):
grid[a][0].typ = SquareType.SEAT
for x in range(1,width):
border += [Passenger((a, x),(-1,-1)) for a in range(0,3)]
@ -73,11 +74,11 @@ grid=makeGrid()
#boarding order
passengers = GenPassList(grid)
import random
random.seed(505)
random.shuffle(passengers)
rnd.seed(505)
# passengers.reverse()
rnd.shuffle(passengers)
toad = 0
btime = 10 #passengers board every btime ticks
btime = 3 #passengers board every btime ticks
import os
@ -114,16 +115,22 @@ def tick(t):
print(nextSquare(man, grid))
done=False
#im sexist
cp = man.curr
man.curr = nextSquare(man, grid)
other = grid[cp[0]][cp[1]]
other.occupant = grid[man.curr[0]][man.curr[1]].occupant #they move out of there
if other.occupant is not None:
passengers[other.occupant].curr = cp
grid[man.curr[0]][man.curr[1]].occupant = i
time.sleep(0.1)
if passengers[i].shuffled == 0 and not ( grid[nextSquare(man,grid)[0]][nextSquare(man,grid)[1]].typ == SquareType.AISLE and grid[nextSquare(man,grid)[0]][nextSquare(man,grid)[1]].occupant is not None):
cp = man.curr
man.curr = nextSquare(man, grid)
other = grid[cp[0]][cp[1]]
other.occupant = grid[man.curr[0]][man.curr[1]].occupant #they move out of there
if other.occupant is not None:
passengers[other.occupant].curr = cp
passengers[other.occupant].shuffled = 5
grid[man.curr[0]][man.curr[1]].occupant = i
for man in passengers:
if man.shuffled != 0:
man.shuffled-=1
time.sleep(0.05)
os.system("clear")
if done:
if done and toad >= len(passengers):
print("Number of ticks: " + str(t))
exit()
def run():

Loading…
Cancel
Save