-
Notifications
You must be signed in to change notification settings - Fork 6
/
gameEngine.py
executable file
·76 lines (66 loc) · 2.83 KB
/
gameEngine.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
71
72
73
74
75
76
import sys, pygame, simulation.road, simulation.speedLimits, random, importlib, config
from representation import Representation
from simulationManager import SimulationManager
from simulation.trafficGenerators import *
class caEnv_v0():
def __init__(self,config):
self.config = config
self.data = config.data
print(self.data)
#def reset(self):
#def step(self,action):
def displayInitialize(self, isBatch):
if isBatch:
print("Initializing batch simulation....")
print("Starting simulation...\n")
else:
pygame.init()
pygame.display.set_caption('Traffic Analysis Software')
def render_interactive(self):
random.seed(config.seed)
screen = pygame.display.set_mode(config.size)
clock = pygame.time.Clock()
speedLimits = simulation.speedLimits.SpeedLimits(config.speedLimits, config.maxSpeed)
road = simulation.road.Road(config.lanes, config.length, speedLimits)
simulation_ = SimulationManager(road, config.trafficGenerator, config.updateFrame)
representation = Representation(screen, road, simulation_, config.data, config.speedLimits)
while simulation_.running:
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
simulation_.processKey(event.key)
clock.tick_busy_loop(config.maxFps)#.tick_busy_loop = updates the clock
dt = clock.get_time()# — time used in the previous tick
simulation_.update(dt) #updates logistics
representation.draw(dt * simulation_.timeFactor) #updates graphics
pygame.display.flip()
def render_batch(self):
random.seed(config.seed)
clock = pygame.time.Clock()
speedLimits = simulation.speedLimits.SpeedLimits(config.speedLimits, config.maxSpeed)
road = simulation.road.Road(config.lanes, config.length, speedLimits)
simulation_ = SimulationManager(road, config.trafficGenerator, config.updateFrame)
while simulation_.running:
clock.tick_busy_loop(config.maxFps)#
dt = clock.get_time()# — time used in the previous tick
simulation_.update(dt) #updates logistics
def runInteractive(self):
self.displayInitialize(False) #interactive
self.render_interactive()
def runBatch(self):
self.displayInitialize(True) #batch
self.render_batch()
# def getStateSpace(self):
# def getActionSpace(self):
# def getStateSpaceSize(self, state_space):
# def getActionSpaceSize(self, action_space):
# main
configFile = sys.argv[2]
config = importlib.import_module('config.'+configFile)
mode = sys.argv[1]
env = caEnv_v0(config)
if mode=="batch":
env.runBatch()
elif mode=="gui":
env.runInteractive()
else:
env.runBatch()