-
Notifications
You must be signed in to change notification settings - Fork 13
/
go-competition.c
69 lines (56 loc) · 1.65 KB
/
go-competition.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
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
enum colour {
NO_COL = 0,
BLACK_R = 1,
WHITE_R = 2,
BOTH_R = 3,
HAS_ST = 4,
BLACK = 5,
WHITE = 6
};
enum colour grid[ 400 ] = { 0 };
int L;
enum colour charToCol(char c) {
switch (c) {
case '.': return NO_COL;
case 'B': return BLACK;
case 'W': return WHITE;
}
}
void fill_grid(void) {
int ch;
enum colour top, bot, lft, rht, acc;
do { ch = 0;
for ( int i = 0; i < L; ++i ) {
for ( int j = 0; j < L; ++j ) {
if (grid[i*L+j] >= BOTH_R) continue;
top = (i == 0 ) ? NO_COL : grid[ (i-1) * L+j ];
lft = (j == 0 ) ? NO_COL : grid[ i*L + j-1 ];
bot = (i == L-1) ? NO_COL : grid[ (i+1)*L + j ];
rht = (j == L-1) ? NO_COL : grid[ i*L + j+1 ];
acc = grid[i*L+j] | top | bot | lft | rht;
acc &= ~HAS_ST;
ch |= grid[i*L+j] != acc;
grid[i * L + j] = acc;
}
}
} while (ch);
}
void compute_score(void) {
int w = 6, b = 0;
for (int i = 0; i < L*L; ++i) switch (grid[i] & ~HAS_ST) {
case WHITE_R: ++w; break;
case BLACK_R: ++b; break;
}
printf("BLACK : %d\nWHITE : %d.5\n%s WINS\n", b, w, (b>w)?"BLACK" : "WHITE");
}
main() {
char ROW[1025];
scanf("%d", &L); fgetc(stdin);
for (int i = 0; i < L && fgets(ROW, 1025, stdin); i++)
for (int j = 0; j < L; j++) { grid[i*L+j] = charToCol(ROW[j]); }
fill_grid();
compute_score();
}