-
Notifications
You must be signed in to change notification settings - Fork 0
/
maze_test.c
93 lines (71 loc) · 1.67 KB
/
maze_test.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
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "maze.h"
int pathLength, pathShort, combIndex;
/* Main function */
int main(int argc, char *argv[]) {
/* Read a provided file */
FILE * filePtr; //pointer to a file
if(argc == 1) {
filePtr = fopen("mazeLib/maze1.txt", "r");
}
else if(argc == 3) {
/* read input */
if(strcmp(argv[1], "-f") == 0) {
filePtr = fopen(argv[2], "r");
}
else {
printf("ERROR, wrong arguments\n");
printf("%s", argv[2]);
usage();
return -1;
}
}
else {
printf("ERROR, wrong amount of arguments\n");
usage();
return -1;
}
if(filePtr == NULL) {
printf("ERROR, missing a maze file\n");
usage();
return -1;
}
/* maze manipulations */
// Create a maze from file
maze * mazePtr = createMazeFromFile(filePtr);
// Check the creation
if(mazePtr == NULL) {
printf("maze is null\n");
return 0;
}
// Print emty maze to the terminal
printMaze(mazePtr);
// Get longest path and print it
findPathLong(mazePtr);
printMaze(mazePtr);
// Get shortest path and print it
findPathShort(mazePtr);
printMaze(mazePtr);
// Delete maze and close the file
deleteMaze(mazePtr);
fclose(filePtr);
/* Random maze */
printf("\n===================\n");
mazePtr = newMaze(100,200);
assignRandomData(mazePtr);
// Print emty maze to the terminal
printMaze(mazePtr);
// Get longest path and print it
findPathLong(mazePtr);
printMaze(mazePtr);
// Get shortest path and print it
findPathShort(mazePtr);
printMaze(mazePtr);
deleteMaze(mazePtr);
//return
return 0;
}