Submission

Status:

PPPPPP-PPPPP-P----PP

Subtask/Task Score:

70/100

Score: 70

User: chokun

Problemset: Othello

Language: cpp

Time: 0.003 second

Submitted On: 2026-10-14 21:24:34

#include <bits/stdc++.h>
using namespace std;

const int BOARD_SIZE = 8;

int dr[] = {-1, -1, -1,  0, 0,  1, 1, 1};
int dc[] = {-1,  0,  1, -1, 1, -1, 0, 1};

bool isBoardFull(const vector<string>& board) {
    for (int i = 0; i < BOARD_SIZE; ++i) {
        for (int j = 0; j < BOARD_SIZE; ++j) {
            if (board[i][j] == '_') {
                return false;
            }
        }
    }
    return true;
}

void playMove(vector<string>& board, int r, int c, char current_player) {
    char opponent = (current_player == 'B') ? 'W' : 'B';
    board[r][c] = current_player;

    for (int dir = 0; dir < 8; ++dir) {
        int nr = r + dr[dir];
        int nc = c + dc[dir];
        vector<pair<int, int>> to_flip;

        while (nr >= 0 && nr < BOARD_SIZE && nc >= 0 && nc < BOARD_SIZE && board[nr][nc] == opponent) {
            to_flip.push_back({nr, nc});
            nr += dr[dir];
            nc += dc[dir];
        }

        if (nr >= 0 && nr < BOARD_SIZE && nc >= 0 && nc < BOARD_SIZE && board[nr][nc] == current_player) {
            for (auto p : to_flip) {
                board[p.first][p.second] = current_player;
            }
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    vector<string> board(BOARD_SIZE);
    
    // 1. รับบอร์ดเริ่มต้นขนาด 8x8
    for (int i = 0; i < BOARD_SIZE; ++i) {
        if (!(cin >> board[i])) return 0;
    }

    char current_player = 'B';
    int r, c;

    while (cin >> r >> c) {
        if (r == -1 && c == -1) {
            break;
        }

        playMove(board, r, c, current_player);

        if (isBoardFull(board)) {
            break;
        }

        current_player = (current_player == 'B') ? 'W' : 'B';
    }

    for (int i = 0; i < BOARD_SIZE; ++i) {
        cout << board[i] << "\n";
    }

    int black_count = 0;
    int white_count = 0;
    for (int i = 0; i < BOARD_SIZE; ++i) {
        for (int j = 0; j < BOARD_SIZE; ++j) {
            if (board[i][j] == 'B') black_count++;
            if (board[i][j] == 'W') white_count++;
        }
    }

    if (black_count > white_count) {
        cout << "black wins\n";
    } else if (white_count > black_count) {
        cout << "white wins\n";
    } else {
        cout << "draw\n";
    }
}