/home/toolbox/public_html/solutions/5/532/b.c
1 #include <stdio.h>
2 #include <string.h>
3 #include <sys/types.h>
4 #include <sys/stat.h>
5 #include <fcntl.h>
6 #include <stdint.h>
7 #include <math.h>
8 #include <stdlib.h>
9
10 #define TRUE (1 == 1)
11 #define FALSE (1 != 1)
12
13 #define DEBUG if (FALSE)
14
15 /*
16 * Author: Isaac Traxler
17 * Date: 2018-03-11
18 * Purpose: fun
19 * Problem: 532 - Dungeon Master
20 */
21
22 /*
23 * This template reads data until a terminating value is reached.
24 */
25
26
27 #define MAX_DIM 32
28 #define MXX = (MAX_DIM * MAX_DIM * MAX_DIM)
29 #define illegal -99
30 #define block -1
31 #define vacant 0
32
33
34 int dungeon[MAX_DIM][MAX_DIM][MAX_DIM];
35 int rw;
36 int cl;
37 int pl;
38 int start[3]; /* 0 is p, 1 is r, 2 is c */
39 int goal[3]; /* 0 is p, 1 is r, 2 is c */
40 int stk[MXX][3];
41 int stackTop;
42
43 void init()
44 {
45 /* FUNCTION init */
46 int p;
47 int r;
48 int c;
49
50 for (p=0; MAX_DIM>p; p++)
51 for (r=0; MAX_DIM>r; r++)
52 for (c=0; MAX_DIM>c; c++)
53 dungeon[p][r][c] = illegal;
54 stackTop = 0;
55 } /* FUNCTION init */
56
57 void dump()
58 {
59 /* FUNCTION dump */
60 int p;
61 int r;
62 int c;
63
64 printf("%d %d %d\n", pl, rw, cl);
65 for (p=0; (pl+2)>p; p++)
66 {
67 /* for p */
68 for (r=0; (rw+2)>r; r++)
69 {
70 /* for r */
71 for (c=0; (cl+2)>c; c++)
72 {
73 /* for c */
74 printf("%4d", dungeon[p][r][c]);
75 } /* for c */
76 printf("\n");
77 } /* for r */
78 printf("\n");
79 } /* for p */
80 } /* FUNCTION dump */
81
82 int getInput()
83 {
84 /* FUNCTION getInput */
85 int dataReadFlag;
86 int p;
87 int r;
88 int c;
89 int l;
90 char line[MAX_DIM];
91
92 init();
93 scanf(" %d %d %d ", &pl, &rw, &cl);
94 dataReadFlag = ((0 != rw) || (0 != cl) || (0 != pl));
95 if (dataReadFlag)
96 {
97 /* read the dungeon */
98 for (p=1; pl>=p; p++)
99 {
100 /* for each plane */
101 for (r=1; rw>=r; r++)
102 {
103 /* for each row */
104 scanf(" %s ", line);
105 for (c=1,l=0; cl>=c; c++,l++)
106 {
107 /* process a cell */
108 switch (line[l])
109 {
110 /* switch */
111 case '#':
112 dungeon[p][r][c] = block;
113 break;
114 case '.':
115 dungeon[p][r][c] = vacant;
116 break;
117 case 'S':
118 dungeon[p][r][c] = vacant;
119 start[0] = p;
120 start[1] = r;
121 start[2] = c;
122 break;
123 case 'E':
124 dungeon[p][r][c] = vacant;
125 goal[0] = p;
126 goal[1] = r;
127 goal[2] = c;
128 break;
129 } /* switch */
130 } /* process a cell */
131 } /* for each row */
132 } /* for each plane */
133 } /* read the dungeon */
134 return (dataReadFlag);
135 } /* FUNCTION getInput */
136
137 void push(int a; int b; int c)
138 {
139 /* FUNCTION push */
140 sk[stackTop][0] = a;
141 sk[stackTop][1] = b;
142 sk[stackTop][2] = c;
143 stackTop++;
144 } /* FUNCTION push */
145
146 void pop()
147 {
148 /* FUNCTION pop */
149 stackTop--;
150 } /* FUNCTION pop */
151
152 void move()
153 {
154 /* FUNCTON move */
155 } /* FUNCTON move */
156
157 void checkForMoves()
158 {
159 /* FUNCTON checkForMoves */
160 } /* FUNCTON checkForMoves */
161
162 void process()
163 {
164 /* FUNCTION process */
165 int loc[3];
166 int steps = -1;
167
168 loc[0] = start[0];
169 loc[1] = start[1];
170 loc[2] = start[2];
171 push(start[0], start[1], start[2]);
172 while (0 < stackTop)
173 {
174 /* while moves still possible */
175 move();
176 checkForMoves();
177 } /* while moves still possible */
178
179 dump();
180 } /* FUNCTION process */
181
182 int main()
183 {
184 /* main */
185 int moreToDo;
186
187 moreToDo = getInput();
188 while (moreToDo)
189 {
190 /* while */
191 process();
192 moreToDo = getInput();
193 } /* while */
194
195 return EXIT_SUCCESS;
196 } /* main */
197