-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShopClasses.py
71 lines (62 loc) · 1.54 KB
/
ShopClasses.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import random
class Model:
def __init__(self, CashBoxCount, maxQueueLen):
self.currentTime = 0
self.customers = []
self.shop = Shop(cashBoxCount, maxQueueLen)
self.rnd = random.seed()
self.newCustomerTimer = rnd(2,6)
def tick(self):
currentTime += 1
shop.tick()
if newCustomer-1 <= 0:
customers.append(Customer(rnd, shop))
newCustomerTimer = rnd(2, 6)
class Shop:
def __init__(self, cashBoxCount, maxQueueLen, rnd):
self.cashBoxes = []
self.customers = []
for i in range(cashBoxCount):
cashBoxes.append(CashBox(rnd))
self.maxQueueLen = maxQueueLen
def tick():
for i in reversed(customers.size):
customers[i].tick()
for cb in cashBoxes:
cb.tick()
class CashBox:
def __init__(self, rnd):
self.rnd = rnd
self.serviceTime = 0
self.queue = []
def tick():
if serviceTime == 0 && queue.size > 0:
serviceTime = rnd(5, 16)
elif serviceTimer > 0:
serviceTimer -= 1
if serviceTimer == 0:
Customer c = queue.dequeue()
c.ServiceDone()
class Customer:
def __init__(self, rnd, shop):
self.rnd = rnd
self.shop = shop
shop.newCustomer(self)
self.cash = rnd(100,3000)
self.state = State.shopping
self.stateTimer = rnd(5, 16)
tick():
if state == State.queued:
return
if stateTimer-1 <=0:
if state = State.shopping:
state = state.searching
stateTimer = rhd(5, 11)
elif state = State.searching:
CashBox cb = shop.findCashBox()
if cb == None:
state = State.fail
sop.customerLeave(self)
else:
state = State.queued
cb.Enqueue(self)