-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsquare.c
More file actions
191 lines (137 loc) · 4.17 KB
/
square.c
File metadata and controls
191 lines (137 loc) · 4.17 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#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 "square.h"
#include "toll.h"
Car* carWillBeSend;
Minibus* minibusWillBeSend;
Truck* truckWillBeSend;
// void Square_load_ferry(Square* self, Toll* toll){
// }
void Square_load(Square* self, Toll* toll){
if (!self || !toll) {
return;
}
int vehicle_type_choice = rand() % 3;
if (vehicle_type_choice == 0) {
Car* new_car = Toll_car_return(toll);
if (new_car != NULL) {
int placed = 0;
for (int i = 0; i < carsLength; ++i) {
if (self->cars[i] == NULL) {
self->cars[i] = new_car;
placed = 1;
break;
}
}
if (!placed) {
}
}
} else if (vehicle_type_choice == 1) {
Minibus* new_minibus = Toll_minibus_return(toll);
if (new_minibus != NULL) {
int placed = 0;
for (int i = 0; i < minibusesLength; ++i) {
if (self->minibuses[i] == NULL) {
self->minibuses[i] = new_minibus;
placed = 1;
break;
}
}
if (!placed) {
}
}
} else {
Truck* new_truck = Toll_truck_return(toll);
if (new_truck != NULL) {
int placed = 0;
for (int i = 0; i < trucksLength; ++i) {
if (self->trucks[i] == NULL) {
self->trucks[i] = new_truck;
placed = 1;
break;
}
}
if (!placed) {
}
}
}
}
Car* Square_car_Left(Square* self){ //tolldaki hatalı kodlama olurdu çünkü her left loaddan sonra değil
//ferry gerekli mi burda
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){ return NULL; }
}
int vehicle_type_choice = rand() % carsLength;//hataaaaaaaaaaaaaaaaaaaaaaaa
while(self->cars[vehicle_type_choice]==NULL&& !isAllEmpty) {
vehicle_type_choice = rand() % carsLength;
}
carWillBeSend=self->cars[vehicle_type_choice];
self->cars[vehicle_type_choice]=NULL;
return carWillBeSend;
}
Minibus* Square_minibus_Left(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){
return NULL;
}
}
int vehicle_type_choice = rand() % minibusesLength;
while(self->minibuses[vehicle_type_choice]==NULL&& !isAllEmpty) {
vehicle_type_choice = rand() % minibusesLength;
}
minibusWillBeSend=self->minibuses[vehicle_type_choice];
self->minibuses[vehicle_type_choice]=NULL;
return minibusWillBeSend;
}
Truck* Square_truck_Left(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){
return NULL;
}
}
int vehicle_type_choice = rand() % trucksLength;
while(self->trucks[vehicle_type_choice]==NULL&& !isAllEmpty) {
vehicle_type_choice = rand() % trucksLength;
}
truckWillBeSend=self->trucks[vehicle_type_choice];
self->trucks[vehicle_type_choice]=NULL;
return truckWillBeSend;
}