Browse Source

Fixed shuffling

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

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

Loading…
Cancel
Save