예제 #1
0
/**************************************************************************************************
 *                                  getLength
 * ***********************************************************************************************/
uint getWorldPartSize(const world& w, visitedMap& map, const WormPart& p){
    NeighborContainer mustVisited;
    mustVisited.push_back(p);
    uint result(0);

    while(!mustVisited.empty()){
        WormPart cur = mustVisited[mustVisited.size()-1];
        mustVisited.pop_back();
        if((w.getWormMap().getTheHomeFor(cur.getX(), cur.getY()) != 1) && (!map[cur.getX()][cur.getY()])){
            result++;
            map[cur.getX()][cur.getY()] = true;
            NeighborContainer* buffer = w.getNeighborFields(cur);
            for(auto p: *buffer){
                mustVisited.push_back(p);
            }
        }
    }

    return result;
}
예제 #2
0
/**
 * @brief createVisitedMap
 * @param w: The Current World: needed for size and blocked fields
 * @param map: The Result Map
 * @param worms: Worms that block fields
 */
void createVisitedMap(const world& w, visitedMap& map, const WormContainer& worms){
    map.clear();
    for(uint x=0; x<w.getSizeX(); ++x){
        visitedMapInnerContainer innerContainer;
        for(uint y=0; y<w.getSizeY(); ++y){
            if(w.getWormMap().getTheHomeFor(x,y) == 1){
                innerContainer.push_back(true);
            } else{
                bool found(false);
                for(const Worm& wurm: worms){
                    if(wurm.contains(WormPart(x,y))) {
                        innerContainer.push_back(true);
                        found = true;
                        break;
                    }
                }
                if(!found)
                    innerContainer.push_back(false);
            }
        }
        map.push_back(innerContainer);
    }
}