-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsupport.c
150 lines (108 loc) · 3.32 KB
/
support.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
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
extern int map[13][13], waypoints[4][3], route[100][4], routeLength;
void printMaze () { /* This function prints the contents of the Maze */
int i,j;
printf("Printing the maze:\n");
for (i = 0; i < 13; i++) {
for (j = 0; j < 13; j++)
printf("%d\t", map[i][j]);
printf("\n");
}
}
void printWaypoints() { /* This function prints out the waypoints array */
int i, j;
printf("Printing the Input Array:\n");
for (i = 0; i < 4; i++) {
for (j = 0; j < 3; j++)
printf("%d ", waypoints[i][j]);
printf("\n");
}
}
void printRoute () { /* This function prints out the route array */
int i, j;
printf("Printing the Route Array:\n");
for (i = 0; i <= routeLength; i++) {
for (j = 0; j < 4; j++)
printf("%d ", route[i][j]);
printf("\n");
}
}
/* These next two functions determine the coordinates of a station */
int xPos (int punt) {
if (punt == 10 || punt == 11 || punt == 12)
return 0;
if (punt == 1 || punt == 9)
return 4;
if (punt == 2 || punt == 8)
return 6;
if (punt == 3 || punt == 7)
return 8;
if (punt == 4 || punt == 5 || punt == 6)
return 12;
return 99;
}
int yPos (int punt) {
if (punt == 1 || punt == 2 || punt == 3)
return 12;
if (punt == 4 || punt == 12)
return 8;
if (punt == 5 || punt == 11)
return 6;
if (punt == 6 || punt == 10)
return 4;
if (punt == 7 || punt == 8 || punt == 9)
return 0;
return 99;
}
/* This function determines the direction the robot will face when it just arrived at a station */
int richtingStation (int punt) {
if (punt == 1 || punt == 2 || punt == 3)
return 1;
if (punt == 4 || punt == 5 || punt == 6)
return 3;
if (punt == 7 || punt == 8 || punt == 9)
return 2;
if (punt == 10 || punt == 11 || punt == 12)
return 4;
return 99;
}
/* This function copy's the punt array to the route array and returns a new value for K */
int k_copyPoint(int punt[], int k) {
int i;
for (i = 0; i < 3; i++)
route[routeLength][i] = punt[i];
routeLength++;
return k - 2;
}
/* This function swaps two waypoints without using (visible) pointers */
void swapWaypoints (int swap1, int swap2) {
int i, tempInput;
for (i = 0; i < 3; i++) {
tempInput = waypoints[swap1][i];
waypoints[swap1][i] = waypoints[swap2][i];
waypoints[swap2][i] = tempInput;
}
}
/* This functions sets a waypoint to all 99's, and removing it */
void removeWaypoint (int waypointStep) {
int i;
for (i = 0; i < 3; i++)
waypoints[waypointStep][i] = 99;
}
/* This function sets the current position and direction in the waypoint array */
void setCurrentWaypoint (int curPos[]) {
int i;
for (i = 0; i < 3; i++)
waypoints[0][i] = curPos[i];
}
/* This funcion marks a position as a mine */
void markMine(int minePos[]) {
map[minePos[0]][minePos[1]] = -1;
}
/* This function inverts the direction of a waypoint (usefull when the robot hit a mine) */
void flipNextWaypointDir (int curPos[]) {
if (curPos[2] % 2) {
waypoints[0][2] = curPos[2] + 1;
} else {
waypoints[0][2] = curPos[2] - 1;
}
}