-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.c
92 lines (81 loc) · 2.76 KB
/
client.c
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
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<time.h>
#include"server.h"
#define MAX 5
int main()
{
int simulation_time, plane_no=1;
double probability_takeoff, probability_landing;
int rand_landings, rand_takeoffs;
Init_simulation(&simulation_time, &probability_takeoff, &probability_landing);
plane_queue *land_front = NULL;
plane_queue *land_rear = NULL;
plane_queue *takeoff_front = NULL;
plane_queue *takeoff_rear = NULL;
for(int T=1; T<=simulation_time; T++)
{
rand_takeoffs = randoms(probability_takeoff);
for(int planes = 0; planes < rand_takeoffs ; planes++)
{
printf("plane %d is ready to takeoff\n", plane_no);
if((count(&takeoff_front)) <= MAX)
new_plane(&takeoff_front, &takeoff_rear, plane_no);
else
{
printf("plane %d is told to wait", plane_no);
new_plane(&takeoff_front, &takeoff_rear, plane_no);
}
plane_no ++;
}
rand_landings = randoms(probability_landing);
for(int planes = 0; planes < rand_landings; planes++)
{
printf("plane %d is ready to land\n", plane_no);
new_plane(&land_front, &land_rear, plane_no);
plane_no++;
}
if((count(&land_front)> MAX))
{
printf("\n%d\n", T);
printf("plane %d landed using runway 1\n",del_plane(&land_front, &land_rear));
printf("plane %d landed using runway 2\n",del_plane(&land_front, &land_rear));
}
else if((count(&land_front)<= MAX && count(&land_front) > 0) && (count(&takeoff_front) > 0))
{
printf("\n%d\n", T);
printf("plane %d took off using runway 2\n",del_plane(&takeoff_front, &takeoff_rear));
printf("plane %d landed using runway 1\n",del_plane(&land_front, &land_rear));
}
else if(count(&land_front) > 1 && count(&takeoff_front)==0)
{
printf("\n%d\n", T);
printf("plane %d landed using runway 1\n",del_plane(&land_front, &land_rear));
printf("plane %d landed using runway 2\n",del_plane(&land_front, &land_rear));
}
else if(count(&takeoff_front) > 1 && count(&land_front)==0)
{
printf("\n%d\n", T);
printf("plane %d took off using runway 1\n",del_plane(&takeoff_front, &takeoff_rear));
printf("plane %d took off using runway 2\n",del_plane(&takeoff_front, &takeoff_rear));
}
else if(count(&takeoff_front) ==1 && count(&land_front)==0)
{
printf("\n%d\n", T);
printf("plane %d took off using runway 2\n",del_plane(&takeoff_front, &takeoff_rear));
}
else if(count(&land_front) ==1 && count(&takeoff_front)==0)
{
printf("\n%d\n", T);
printf("plane %d landed using runway 1\n",del_plane(&land_front, &land_rear));
}
else
{
printf("\n%d\n", T);
printf("Runways are idle\n");
}
}
return 0;
}