Skip to content
This repository was archived by the owner on Dec 10, 2019. It is now read-only.

Commit e5f2e43

Browse files
author
David Bailey
committed
anything?
1 parent 0135077 commit e5f2e43

File tree

1 file changed

+23
-18
lines changed

1 file changed

+23
-18
lines changed

trafficSim.py

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from math import sqrt
22

3+
People = []
34
class Person:
45
def __init__(self,route):
56
self.arrived = False
@@ -34,6 +35,11 @@ def __init__(self,driver):
3435
self.driver = driver
3536
self.speed = 0.0
3637
self.acceleration = 0.0
38+
self.deacceleraton = 0.0
39+
def Accelerate():
40+
self.speed += self.acceleration
41+
def Deaccelerate():
42+
self.speed += self.deacceleraton
3743

3844
class Bicycle(Vehicle):
3945
def __init__(self,driver):
@@ -58,13 +64,15 @@ class Train:
5864
class Ferry:
5965
pass
6066

61-
class Place:
67+
class Point:
6268
def __init__(self, x, y):
6369
self.x = x
6470
self.y = y
6571

72+
Signals = []
6673
class Signal: # red = stop, yellow = stop if able, green = go
6774
def __init__(self,color,greenTime,redTime,yellowTime):
75+
Signals.append(self)
6876
self.color = color
6977
self.greenTime = greenTime
7078
self.redTime = redTime
@@ -101,24 +109,20 @@ def __init__(self,nRoadSegment,sRoadSegment,eRoadSegment,wRoadSegment):
101109

102110
class TwoWayStopSign: # this direction stop, then yeild, then go
103111
def __init__(self):
112+
pass
104113

105-
106-
class YeildSign: # yeild, then go
114+
class YeildSign: # yeild, thens go
107115
def __init__(self):
108116
pass
109117

110118
class = Crosswalk: #
111119
def __init__(self):
112-
pedestrian = False
113-
114-
Signals = []
120+
pedestrianPresent = False
115121

116122
class FourWaySignal:
117123
def __init__(self,majorTime,minorTime,yellowTime):
118124
self.major = Signal('green',majorTime,minorTime+yellowTime,yellowTime)
119-
Signals.append(self.major)
120125
self.minor = Signal('red',minorTime,majorTime+yellowTime,yellowTime)
121-
Signals.append(self.minor)
122126

123127
class FourWaySignalIntersection:
124128
def __init__(self)
@@ -134,18 +138,20 @@ def __init__(self, origin, destination, signal, type):
134138
self.signal = signal
135139
self.type = type
136140

141+
class HalfTwoLaneRoad:
142+
def __init__(self,end1,end2):
143+
self.sidewalk1 = RoadSegment(end1,end2,'person')
144+
self.sidewalk2 = RoadSegment(end2,end1,'person')
145+
self.lane = RoadSegment(end1,end2,'vehicle')
146+
137147
class TwoLaneRoad:
138148
def __init__(self,end1,end2):
139-
self.sidewalk1a = RoadSegment(end1,end2,'person')
140-
self.sidewalk1b = RoadSegment(end2,end1,'person')
141-
self.roada = RoadSegment(end1,end2,'vehicle')
142-
self.roadb = RoadSegment(end2,end1,'vehicle')
143-
self.sidewalk2a = RoadSegment(end1,end2,'person')
144-
self.sidewalk2b = RoadSegment(end2,end1,'person')
149+
self.half1 = HalfTwoLaneRoad(end1,end2)
150+
self.half2 = HalfTwoLaneRoad(end2,end1)
145151

146-
p1 = Place(0,0)
147-
p2 = Place(10,10)
148-
p3 = Place(20,20)
152+
p1 = Point(0,0)
153+
p2 = Point(10,10)
154+
p3 = Point(20,20)
149155

150156
rs1 = RoadSegment(p1,p2,s1)
151157
rs2 = RoadSegment(p2,p3,s2)
@@ -155,7 +161,6 @@ def __init__(self,end1,end2):
155161

156162
P1 = Person([rs2,rs1])
157163
P2 = Person([rs4,rs3])
158-
People = [P1,P2]
159164

160165
while P1.arrived == False:
161166
for S in Signals:

0 commit comments

Comments
 (0)