-
Notifications
You must be signed in to change notification settings - Fork 0
/
map.c
87 lines (63 loc) · 1.3 KB
/
map.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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "headers/constants.h"
#include "headers/appartU.h"
#include "headers/map.h"
#include "headers/robot.h"
/*
* Read the map from the header and store it in memory
*
* @return Map strcuture
*/
Map read_map() {
Map map;
memcpy(map.map, appart, MAP_WIDTH * MAP_HEIGHT);
map.width = MAP_WIDTH;
map.height = MAP_HEIGHT;
return map;
}
/*
* Show the map with the robot
*
*/
void show_map(Map map, Robot bot) {
int i = 0, j = 0;
printf("\n");
for (i = 0; i < map.height; i++) {
for (j = 0; j < map.width; j++) {
if (bot.posY == i && bot.posX == j) {
printf("%c", bot.name);
}
else if (map.map[i][j] == 'x' || map.map[i][j] == 'S') {
printf("%c", map.map[i][j]);
}
else if (bot.m[i][j] == 1) {
printf("*");
}
else {
printf(" ");
}
}
printf("\n");
}
printf("\n");
}
/*
* Find the exit coordinates of the map
*
* @return Exit structure
*/
Exit find_map_exit(Map map) {
int i = 0, j = 0;
Exit exit;
for (i = 0; i < map.height; i++) {
for (j = 0; j < map.width; j++) {
if (map.map[i][j] == 'S') {
exit.y = i;
exit.x = j;
}
}
}
return exit;
}