Browse Source

Fixed shuffling

master
iamsosmart19 3 years ago
parent
commit
d674130ded
  1. 20
      main.py

20
main.py

@ -4,6 +4,8 @@ import random as rnd
from enum import Enum from enum import Enum
import time import time
DEBUG=True
class SquareType(Enum): class SquareType(Enum):
AISLE = 0 AISLE = 0
SEAT = 1 SEAT = 1
@ -64,7 +66,8 @@ 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 += reversed([Passenger((a, x),(-1,-1)) for a in range(4,7)]) # border += reversed([Passenger((a, x),(-1,-1)) for a in range(4,7)])
border += [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,9 +77,9 @@ grid=makeGrid()
#boarding order #boarding order
passengers = GenPassList(grid) passengers = GenPassList(grid)
rnd.seed(505) # rnd.seed(605)
# passengers.reverse() # passengers.reverse()
rnd.shuffle(passengers) # rnd.shuffle(passengers)
toad = 0 toad = 0
btime = 3 #passengers board every btime ticks btime = 3 #passengers board every btime ticks
@ -91,6 +94,7 @@ def tick(t):
global toad global toad
global btime global btime
# print grid # print grid
if DEBUG:
for row in grid: for row in grid:
for guy in row: for guy in row:
if guy.occupant is not None: if guy.occupant is not None:
@ -111,13 +115,14 @@ def tick(t):
continue continue
if man.curr == (-1, -1): if man.curr == (-1, -1):
continue continue
if i == 36: if i == 36 and DEBUG:
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): nextS=nextSquare(man,grid)
if passengers[i].shuffled == 0 and not ( grid[nextS[0]][nextS[1]].typ == SquareType.AISLE and grid[nextS[0]][nextS[1]].occupant is not None):
cp = man.curr cp = man.curr
man.curr = nextSquare(man, grid) man.curr = nextS
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:
@ -127,7 +132,8 @@ def tick(t):
for man in passengers: for man in passengers:
if man.shuffled != 0: if man.shuffled != 0:
man.shuffled-=1 man.shuffled-=1
time.sleep(0.05) if DEBUG:
time.sleep(0.01)
os.system("clear") os.system("clear")
if done and toad >= len(passengers): if done and toad >= len(passengers):
print("Number of ticks: " + str(t)) print("Number of ticks: " + str(t))

Loading…
Cancel
Save