예제 #1
0
/**
 * @brief countWorldParts: This function count how many parts are in the World
 * @param w: The World
 * @param blockedWorms: The Worms, that block fields
 * @return The Count of seperated Parts in the Map
*/
uint Tools::countWorldParts(const world& w, const WormContainer& blockedWorms){
    visitedMap map;
    uint result(0);
    createVisitedMap(w, map, blockedWorms);

    for(uint x=0; x< w.getSizeX(); ++x){
        for(uint y=0; y < w.getSizeY(); ++y){
            if(map[x][y] == false){
                result++;
                getWorldPartSize(w,map, WormPart(x,y));
            }
        }
    }
    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);
    }
}