-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAPI.c
More file actions
117 lines (94 loc) · 2.3 KB
/
API.c
File metadata and controls
117 lines (94 loc) · 2.3 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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define BUFFER_SIZE 32
int getInteger(char* command) {
printf("%s\n", command);
fflush(stdout);
char response[BUFFER_SIZE];
fgets(response, BUFFER_SIZE, stdin);
int value = atoi(response);
return value;
}
int getBoolean(char* command) {
printf("%s\n", command);
fflush(stdout);
char response[BUFFER_SIZE];
fgets(response, BUFFER_SIZE, stdin);
int value = (strcmp(response, "true\n") == 0);
return value;
}
int getAck(char* command) {
printf("%s\n", command);
fflush(stdout);
char response[BUFFER_SIZE];
fgets(response, BUFFER_SIZE, stdin);
int success = (strcmp(response, "ack\n") == 0);
return success;
}
int API_mazeWidth() {
return getInteger("mazeWidth");
}
int API_mazeHeight() {
return getInteger("mazeHeight");
}
int API_wallFront() {
return getBoolean("wallFront");
}
int API_wallRight() {
return getBoolean("wallRight");
}
int API_wallLeft() {
return getBoolean("wallLeft");
}
int API_moveForward() {
return getAck("moveForward");
}
void API_turnRight() {
getAck("turnRight");
}
void API_turnLeft() {
getAck("turnLeft");
}
void API_setWall(int x, int y, char direction) {
printf("setWall %d %d %c\n", x, y, direction);
fflush(stdout);
}
void API_clearWall(int x, int y, char direction) {
printf("clearWall %d %d %c\n", x, y, direction);
fflush(stdout);
}
void API_setColor(int x, int y, char color) {
printf("setColor %d %d %c\n", x, y, color);
fflush(stdout);
}
void API_clearColor(int x, int y) {
printf("clearColor %d %d\n", x, y);
fflush(stdout);
}
void API_clearAllColor() {
printf("clearAllColor\n");
fflush(stdout);
}
void API_setText(int x, int y, char* text) {
printf("setText %d %d %s\n", x, y, text);
fflush(stdout);
}
void API_clearText(int x, int y) {
printf("clearText %d %d\n", x, y);
fflush(stdout);
}
void API_clearAllText() {
printf("clearAllText\n");
fflush(stdout);
}
int API_wasReset() {
return getBoolean("wasReset");
}
void API_ackReset() {
getAck("ackReset");
}
void debug_log(char* text) {
fprintf(stderr, "%s\n", text);
fflush(stderr);
}