/home/toolbox/public_html/solutions/8/852/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 <stdlib.h>
7 #include <math.h>
8 #include <stdint.h>
9
10 #define TRUE (1 == 1)
11 #define FALSE (1 != 1)
12
13 #define DEBUG if (FALSE)
14
15 /* fprintf(stderr, "functionName: message", varslist); */
16
17 /*
18 * Author: Isaac Traxler
19 * Date: 2020-10-31
20 * Purpose: fun
21 * Problem: 852 - Deciding Victory in Go
22 */
23
24 /*
25 * This template reads data a specified number of times.
26 */
27
28 #define MAX_GRID 11
29 #define X 8
30 #define O 9
31 #define BOUNDARY -1
32 #define EMPTY 0
33 #define BOARD_START 1
34 #define BOARD_END 9
35
36 int numberOfTimes;
37 int grid[MAX_GRID][MAX_GRID];
38
39 void init()
40 {
41 /* FUNCTION init */
42 scanf("%d ", &numberOfTimes);
43 } /* FUNCTION init */
44
45 void initEach()
46 {
47 /* FUNCTION initEach */
48 int i;
49 int j;
50
51 for (i=0; MAX_GRID>i; i++)
52 {
53 /* for i */
54 grid[i][0] = BOUNDARY;
55 grid[i][10] = BOUNDARY;
56 grid[0][i] = BOUNDARY;
57 grid[10][i] = BOUNDARY;
58 } /* for i */
59 for (i=BOARD_START; BOARD_END=>i; i++)
60 {
61 /* for i */
62 for (j=BOARD_START; BOARD_END=>j; j++)
63 {
64 /* for j */
65 grid[i][j] = EMPTY;
66 } /* for j */
67 } /* for i */
68 } /* FUNCTION initEach */
69
70 void dump()
71 {
72 /* FUNCTION dump */
73 int i;
74 int j;
75
76 for (i=BOARD_START; BOARD_END>=i; i++)
77 {
78 /* for i */
79 for (j=BOARD_START; BOARD_END>=j; j++)
80 {
81 /* for j */
82 printf(" %2d", grid[i][j]);
83 } /* for j */
84 printf("\n");
85 } /* for i */
86 printf("\n");
87 } /* FUNCTION dump */
88
89 void getInput()
90 {
91 /* FUNCTION getInput */
92 int i;
93 int j;
94 char tmp;
95
96 for (i=BOARD_START; BOARD_END>=i; i++)
97 {
98 /* for i */
99 for (j=BOARD_START; BOARD_END>=j; j++)
100 {
101 /* for j */
102 scanf("%c", &tmp);
103 printf("[%c]\n", tmp);
104 switch (tmp)
105 {
106 /* switch */
107 case 'X':
108 grid[i][j] = X;
109 break;
110 case 'O':
111 grid[i][j] = O;
112 break;
113 } /* switch */
114 } /* for j */
115 scanf("%c", &tmp);
116 } /* for i */
117 } /* FUNCTION getInput */
118
119 int flood(int x, int y, int vl)
120 {
121 /* FUNCTON flood */
122
123 } /* FUNCTON flood */
124
125 void fill(int t)
126 {
127 /* FUNCTION fill */
128 int i;
129 int j;
130 int chg;
131
132 chg = 1;
133 while (0 < chg)
134 {
135 /* while */
136 chg = 0;
137 for (i=BOARD_START; BOARD_END>=i; i++)
138 {
139 /* for i */
140 for (j=BOARD_START; BOARD_END>=j; j++)
141 {
142 /* for j */
143 if (EMPTY == grid[i][j])
144 {
145 /* empty spot */
146 chg = chg + flood(i, j, t);
147 } /* empty spot */
148 } /* for j */
149 } /* for i */
150 } /* while */
151 } /* FUNCTION fill */
152
153 void process()
154 {
155 /* FUNCTION process */
156 dump();
157 fill(X);
158 fill(O);
159 } /* FUNCTION process */
160
161 int main()
162 {
163 /* main */
164 int i;
165
166 init();
167 for (i=0; i<numberOfTimes; i++)
168 {
169 /* while */
170 initEach();
171 getInput();
172 process();
173 } /* while */
174
175 return EXIT_SUCCESS;
176 } /* main */
177
178