visualiser package¶
Provides the visualiser modules
-
class
visualiser.
SimulatorVisualiser
(windowID)[source]¶ Bases:
object
The visualiser of the simulator, showing a graphical representation of the highway.
Parameters: windowID – str
set as the SDL_WINDOWID environment variable. Used to embed the pygame window into the GUI.-
_cachedSprites
= None¶ (
boolean
) Whether all sprites have been cached
-
draw
()[source]¶ Updates the canvas Attempts to achieve target FPS by blocking As such, it should run in its own thread so other things can be done in the background Should run in and endless loop to continuously redraw
-
fps
¶ The current target frames per second
Getter: Get the current FPS Setter: Set the current FPS. Calculates the necessary target draw interval Type: int
-
mode
¶ The mode of the visualiser. See
mode
for details.Getter: Return the current set mode Setter: Set the current mode. Also sets the correct dimensions of the display, doubling the width if in compare mode Type: int
-
stateVector
(agent=False)[source]¶ Return a dictionary of features: {last action, current lane, distance of obstales in three lanes, offroad} Some features have been ‘pruned’ from our descision tree because they did not affect the accuracy of the tree. These have been commented out for clarity.
-
Submodules¶
visualiser.util module¶
Utility functions and classes
-
class
visualiser.util.
Actions
[source]¶ Bases:
enum.Enum
Enumerations of the actions that the simulator can receive
-
LEFT
= 2¶ Move into the lane to the left
-
NONE
= 1¶ No action
-
PAUSE
= 4¶ Toggle the pause state of the simulator
-
RIGHT
= 3¶ Move into the lane to the right
-
-
class
visualiser.util.
Pos
(vehicle, x=0, y=0)[source]¶ Bases:
visualiser.util.Vector
2D vector that automatically updates its vehicle’s rect position
-
class
visualiser.util.
Vector
(x=0, y=0)[source]¶ Bases:
object
A 2D vector, with arithmetic magic methods implemented
-
x
= None¶ The x component of the vector
-
y
= None¶ The y component of the vector
-
-
visualiser.util.
loadSprite
(path, scale=1)[source]¶ Load an image as a
pygame.Surface
. Automatically caches loaded images in the backgroundParameters:
visualiser.vehicles module¶
Vehicle classes used by the game
-
class
visualiser.vehicles.
Car
(game)[source]¶ Bases:
visualiser.vehicles.Vehicle
The controlled car
Parameters: game – The parent SimulatorVisualiser
-
class
visualiser.vehicles.
Obstacle
(game)[source]¶ Bases:
visualiser.vehicles.Vehicle
An obstacle vehicle that the main car has to avoid
Parameters: game – The parent SimulatorVisualiser
-
hasCollidedAgent
¶ Getter: Returns whether the vehicle has started colliding with agent car this tick. Updates _agentCollided
-
speed
¶ The virtual forward speed of the vehicle, in metres per second
Getter: Get the vehicle speed Setter: Set the vehicle speed in m/s. Also sets the real velocity, which is relative to the user car
-
-
visualiser.vehicles.
SPRITE_SCALES
= {'car.png': 0.4, 'lorry.png': 0.75, 'police.png': 0.42, 'taxi.png': 0.35, 'truck.png': 0.5, 'van.png': 0.55, 'viper.png': 0.37}¶ dict
mapping obstacle sprites onto their respectivefloat
scales
-
class
visualiser.vehicles.
Vehicle
(game)[source]¶ Bases:
object
A vehicle in the game
Parameters: game – The parent SimulatorVisualiser
-
lane
¶ The current lane of the vehicle
Getter: Get the current lane Setter: Set the lane of the vehicle. The vehicle is centered in its lane. Will only accept lanes available Type: int
-
speed
¶ The virtual forward speed of the vehicle, in metres per second
Getter: Get the vehicle speed Setter: Set the vehicle speed in m/s
-
sprite
¶ The sprite object. Uses
_sprite
as the file name of the image to loadGetter: Return the sprite Type: pygame.Surface
-
visualiser.visualiser module¶
The visualiser of the simulator - the game the user plays Uses the PyGame library
-
class
visualiser.visualiser.
SimulatorVisualiser
(windowID)[source]¶ Bases:
object
The visualiser of the simulator, showing a graphical representation of the highway.
Parameters: windowID – str
set as the SDL_WINDOWID environment variable. Used to embed the pygame window into the GUI.-
_cachedSprites
= None¶ (
boolean
) Whether all sprites have been cached
-
draw
()[source]¶ Updates the canvas Attempts to achieve target FPS by blocking As such, it should run in its own thread so other things can be done in the background Should run in and endless loop to continuously redraw
-
fps
¶ The current target frames per second
Getter: Get the current FPS Setter: Set the current FPS. Calculates the necessary target draw interval Type: int
-
mode
¶ The mode of the visualiser. See
mode
for details.Getter: Return the current set mode Setter: Set the current mode. Also sets the correct dimensions of the display, doubling the width if in compare mode Type: int
-
stateVector
(agent=False)[source]¶ Return a dictionary of features: {last action, current lane, distance of obstales in three lanes, offroad} Some features have been ‘pruned’ from our descision tree because they did not affect the accuracy of the tree. These have been commented out for clarity.
-