回答編集履歴
2
改良
answer
CHANGED
|
@@ -15,15 +15,15 @@
|
|
|
15
15
|
|
|
16
16
|
int check(int target, int ii, int jj, int di, int dj, int value) {
|
|
17
17
|
for(int i=ii+di, j=jj+dj, otherCount=0; 0<=i && i<8 && 0<=j && j<8; i+=di, j+=dj) {
|
|
18
|
-
if(field[i][j] == target) return otherCount > 0 ? value : 0;
|
|
18
|
+
if(field[i][j] == target) return otherCount > 0 ? value : 0; //自石
|
|
19
|
-
if(field[i][j] == 0) return 0;
|
|
19
|
+
if(field[i][j] == 0) return 0; //空き
|
|
20
|
-
otherCount ++;
|
|
20
|
+
otherCount ++; //相手石
|
|
21
21
|
}
|
|
22
22
|
return 0;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
int search(int target) {
|
|
26
|
-
int count = 0;
|
|
26
|
+
int count = 0; //置ける場所数
|
|
27
27
|
for(int i=0; i<8; i++) {
|
|
28
28
|
for(int j=0; j<8; j++) {
|
|
29
29
|
canput[i][j] = 0;
|
|
@@ -50,8 +50,7 @@
|
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
void put(int target, int ii, int jj, int di, int dj) {
|
|
53
|
-
for(int i=ii+di, j=jj+dj;
|
|
53
|
+
for(int i=ii+di, j=jj+dj; field[i][j]!=target; i+=di, j+=dj) {
|
|
54
|
-
if(field[i][j] == target) break;
|
|
55
54
|
field[i][j] = target;
|
|
56
55
|
}
|
|
57
56
|
}
|
|
@@ -63,24 +62,25 @@
|
|
|
63
62
|
}
|
|
64
63
|
}
|
|
65
64
|
|
|
65
|
+
//テストデータ
|
|
66
66
|
int ti[] = { 2, 2, 5, 5, 3, 2 };
|
|
67
67
|
int tj[] = { 3, 2, 4, 5, 2, 4 };
|
|
68
68
|
|
|
69
69
|
int main() {
|
|
70
|
-
|
|
70
|
+
memset(field, 0, sizeof(field));
|
|
71
|
-
|
|
71
|
+
field[3][4] = field[4][3] = 1;
|
|
72
|
-
|
|
72
|
+
field[3][3] = field[4][4] = 2;
|
|
73
73
|
|
|
74
|
-
|
|
74
|
+
int turn = 1; //3との XOR で 1<->2 を繰り返す
|
|
75
|
-
|
|
75
|
+
for(int round=0; round<sizeof(ti)/sizeof(int); round++, turn^=3) {
|
|
76
|
-
int count = search(turn);
|
|
77
|
-
display();
|
|
78
|
-
if(count == 0) printf("pass");
|
|
79
|
-
else over(turn, ti[round], tj[round]);
|
|
80
|
-
}
|
|
81
76
|
int count = search(turn);
|
|
82
77
|
display();
|
|
78
|
+
if(count == 0) printf("pass");
|
|
79
|
+
else over(turn, ti[round], tj[round]);
|
|
80
|
+
}
|
|
81
|
+
int count = search(turn);
|
|
82
|
+
display();
|
|
83
83
|
|
|
84
|
-
|
|
84
|
+
return 0;
|
|
85
85
|
}
|
|
86
86
|
```
|
1
コード改良
answer
CHANGED
|
@@ -72,7 +72,7 @@
|
|
|
72
72
|
field[3][3] = field[4][4] = 2;
|
|
73
73
|
|
|
74
74
|
int turn = 1;
|
|
75
|
-
for(int round=0; round<sizeof(ti)/sizeof(int); round++, turn=
|
|
75
|
+
for(int round=0; round<sizeof(ti)/sizeof(int); round++, turn^=3) {
|
|
76
76
|
int count = search(turn);
|
|
77
77
|
display();
|
|
78
78
|
if(count == 0) printf("pass");
|