Browse Source

Fixed shuffling

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

44
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,17 +94,18 @@ def tick(t):
global toad global toad
global btime global btime
# print grid # print grid
for row in grid: if DEBUG:
for guy in row: for row in grid:
if guy.occupant is not None: for guy in row:
print(chr(0x4e00 + guy.occupant), end="") if guy.occupant is not None:
elif guy.typ == SquareType.SEAT: print(chr(0x4e00 + guy.occupant), end="")
print("", end="") elif guy.typ == SquareType.SEAT:
else: print("", end="")
print("", end="") else:
print() print("", end="")
print("---") print()
print(grid[3][0].occupant, grid[3][1].occupant, passengers[nunty(grid[3][1].occupant)].dest) print("---")
print(grid[3][0].occupant, grid[3][1].occupant, passengers[nunty(grid[3][1].occupant)].dest)
if toad < len(passengers) and grid[3][0].occupant is None and t % btime == 0: if toad < len(passengers) and grid[3][0].occupant is None and t % btime == 0:
grid[3][0].occupant = toad #added grid[3][0].occupant = toad #added
passengers[toad].curr = (3, 0) passengers[toad].curr = (3, 0)
@ -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,8 +132,9 @@ 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:
os.system("clear") time.sleep(0.01)
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))
exit() exit()

Loading…
Cancel
Save