Exemple #1
0
bool obstInMap(obst_t* obst, map_t* map){
    if(
       pointInMap(obst->top, obst->left, map)
       && pointInMap(obst->bottom, obst->right, map)
    ){
        return true;
    }else{
        return false;
    }
}
void color(Point start, int col){
    push(start);
    while (queueIsNotEmpty) {
        Point curr = pop();
        pointInMap(curr) = col;
        int i;
        for (i = 0; i < MOVCOUNT; i++) {
            Point next = nextPoint(curr, i);
            if (isValidPoint(next) && pointInMap(next) == SPOT) {
                push(next);
            }
        }
    }
    resetQueue();
}
int doSearch(Point start){
    int minDist = INT_MAX;
    pointInMap(start) = 0;
    push(start)
    while (queueIsNotEmpty) {
        Point curr = pop();
        int i;
        for (i = 0; i < MOVCOUNT; i++) {
            Point next = nextPoint(curr, i);
            if (isValidPoint(next)) {
                if (pointInMap(next) == SPOTB && minDist > pointInMap(curr)) {
                    minDist = pointInMap(curr);
                } else if (pointInMap(next) == SPOTA) {
                    pointInMap(next) = 0;
                    push(next);
                } else if (pointInMap(next) == EMPTY) {
                    pointInMap(next) = pointInMap(curr) + 1;
                    push(next);
                } else if (pointInMap(next) > pointInMap(curr) + 1) {
                    pointInMap(next) = pointInMap(curr) + 1;
                    push(next);
                }
            }
        }
    }
    return minDist;
}