Ejemplo n.º 1
0
void Graph::enumerateSubsets (VVertices *R, VVertices *F, int m, int n, VVertices *T, int q = 0, int r = 0)
{
    if (q == n)
    {
		VVertices *newR = new VVertices(*R);
		newR->insert(newR->end(), T->begin(), T->end());
		for (VVertices::iterator it = newR->begin(); it != newR->end(); ++it)
			std::cout << (*it) << "\t";
		std::cout << std::endl;
	
		VVertices *newF = new VVertices();
		for (int j = *std::min_element(newR->begin(),newR->end())+1; j < size; j++)
		{
			if (areAdjacent(T,j) && !areAdjacent(R,j) && std::find(newR->begin(),newR->end(),j) == newR->end()) {newF->push_back(j); }
		}
		slyce(newR,newF,m-n);

		delete newR;
		delete newF;
    }

    else
    {
        for (int i = r; i < m; i++)
        {
            T[q] = F[i];
            enumerateSubsets(R,F,m,n,T,q+1,i+1);
        }
    }
}
Ejemplo n.º 2
0
		void PathSearch::initialize(TileMap* _tileMap)
		{

			currentTileMap = _tileMap;

			int _debugTileX = 2;
			int _debugTileY = 2;

			int _nRows = _tileMap->getRowCount();
			int _nCols = _tileMap->getColumnCount();

			for (int y = 0; y < _nRows; y++)
				for (int x = 0; x < _nCols; x++)
				{

					SearchNode* _nNode = new SearchNode;
					_nNode->data = _tileMap->getTile(y, x);
					SearchMap[_tileMap->getTile(y, x)] = _nNode;

				}

			for (int y = 0; y < _nRows; y++)
				for (int x = 0; x < _nCols; x++)
					for (int _y = (y - 1); _y < (y + 2); _y++)
						for (int _x = (x - 1); _x < (x + 2); _x++)
							if (_x >= 0 && _x < _nCols && _y >= 0 && _y <= _nRows && (x != _x || y != _y) && _tileMap->getTile(y, x) && _tileMap->getTile(y, x)->getWeight())
							{

								Tile* _thisTile = _tileMap->getTile(y, x);
								Tile* _adjTile = _tileMap->getTile(_y, _x);

								/*if (!_thisTile->getFill())
									_thisTile->setFill(0xFFFFFF00);

								if (x == _debugTileX && y == _debugTileY)
								{

									_thisTile->setFill(0xFF00FF00);
									_adjTile->setFill(0xFFFF0000);

								}*/


								if (_thisTile != _adjTile && _thisTile && _adjTile && areAdjacent(_thisTile, _adjTile))
								{
									SearchMap[_thisTile]->edges.push_back(SearchMap[_adjTile]);

									/*if (x == _debugTileX && y == _debugTileY)
										_adjTile->setFill(0xFF0000FF);*/

								}

							}


		}
Ejemplo n.º 3
0
/**
 * If tile borders empty space, moves tile and returns true, else
 * returns false. 
 */
