-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmovePedestrians.c
More file actions
42 lines (40 loc) · 1.6 KB
/
Copy pathmovePedestrians.c
File metadata and controls
42 lines (40 loc) · 1.6 KB
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
#include "movePedestrians.h"
void movePedestrians(int** lightControl) {
// pedestrianCrossing counts number of people waiting
// pedestrianWaiting counts time spent waiting
// intersectExtra counts number of people crossing
// loop through pedestrianCrossing (8 elements)
for (int i=0; i<8; i++) {
if (intersectExtra[i%2==0 ? (i+1) % 4 : (i-1) % 4 + 2]) {
// unrealistic, needs improvement, but for simplicty, assume
// crossing in 1 second
intersectExtra[i%2==0 ? (i+1) % 4 : (i-1) % 4 + 2] = 0;
intersectExtra[i%2==0 ? (i+1) % 4 : (i-1) % 4 + 5] = 0;
}
if (!pedestrianCrossing[i]) {
continue;
}
// check traffic on the two lanes
// see if active (use i%2==0 ? (i+1) % 4 : (i-1) % 4)
if (intersectExtra[i%2==0 ? (i+1) % 4 : (i-1) % 4] || intersectExtra[i%2==0 ? (i+1) % 4 : (i-1) % 4 + 3]) {
// car in the lane
continue;;
}
// if not checkTrafficPedestrian
if (!checkTrafficPedestrian(i)) {
// move the pedestrian
// set crossing to num of people
intersectExtra[i%2==0 ? (i+1) % 4 : (i-1) % 4 + 2] = pedestrianCrossing[i];
intersectExtra[i%2==0 ? (i+1) % 4 : (i-1) % 4 + 5] = pedestrianCrossing[i];
// set pedestrian waiting to 0
pedestrianWaiting[i] = 0;
// set pedestrian crossing to 0
pedestrianCrossing[i] = 0;
}
// else
else {
// increment pedestrian waiting
pedestrianWaiting[i]++;
}
}
}