Exemple #1
0
/**
 * Check whether figure can move right (X positive)
 */
bool_t canMoveFigureRight (void)
{
    bool_t canMove = FALSE;
    uint8_t i;

    if (game.figure_is_vertical)
    {
        /* VERTICAL, Fuggoleges */
        if (game.figure_x < MAP_SIZE_X - 1)
        {
            canMove = TRUE;
            for (i = 0; i < FIGURE_SIZE; i++)
            {
                if (MAP_IS_NOT_EMPTY(game.figure_x + 1, game.figure_y + i))
                {
                    canMove = FALSE;
                    break;
                }
            }
        }
    }
    else
    {
        if (game.figure_x < MAP_SIZE_X - FIGURE_SIZE)
        {
            /* HORIZONTAL, Vizszintes */
            if (MAP_IS_EMPTY(game.figure_x + FIGURE_SIZE, game.figure_y))
            {
                canMove = TRUE;
            }
        }
    }

    return canMove;
}
Exemple #2
0
// takes in a map of chars to generate a wavefront map with no-go-pos=0, and rest the cost to go there
// map consists only of free and wall elements
void Sokoban::wavefront(std::vector< std::vector<char> > &map_out, std::vector< pos_t > &state){
    // make heap
    std::vector< wfElement > wfHeap;
    std::make_heap(wfHeap.begin(), wfHeap.end(), wfElement());

    // push starting point
    wfElement current, next;
    current.cost_ = MAP_WALKABLE;
    for(int i = 0; i < state.size(); i++){
        current.point_ = state[i];
        wfHeap.push_back(current);
    }
    std::push_heap(wfHeap.begin(), wfHeap.end(), wfElement());


    // while something can be poped, do so
    while (wfHeap.size()) {
        // pop value
        current = wfHeap.front();
        std::pop_heap(wfHeap.begin(), wfHeap.end(), wfElement());
        wfHeap.pop_back();

        // set value if free
        char state = map_out[current.point_.y_][current.point_.x_];
        if(MAP_IS_EMPTY(state) || MAP_IS_GOAL(state)){
            map_out[current.point_.y_][current.point_.x_] = current.cost_;
            // add neighbours
            next.cost_ = current.cost_ + 1;
            if(current.point_.y_ > 0){
                next.point_.x_ = current.point_.x_;
                next.point_.y_ = current.point_.y_- 1;
                wfHeap.push_back(next);
            }
            if(current.point_.y_ < map_size_.y_){
                next.point_.x_ = current.point_.x_;
                next.point_.y_ = current.point_.y_+ 1;
                wfHeap.push_back(next);
            }
            if(current.point_.x_ > 0){
                next.point_.x_ = current.point_.x_ - 1;
                next.point_.y_ = current.point_.y_;
                wfHeap.push_back(next);
            }
            if(current.point_.x_ < map_size_.x_){
                next.point_.x_ = current.point_.x_ + 1;
                next.point_.y_ = current.point_.y_;
                wfHeap.push_back(next);
            }
            std::push_heap(wfHeap.begin(), wfHeap.end(), wfElement());
        }
    }
}