bool move(int tile)
{
    position pos_tile = getTilePosition(tile);
    position pos_empty = getTilePosition(EMPTY);

    if (areAdjacent(pos_tile, pos_empty)) {
        swap(pos_tile, pos_empty);
        return true;
    } else
        return false;
}
Ejemplo n.º 4
0
MyGraph MyGraph::graph_complement() const{
    MyGraph output = copyGraph();
    graph_hashmap::const_iterator g_iter = thegraph.begin();
    my_set::const_iterator g2_iter;
    while (g_iter != thegraph.end()){
        g2_iter = set_of_vertices.begin();
        while ( g2_iter != set_of_vertices.end()){
            if (strcmp(g_iter->first.c_str(),(*g2_iter).c_str()) ){ //avoid self-loops
                if( areAdjacent(g_iter->first, *g2_iter) )
                    output.removeEdge(g_iter->first, *g2_iter);
                else
                    if (!output.areAdjacent(g_iter->first, *g2_iter))
                        output.insertEdge(g_iter->first, *g2_iter);
                }
            *g2_iter++;
            }
        *g_iter++;
        }
    return output;
}
Ejemplo n.º 5
0
//returns ms elapsed, -2 if the monster dies
int
shMonster::doPet ()
{
    int i, n;
    shCoord coord[9];
    int info[9];
    int best = -1;
    int score, bestscore = -9999;
    int flags = kLinedUp | kTrap;
    int res = -1;
    int dist;
    int scrubbot = isA (kMonScrubbot);

    int val_linedup;
    int val_adjacent;
    int val_dist;
    int val_track;
    int val_monst;

    shMonster *c;
    int elapsed;

    /* first priority is always to drink any beer in our square! */
    res = drinkBeer ();
    if (-1 != res) return res;

    if (mHP > mMaxHP / 4) {
        flags |= kMonster;
    }

    if (canSee (&Hero)) {
        findPetGoal ();

        val_linedup = -10;
        val_dist = -2;
        val_track = -5;
        val_adjacent = RNG (3) ? -5 : 10;
        val_monst = 10;
    } else {
        mDestX = Hero.mX;
        mDestY = Hero.mY;
        val_linedup = 0;
        val_dist = -1;
        val_track = -10;

        val_adjacent = 5;
        val_monst = 5;
    }

    if (isSessile ()) {
        val_monst += 50;
    }

    if (scrubbot) flags |= kFreeWreck;
    n = findSquares (flags, coord, info);
    for (i = 0; i < n; i++) {
        score = 0;
        if (info[i] & kTrap
            and RNG (30)) /* small chance that a pet will walk on a trap*/
        {
            score -= 30;
        }
        if (info[i] & kFreeWreck) score += 50;
        if (info[i] & kLinedUp) score += val_linedup;
        if (info[i] & kMonster) {
            c = (shMonster *) mLevel->getCreature (coord[i].mX, coord[i].mY);
            if (c and !c->isHero () and !c->isPet () and c->isHostile () and
            /* Smart bombs and missiles should be ready to sacrifice
               themselves on any hostile target. isExplosive checks this. */
                (c->mCLevel <= mCLevel + 1 or isExplosive ()))
            {
                score += c->isHostile () ? val_monst : val_monst / 2;
            } else if (c != this) {
                score -= 30;
            }
        }
        if (coord[i].mX == mX and coord[i].mY == mY) {
            score -= 10;
        }
        if (areAdjacent (coord[i].mX, coord[i].mY, Hero.mX, Hero.mY))
            score += val_adjacent;
        dist = distance (coord[i].mX, coord[i].mY, mDestX, mDestY);
        if (dist > 50 and val_dist > 0) { dist = 50; }
        score += val_dist * dist;

        int ti;
        for (ti = 0 ; ti < TRACKLEN; ti++) {
            if (mTrack[ti].mX == coord[i].mX and mTrack[ti].mY == coord[i].mY) {
                score += val_track;
            }
        }

        if (score > bestscore) {
            bestscore = score;
            best = i;
        }
    }

    if (-1 == best) {
        /* nothing to do but stay where we are for now */
        return 500;
    }
    if (coord[best].mX == mX and coord[best].mY == mY) {
        if (info[best] & kFreeWreck) {
            shObjectVector *v = mLevel->getObjects (mX, mY);
            shObject *obj;
            for (int i = 0; i < v->count (); ++i) {
                obj = v->get (i);
                if (obj->isA (kObjWreck)) {
                    v->remove (obj);
                    if (0 == v->count ()) {
                        delete v;
                        mLevel->setObjects (mX, mY, NULL);
                    }
                    return utilizeWreck (obj);
                }
            }
        }
        return 250;
    } else {
        if (info[best] & kMonster) {
            c = (shMonster *)
                mLevel->getCreature (coord[best].mX, coord[best].mY);
            doAttack (c, &elapsed);
            return elapsed;
        }
        if (!isSessile ())
            return doMove (vectorDirection (mX, mY,
                                            coord[best].mX, coord[best].mY));
    }
    return 250;
}
Ejemplo n.º 6
0
bool Graph::areAdjacent (VVertices *v1, VVertices *v2)
{
    for (VVertices::iterator it = v1->begin(); it != v1->end(); ++it)
		if (areAdjacent(*it,v2)) return true;
    return false;
}
Ejemplo n.º 7
0
bool Graph::areAdjacent (VVertices *v1, int v2) { return areAdjacent(v2,v1); }