-
Notifications
You must be signed in to change notification settings - Fork 0
/
vehicles.h
57 lines (46 loc) · 1.27 KB
/
vehicles.h
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
#ifndef _VEHICLE_H
#define _VEHICLE_H
#include <stdio.h>
#include <gsl/gsl_rng.h>
#include <gsl/gsl_randist.h>
#include <vector>
#include <algorithm> //random_shuffle, distance, max_element
#include <ctime>
#include "parameters.h"
using namespace std;
/* Program parameters are defined here */
#define RIGHT 1
#define LEFT -1
extern gsl_rng * generator;
extern time_t seed;
typedef vector<vector<int> > road_arr;
class vehicle {
public:
int vel, pos, lane, width, length, marker, size, prev_lane = lane, _distance;
bool changed_lane = false, exit_road = false;
double chance_right;
private:
vector<int> headway(road_arr& road);
int aveheadway(vector<int>& headwaycount);
bool check_lane(road_arr& road, int direction);
public:
void place(road_arr& road);
void remove(road_arr& road);
void accelerate(void);
void decelerate(road_arr& road);
void random_slow(void);
void move(road_arr& road);
void change_lane(road_arr& road);
vector<int> stats(void);
};
class car : public vehicle{
public:
car() { marker = 2, width = 2, length = 2, size = length*width; }
};
class motorcycle : public vehicle{
public:
motorcycle() { marker = 1, width = 1, length = 1, size = length*width; }
};
bool place_check(int pos, int lane, int length, int width,
road_arr& road, int ROADLENGTH);
#endif