コード例 #1
0
ファイル: board.cpp プロジェクト: chankyu-choi/janggi
vector<Pos> Board::MoveGung(Pos pos)
{
    vector<Pos> candidates;
    int curr_id = stage[pos.y][pos.x];
    int nx, ny;
    for (int dy = -1; dy <= 1; dy++) {
        for (int dx = -1; dx <= 1; dx++) {
            nx = pos.x + dx;
            ny = pos.y + dy;
            if ((pos.x == 3 && (pos.y == 1 || pos.y == 8)) ||
                (pos.x == 4 && (pos.y == 0 || pos.y == 2 || pos.y == 7 || pos.y == 9)) ||
                (pos.x == 5 && (pos.y == 1 || pos.y == 8))) {
                // movable to only up, right, left, down side
                if (pos.DistWith(nx, ny) > 1)
                    continue;
            }
            if (nx >= 3 && nx <= 5
                && ((ny >= 0 && ny <= 2) || (ny >= 7 && ny <= 9))) {
                if (curr_id <= 6) {
                    if (stage[ny][nx]<0 || stage[ny][nx]>6) {
                        candidates.push_back(Pos(nx, ny));
                    }
                }
                else {
                    if (stage[ny][nx]<0 || stage[ny][nx] <= 6) {
                        candidates.push_back(Pos(nx, ny));
                    }
                }
            }
        }
    }
    
    return candidates;
}
コード例 #2
0
ファイル: board.cpp プロジェクト: chankyu-choi/janggi
vector<Pos> Board::MoveJol(Pos pos)
{
    int curr_id = stage[pos.y][pos.x];
    vector<Pos> candidates;
    
    int nx, ny;
    // down-ward
    //if ((curr_id <= 6 && standard_position) || curr_id >6 && !standard_position) {
    if (curr_id <= 6) {
        for (int dy = 0; dy <= 1; dy++) {
            for (int dx = -1; dx <= 1; dx++) {
                nx = pos.x + dx;
                ny = pos.y + dy;
                if (nx >= 0 && nx < kStageWidth && ny >= 0 && ny < kStageHeight && (stage[ny][nx] < 0 || (curr_id <= 6 && stage[ny][nx] > 6) || (curr_id > 6 && stage[ny][nx] <= 6))) {
                    if ((pos.x == 3 && pos.y == 7 && nx == 4 && ny == 8) ||
                        (pos.x == 5 && pos.y == 7 && nx == 4 && ny == 8) ||
                        (pos.x == 4 && pos.y == 8 && nx == 3 && ny == 9) ||
                        (pos.x == 4 && pos.y == 8 && nx == 5 && ny == 9) || pos.DistWith(nx, ny) <= 1.1) {
                        candidates.push_back(Pos(nx, ny));
                    }
                }
            }
        }
    }
    // up-ward
    else {
        for (int dy = -1; dy <= 0; dy++) {
            for (int dx = -1; dx <= 1; dx++) {
                nx = pos.x + dx;
                ny = pos.y + dy;
                if (nx >= 0 && nx < kStageWidth && ny >= 0 && ny < kStageHeight && (stage[ny][nx] < 0 || (curr_id <= 6 && stage[ny][nx] > 6) || (curr_id > 6 && stage[ny][nx] <= 6))) {
                    if ((pos.x == 3 && pos.y == 2 && nx == 4 && ny == 1) ||
                        (pos.x == 5 && pos.y == 2 && nx == 4 && ny == 1) ||
                        (pos.x == 4 && pos.y == 1 && nx == 3 && ny == 0) ||
                        (pos.x == 4 && pos.y == 1 && nx == 5 && ny == 0) || pos.DistWith(nx, ny) <= 1.1) {
                        candidates.push_back(Pos(nx, ny));
                    }
                }
            }
        }
    }
    return candidates;
}
コード例 #3
0
ファイル: board.cpp プロジェクト: chankyu-choi/janggi
vector<Pos> Board::MoveCha(Pos pos)
{
    int curr_id = stage[pos.y][pos.x];
    vector<Pos> candidates;
    
    // up
    if (pos.y>0) {
        for (int y = pos.y - 1; y >= 0; y--) {
            if (curr_id <= 6) {
                if (stage[y][pos.x] < 0) {
                    candidates.push_back(Pos(pos.x, y));
                }
                else {
                    if (stage[y][pos.x] > 6) {
                        candidates.push_back(Pos(pos.x, y));
                    }
                    break;
                }
            }
            else {
                if (stage[y][pos.x] < 0) {
                    candidates.push_back(Pos(pos.x, y));
                }
                else {
                    if (stage[y][pos.x] <= 6) {
                        candidates.push_back(Pos(pos.x, y));
                    }
                    break;
                }
            }
        }
    }
    // down
    if (pos.y<kStageHeight - 1) {
        for (int y = pos.y + 1; y < kStageHeight; y++) {
            if (curr_id <= 6) {
                if (stage[y][pos.x] < 0) {
                    candidates.push_back(Pos(pos.x, y));
                }
                else {
                    if (stage[y][pos.x] > 6) {
                        candidates.push_back(Pos(pos.x, y));
                    }
                    break;
                }
            }
            else {
                if (stage[y][pos.x] < 0) {
                    candidates.push_back(Pos(pos.x, y));
                }
                else {
                    if (stage[y][pos.x] <= 6) {
                        candidates.push_back(Pos(pos.x, y));
                    }
                    break;
                }
            }
        }
    }
    // right
    if (pos.x<kStageWidth - 1) {
        for (int x = pos.x + 1; x < kStageWidth; x++) {
            if (curr_id <= 6) {
                if (stage[pos.y][x] < 0) {
                    candidates.push_back(Pos(x, pos.y));
                }
                else {
                    if (stage[pos.y][x] > 6) {
                        candidates.push_back(Pos(x, pos.y));
                    }
                    break;
                }
            }
            else {
                if (stage[pos.y][x] < 0) {
                    candidates.push_back(Pos(x, pos.y));
                }
                else {
                    if (stage[pos.y][x] <= 6) {
                        candidates.push_back(Pos(x, pos.y));
                    }
                    break;
                }
            }
        }
    }
    // left
    if (pos.x>0) {
        for (int x = pos.x - 1; x >= 0; x--) {
            if (curr_id <= 6) {
                if (stage[pos.y][x] < 0) {
                    candidates.push_back(Pos(x, pos.y));
                }
                else {
                    if (stage[pos.y][x] > 6) {
                        candidates.push_back(Pos(x, pos.y));
                    }
                    break;
                }
            }
            else {
                if (stage[pos.y][x] < 0) {
                    candidates.push_back(Pos(x, pos.y));
                }
                else {
                    if (stage[pos.y][x] <= 6) {
                        candidates.push_back(Pos(x, pos.y));
                    }
                    break;
                }
            }
        }
    }
    
    // diagonal
    if (pos.x >= 3 && pos.x <= 5
        && ((pos.y >= 0 && pos.y <= 2) || (pos.y >= 7 && pos.y <= 9))) {
        int nx, ny;
        for (int dy = -1; dy <= 1; dy++) {
            for (int dx = -1; dx <= 1; dx++) {
                nx = pos.x + dx;
                ny = pos.y + dy;
                if ((pos.x == 3 && (pos.y == 1 || pos.y == 8)) ||
                    (pos.x == 4 && (pos.y == 0 || pos.y == 2 || pos.y == 7 || pos.y == 9)) ||
                    (pos.x == 5 && (pos.y == 1 || pos.y == 8))) {
                    // movable to only up, right, left, down side
                    if (pos.DistWith(nx, ny) > 1)
                        continue;
                }
                if (nx >= 3 && nx <= 5
                    && ((ny >= 0 && ny <= 2) || (ny >= 7 && ny <= 9))) {
                    if (curr_id <= 6) {
                        if (stage[ny][nx]<0 || stage[ny][nx]>6) {
                            candidates.push_back(Pos(nx, ny));
                        }
                    }
                    else {
                        if (stage[ny][nx]<0 || stage[ny][nx] <= 6) {
                            candidates.push_back(Pos(nx, ny));
                        }
                    }
                }
            }
        }
    }
    
    return candidates;
}