-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbus.py
33 lines (27 loc) · 915 Bytes
/
bus.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
import math
import random
from car import Car
class Bus(Car):
max_people = 100
length = 8
def __init__(self, line, speed, people_carried):
self.line = line
self.closest_stop = None
self.waiting_to_turn = False
self.just_stopped = False
Car.__init__(self, 0, 0, 1, speed, people_carried)
def pick_up_people(self, people):
self.people_carried += people
def people_leave(self):
number = int(math.floor(random.random() * random.random() / 7 * self.people_carried))
self.people_carried -= number
return number
def distance_to_target_position(self):
distances = []
for stop in self.line.bus_stops:
distance = stop.position - self.position
if distance > 0:
distances.append(distance)
if distances:
return min(distances)
return 10000000