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