-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbehind_square.c
More file actions
109 lines (89 loc) · 2.53 KB
/
Copy pathbehind_square.c
File metadata and controls
109 lines (89 loc) · 2.53 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
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <time.h>
#include <stdlib.h>
#include "truck.h"
#include "car.h"
#include "minibus.h"
#include "behind_square.h"
Car* carWillBeSent;
Minibus* minibusWillBeSent;
Truck* truckWillBeSent;
int carsLength = 40;
int minibusesLength = 20;
int trucksLength = 12;
Car* Behind_Square_Car_Left(Behind_Square* self){
bool isAllEmpty=true;
if (!self ) {
return NULL;
}
for(int i=0;i<carsLength;i++){
if(self->cars[i]!=NULL){
isAllEmpty=false;
break;
}
else{
}
if(i== carsLength-1 && isAllEmpty){
return NULL;
}
}
int vehicle_type_choice = rand() % carsLength;
while(self->cars[vehicle_type_choice]==NULL&& !isAllEmpty) {
vehicle_type_choice = rand() % carsLength;
}
carWillBeSent=self->cars[vehicle_type_choice];
self->cars[vehicle_type_choice]=NULL;
return carWillBeSent;
}
Minibus* Behind_Square_Minibus_Left(Behind_Square* self){
bool isAllEmpty=true;
if (!self ) {
return NULL;
}
for(int i=0;i<minibusesLength;i++){
if(self->minibuses[i]!=NULL){
isAllEmpty=false;
break;
}
else{
}
if(i== minibusesLength-1 && isAllEmpty){
return NULL;
}
}
int vehicle_type_choice = rand() % minibusesLength;
while(self->minibuses[vehicle_type_choice]==NULL&& !isAllEmpty) {
vehicle_type_choice = rand() % minibusesLength;
}
minibusWillBeSent=self->minibuses[vehicle_type_choice];
self->minibuses[vehicle_type_choice]=NULL;
return minibusWillBeSent;
}
Truck* Behind_Square_Truck_Left(Behind_Square* self){
bool isAllEmpty=true;
if (!self ) {
return NULL;
}
for(int i=0;i<trucksLength;i++){
if(self->trucks[i]!=NULL){
isAllEmpty=false;
break;
}
else{
}
if(i== trucksLength-1 && isAllEmpty){
return NULL;
}
}
int vehicle_type_choice = rand() % trucksLength;
while(self->trucks[vehicle_type_choice]==NULL&& !isAllEmpty) {
vehicle_type_choice = rand() % trucksLength;
}
truckWillBeSent=self->trucks[vehicle_type_choice];
self->trucks[vehicle_type_choice]=NULL;
return truckWillBeSent;
}