コード例 #1
0
ファイル: AI.cpp プロジェクト: Group-3/Pacman
bool AI::calcRoute(Tile *startTile, Tile *endTile)
{
	//calculate costs and find shortest path
	int cost = tryAllDirs(startTile, endTile, 0);
	if(cost != INT_MAX)
	{
		route.clear();
		Tile* currentTile = startTile;
		//build list of directions as route
		while(true)
		{
			currentTile = currentTile->checkDirection(currentTile->shortestDir);
			if(currentTile != endTile)
				route.push_back(currentTile->shortestDir);
			else
				return true;
		}
		return true;
	}
	return false;
}
コード例 #2
0
ファイル: AI.cpp プロジェクト: Group-3/Pacman
int AI::tryAllDirs(Tile *tile, Tile *endTile, int cost)
{
	//if the current tile is the end tile we've reached our goal.
	if(tile == endTile)
		return cost;
	bool allVisited = true;
	//for every direction
	for(int i = 0; i < D_SIZE; i++)
	{
		//if not null
		if(tile->checkDirection((Direction)i))
		{
			if(!tile->checkDirection((Direction)i)->visited)
			{
				tile->checkDirection((Direction)i)->cost = cost + 1;
				allVisited = false;
			}
		}
	}
	//if all are already visited we've reached a dead end.
	if(allVisited)
		return INT_MAX;

	//recursively call this function for all unvisited neighbor tiles.
	for(int i = 0; i < D_SIZE; i++)
	{
		if(tile->checkDirection((Direction)i))
		{
			//if tile is not visited and has higher cost than this.
			if(!tile->checkDirection((Direction)i)->visited && tile->checkDirection((Direction)i)->cost > cost + 1)
			{
				cost = tryAllDirs(tile->checkDirection((Direction)i),endTile,cost+1);
				tile->shortestDir = (Direction)i;
			}
		}
	}
	return cost;
}
コード例 #3
0
ファイル: CEngine.cpp プロジェクト: zpc930/pandoramapper
void CEngine::parseEvent()
{
    print_debug(DEBUG_ANALYZER, "in parseEvent()");

    if (event.movementBlocker) {
    	// notify renderer to remove all the unnecessary line drawn
    	commandQueue.dequeue();
    	toggle_renderer_reaction();
    	return;
    }

    if (event.name != "") {
        print_debug(DEBUG_ANALYZER, "Converting Room Name to ascii format");
        latinToAscii( event.name);
        last_name = event.name;
    }

    if (event.desc != "") {
        print_debug(DEBUG_ANALYZER, "Converting Description to ascii format");
        latinToAscii( event.desc );
        last_desc = event.desc;
    }
    if (event.exits != "") {
        last_exits = event.exits;
    }
    if (event.terrain != -1) {
        last_terrain = event.terrain;
    }

    setMgoto( false );    /* if we get a new room data incoming, mgoto has to go away */

    print_debug(DEBUG_ANALYZER, "Entering the main part of the function");

    print_debug(DEBUG_ANALYZER, "ANALYZER Event. \r\nNAME %s\r\nDESC %s\r\nEXITS %s\r\nBLIND %i, MOVEMENT %i SCOUT %i",
        (const char *) event.name, (const char *) event.desc, (const char *) event.exits
        /*(const char *) event.prompt*/, event.blind, event.movement, event.scout);

    if (event.scout) {
        print_debug(DEBUG_ANALYZER, "SCOUT flag is set. Dropping event");
        return;
    }


    if (event.name.indexOf("It is pitch black...") == 0) {
        print_debug(DEBUG_ANALYZER, "NO light BLIND set");
        event.blind = true;
    }
    if (event.name == "" && event.movement == true) {
        print_debug(DEBUG_ANALYZER, "NAME is empty and Movement is true. Assuming BLIND");
        event.blind = true;
    }

    if (event.name == "" && event.blind == false) {
        print_debug(DEBUG_ANALYZER, "EMPTY name and no blind set. Assuming addedroom-data update incoming.");
        if (addedroom) {
            addedroom->setTerrain(last_terrain);
            resetAddedRoomVar();
            toggle_renderer_reaction();
        }
        return;
    }


    if (event.movement == true) {
        last_movement = event.dir;
    	if (event.dir =="") {
            tryAllDirs();
            // command's queue is useless then, no?
            commandQueue.clear();
    	} else {
            tryDir();
    	}
    } else {
        if (event.name != "")
            tryLook();
    }


    swap();

    if (stacker.amount() == 0)
        resync();

    print_debug(DEBUG_ANALYZER, "Done. Sending an event to the Renderer");
    toggle_renderer_reaction();
}