-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathTestAStar.c
More file actions
67 lines (59 loc) · 1.94 KB
/
TestAStar.c
File metadata and controls
67 lines (59 loc) · 1.94 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
#include "AStar.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
int main (int argc, char **argv)
{
if (argc != 2) {
fprintf (stderr, "testAStar <scenfile>\n");
fprintf (stderr, "(where <scenfile> is of the format used in http://www.aiide.org/benchmarks/)\n");
exit (1);
}
FILE *scenFile = fopen (argv[1], "r");
if (!scenFile) {
perror ("couldn't open given scenario file: ");
exit (1);
}
fscanf (scenFile, "version 1.0\n");
char mapFileBuf[255];
int bucket, height, width, startX, startY, goalX, goalY, optimal;
double something;
fscanf (scenFile, "%i %s %i %i %i %i %i %i %i %lf\n",
&bucket, mapFileBuf, &width, &height, &startX, &startY,
&goalX, &goalY, &optimal, &something);
FILE *mapFile = fopen (mapFileBuf, "r");
if (!mapFile) {
fprintf (stderr, "couldn't open map file %s: %s\n",
mapFileBuf, strerror(errno));
exit (1);
}
fscanf (mapFile, "type octile\nheight %i\nwidth %i\nmap\n", &height, &width);
char grid[width*height];
memset (grid, 0, sizeof (char) * width * height);
for (int i = 0; i < height; i++) {
char buf[width + 1]; // space for a newline
fread (buf, 1, width + 1, mapFile);
for (int j = 0; j < width; j++) {
if (buf[j] == '.' || buf[j] == 'G')
grid[width*i+j] = 1;
else
grid[width*i+j] = 0;
}
}
int doContinue = 1;
do {
int solLen = 0;
int begin = astar_getIndexByWidth (width, startX, startY);
int end = astar_getIndexByWidth (width, goalX, goalY);
free (astar_compute (grid, &solLen, width, height, begin, end));
if (solLen > optimal) {
fprintf (stderr, "validity error! In map %s, from (%i,%i) to (%i, %i), expected length %i, was length %i\n", mapFileBuf, startX, startY, goalX, goalY, optimal, solLen);
exit (1);
}
doContinue = fscanf(scenFile,"%i %s %i %i %i %i %i %i %i %lf\n",
&bucket, mapFileBuf, &width, &height,
&startX, &startY, &goalX,
&goalY, &optimal, &something);
} while (doContinue > 0);
}