본문 바로가기
Computer Science

재미있는 오셀로 게임

by OKOK 2019. 2. 12.

1. 끝단 처리는 어떻게 했는지

2. 방향에 대해서 검사를 진행함

3. 오케이

4. 무엇인가가 놓여져 있어야 함

5. 규칙을 명확하게 파악하고

6. 코딩 시작함


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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include <stdio.h>
int tc;
 
int map[10][10];
const int dx[8= { -1,-1,-1,0,0,1,1,1 };
const int dy[8= { -1,0,1,-1,1,-1,0,1 };
 
const int WHITE = 2;
const int BLACK = 1;
const int NOT = 0;
const int TRUE = 1;
const int FLASE = 0;
int mapSize;
 
void put(int y, int x, int color)
{
    int opColor;
    if (color == BLACK)
        opColor = WHITE;
    else
        opColor = BLACK;
 
    int cnt = 0;
    int dirY;
    int dirX;
    int changeFlag = 0;
    for (int z = 0; z < 8; z++) {
        dirY = y + dy[z];
        dirX = x + dx[z];
 
        changeFlag = 0;
        // 한칸 이동한 방향이 반대색이고, 무엇인가 놓여져 있으면,
        for (cnt = 0; map[dirY][dirX] == opColor && map[dirY][dirX] != NOT; dirY += dy[z], dirX += dx[z]) {
            cnt++;
 
            if (map[dirY + dy[z]][dirX + dx[z]] == color) // 자신의 색깔의 돌을 만날 때까지 이동함
            {
                for (int n = 0; n < cnt; n++, dirY -= dy[z], dirX -= dx[z])
                {
                    map[dirY][dirX] = color;
                    changeFlag = 1;
                }
            }
            if (changeFlag == 1)
                break;
        }
    }
}
 
int main()
{
    freopen("input.txt""r", stdin);
    scanf("%d"&tc);
    int M;
 
    for (int testCase = 1; testCase <= tc; testCase++)
    {
        scanf("%d %d"&mapSize, &M);
        int y, x, color;
        int black = 0;
        int white = 0;
 
        for (int y = 0; y <= 9; y++)
        {
            for (int x = 0; x <= 9; x++)
            {
                map[y][x] = NOT;
            }
        }
 
        map[mapSize / 2][mapSize / 2= WHITE;
        map[mapSize / 2][mapSize / 2 + 1= BLACK;
        map[mapSize / 2 + 1][mapSize / 2= BLACK;
        map[mapSize / 2 + 1][mapSize / 2 + 1= WHITE;
 
        for (int j = 0; j < M; j++)
        {
            scanf("%d %d %d"&y, &x, &color);
            map[y][x] = color;
            put(y, x, color);
        }
 
        for (int y = 1; y <= mapSize; y++)
        {
            for (int x = 1; x <= mapSize; x++)
            {
                if (map[y][x] == BLACK)
                    black++;
                else if (map[y][x] == WHITE)
                    white++;
            }
        }
        printf("%d %d\n", black, white);
    }
    return 0;
}
cs

 


'Computer Science' 카테고리의 다른 글

석찬이의 받아쓰기  (0) 2019.02.12
배열의 분할  (0) 2019.02.12
러시아 국기 같은 깃발  (0) 2019.02.12
늘어지는 소리 만들기  (0) 2019.02.12
콩순이의 가장 싼 팰린드롬  (0) 2019.02.12

댓글