/home/toolbox/public_html/solutions/4/439/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 #include <ctype.h>
10
11 #define TRUE (1 == 1)
12 #define FALSE (1 != 1)
13
14 #define DEBUG if (FALSE)
15
16 #define MAX_LINE 257
17
18 /*
19 * Author: Isaac Traxler
20 * Date:
21 * Purpose: fun
22 * Problem:
23 */
24
25 /*
26 * This template reads lines of data at a time until end of file.
27 */
28
29 #define UNKNOWN -1
30
31 char line[MAX_LINE];
32 char xx[3];
33 char yy[3];
34 int x1;
35 int x2;
36 int y1;
37 int y2;
38 int board[9][9];
39 int dx[8] = {-1, 1, -2, 2, -2, 2, -1, 1};
40 int dy[8] = { 2, 2, 1, 1, -1, -1, -2, -2};
41
42 void init()
43 {
44 /* FUNCTION init */
45 int i;
46 int j;
47
48 for (i=1; 9>i; i++)
49 {
50 /* for i */
51 for (j=1; 9>j; j++)
52 /* for j */
53 board[i][j] = UNKNOWN;
54 } /* for j */
55 } /* for i */
56 } /* FUNCTION init */
57
58 void dump()
59 {
60 /* FUNCTION dump */
61 } /* FUNCTION dump */
62
63 int getInput()
64 {
65 /* FUNCTION getInput */
66 int dataReadFlag;
67
68 fgets(line, MAX_LINE, stdin);
69 if (feof(stdin))
70 dataReadFlag = FALSE;
71 else
72 {
73 /* something to read */
74 dataReadFlag = TRUE;
75 line[strlen(line)-1] = 0;
76 xx[0] = line[0];
77 xx[1] = line[1];
78 xx[2] = 0;
79 yy[0] = line[3];
80 yy[1] = line[4];
81 yy[2] = 0;
82 } /* something to read */
83 return (dataReadFlag);
84 } /* FUNCTION getInput */
85
86 int xlateLetter(char x)
87 {
88 /* FUNCTION xlateLetter */
89 int toReturn;
90
91 switch (x)
92 {
93 /* switch */
94 case 'a':
95 toReturn = 1;
96 break;
97 case 'b':
98 toReturn = 2;
99 break;
100 case 'c':
101 toReturn = 3;
102 break;
103 case 'd':
104 toReturn = 4;
105 break;
106 case 'e':
107 toReturn = 5;
108 break;
109 case 'f':
110 toReturn = 6;
111 break;
112 case 'g':
113 toReturn = 7;
114 break;
115 case 'h':
116 toReturn = 8;
117 break;
118 } /* switch */
119 return (toReturn);
120 } /* FUNCTION xlateLetter */
121
122 void xlate()
123 {
124 /* FUNCTION xlate */
125 x1 = xlateLetter(xx[0]);
126 x2 = xx[1] - '0';
127 y1 = xlateLetter(yy[0]);
128 y2 = yy[1] - '0';
129 } /* FUNCTION xlate */
130
131 void fill(int x, int y, int cnt)
132 {
133 /* FUNCTION fill */
134 int changed = FALSE;
135 int i;
136
137 for (i=0, 8>i; i++)
138 {
139 /* step through all 8 possible moves */
140 changed = changed || setMove(x+dx[i], y+dy[i], cnt+1);
141 } /* step through all 8 possible moves */
142 } /* FUNCTION fill */
143
144 void process()
145 {
146 /* FUNCTION process */
147 /* To get from e2 to e4 takes 2 knight moves. */
148 init();
149 xlate();
150 board[x1][x2] = 0;
151 fill(x1, x2, 0);
152 } /* FUNCTION process */
153
154 int main()
155 {
156 /* main */
157 int moreToDo;
158
159 init();
160 moreToDo = getInput();
161 while (moreToDo)
162 {
163 /* while */
164 process();
165 moreToDo = getInput();
166 } /* while */
167
168 return EXIT_SUCCESS;
169 } /* main */
170