void MapCommand::invoke(vector<string>& parameters) { cout << "Map command." << endl; if (parameters.size() > 0) { TestMode* mode = dynamic_cast<TestMode*>(m_game->getMode(BlockWorld::TEST_MODE)); if (mode) { cout << "Found mode." << endl; MapLoader* loader = new MapLoader(); MapDirectory* map = NULL; loader->loadDirectory("Resources/Maps"); list<MapDirectory*>& maps = loader->getMaps(); list<MapDirectory*>::iterator it = maps.begin(); for ( ; it != maps.end(); it++) { cout << "Map: " << (*it)->getDirectoryName() << " (" << parameters[0] << ")" << endl; if ((*it)->getDirectoryName().compare(parameters[0]) == 0) { map = *it; break; } } if (map) { cout << "Found map." << endl; mode->setMap(map); m_game->setCurrentMode(BlockWorld::TEST_MODE); } delete loader; } } }
void MenuScene::Initialize() { camera = new Camera(Vector2(0, 0), Vector2(game->Render->GetWidth(), game->Render->GetHeight())); camVelocity = Vector2(0.4, 0.7); MapLoader* ml = new MapLoader(this->game); Map = ml->LoadMap("maps/mainmenu.xml", this); delete ml; // Setup buttons singleButton = new Button(game, game->Content->LoadTexture("gui/buttons/Green250.png"), game->Content->LoadTexture("gui/buttons/Hover250.png"), framework::Rectangle(game->Render->GetWidth() / 2 - 100, game->Render->GetHeight() / 2 - 100, 200, 40), this); singleButton->LButtonDownCallback = &singlePlayerButtonDown; multiButton = new Button(game, game->Content->LoadTexture("gui/buttons/Green250.png"), game->Content->LoadTexture("gui/buttons/Hover250.png"), framework::Rectangle(game->Render->GetWidth() / 2 - 100, game->Render->GetHeight() / 2 - 50, 200, 40), this); settingsButton = new Button(game, game->Content->LoadTexture("gui/buttons/Blue250.png"), game->Content->LoadTexture("gui/buttons/Hover250.png"), framework::Rectangle(game->Render->GetWidth() / 2 - 100, game->Render->GetHeight() / 2, 200, 40), this); exitButton = new Button(game, game->Content->LoadTexture("gui/buttons/Red250.png"), game->Content->LoadTexture("gui/buttons/Hover250.png"), framework::Rectangle(game->Render->GetWidth() / 2 - 100, game->Render->GetHeight() / 2 + 50, 200, 40), this); exitButton->LButtonDownCallback = &exitButtonDown; Scene::Initialize(); }
int main(int argc, char **argv) { QCoreApplication application(argc, argv); QStringList arguments = application.arguments(); if(arguments.count() > 1) { QString baseName = arguments[1]; QString outputFilename = QStringEx::format("%1.map", baseName); QFile outputFile(outputFilename); if(outputFile.open(QIODevice::WriteOnly)) { MapLoader mapLoader; Map map = mapLoader.load(baseName); QDataStream stream(&outputFile); stream << map; } else { qDebug() << "Could not open output file for writing"; } } return 0; }
void ECBSSearch::printPaths(const MapLoader& ml) { for (size_t i = 0; i < paths.size(); i++) { cout << "AGENT " << i << " Path: "; for (auto& entry : *paths[i]) { std::cout << entry.location << " " << entry.action << ", "; } cout << endl; } { using namespace pt; ptree pt; ptree agents; for (size_t ag = 0; ag < paths.size(); ag++) { ptree agent; std::stringstream sstr; sstr << "create" << ag + 1; agent.put("name", sstr.str()); ptree path; size_t t = 0; for (auto& entry : *paths[ag]) { ptree pathentry; pathentry.put("x", ml.col_coordinate(entry.location)); pathentry.put("y", ml.row_coordinate(entry.location)); pathentry.put("theta", theta(entry.orientation)); pathentry.put("arrival", t); path.push_back(std::make_pair("", pathentry)); ++t; } agent.add_child("path", path); agents.push_back(std::make_pair("", agent)); } pt.add_child("agents", agents); write_json("schedule_discrete.json", pt); } }
void NetworkTestMode::onLoadMap(LoadMapMessage& message) { performStop(); MapLoader* loader = new MapLoader(); MapDirectory* map = NULL; loader->loadDirectory("Resources/Maps"); list<MapDirectory*>& maps = loader->getMaps(); list<MapDirectory*>::iterator it = maps.begin(); for ( ; it != maps.end(); it++) { if ((*it)->getDirectoryName().compare(message.getName()) == 0) { map = *it; break; } } if (map) { Engine* engine = m_game->getEngine(); ImageMapWorldCreator* worldCreator = new ImageMapWorldCreator(); m_world = worldCreator->createWorld(*engine, *map); m_camera = new MouseScrollCamera(*m_world, *engine); delete worldCreator; m_objectManager = new ObjectManager(); m_gibLoader = new GibResourceLoader(*engine); m_gibLoader->loadFile("Resources/Gibs/gibs.xml"); // If we get here the map should be successfully loaded ;) // Therefore we send the message to the server. MapLoadedMessage loaded(m_thisNetworkID); m_game->getNetwork()->sendMessage(loaded); } delete loader; }
// Load all maps from the resources folder void loadMaps() { MapLoader loader; int fIndex = agk::OpenToRead("maps.dat"); string line; int counter = 0; while(!agk::FileEOF(fIndex)) { line = agk::ReadLine(fIndex); loader.loadFile(line.c_str()); tracks[counter] = loader.getTrack(); counter++; } agk::CloseFile(fIndex); }
int MapTileLayer::_tileRegion(const Coordinate& a, const Coordinate& b, int lod, bool async) { MapLoader* loader = MapViewLayer::Context.Loader; auto ai = loader->getTileIndex(a, lod); auto bi = loader->getTileIndex(b, lod); Coordinate size = loader->getTileSize(lod); cocos2d::log("Map rebuild (%d,%d) (%d,%d)", ai.first, ai.second, bi.first, bi.second); int tilesNotYetLoaded = 0; for(int i = ai.second; i <= bi.second; ++i) // y axis { for(int j = ai.first; j <= bi.first; ++j) // x axis { Coordinate position = Coordinate(j*size.x, i*size.y); const MapTileInfo& tileInfo = loader->getMapTileInfo({j, i}, lod); tilesNotYetLoaded += addTile(tileInfo, position, size, async); } } return tilesNotYetLoaded; }
void GameManager::Run() { std::string title("Ball Game"); DrawManager::Instance()->CreateWindow( title, 1360, 768, true, 60 ); ComponentRegistrator::Register( *ComponentFactory::Instance() ); ObjectTemplateManager::Instance()->LoadObjects( std::string("../resources/data/objects/") ); MapLoader loader; loader.LoadMap( std::string( "../resources/data/maps/protomap/" ) ); ObjectManager::Instance()->InitAllObjects(); Camera::Instance()->SetActiveCameraID( 0 ); sf::RenderWindow* windowPtr = DrawManager::Instance()->Window(); while( windowPtr->isOpen() ) { input->ResetKeyStates(); sf::Event event; while( windowPtr->pollEvent( event ) ) { if(event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape) { windowPtr->close(); } input->PollInput( event ); } float delta = fpsTimer->GetMilliseconds(); fpsTimer->Restart(); PhysicsManager::Instance()->Step(); Camera::Instance()->Update( delta ); ObjectManager::Instance()->UpdateObjects( delta ); DrawManager::Instance()->Render(); } }
void MapTileLayer::tileRegion(const Coordinate& a, const Coordinate& b, int lod) { MapLoader* loader = MapViewLayer::Context.Loader; auto ai = loader->getTileIndex(a, lod); auto bi = loader->getTileIndex(b, lod); if(ai == m_indexA && bi == m_indexB && m_lod == lod){ // don't rebuild map return; } removeAllChildren(); m_indexA = ai; m_indexB = bi; m_lod = lod; int tilesPending = _tileRegion(a, b, lod, true); if(tilesPending > 0) { _tileRegion(a, b, lod+1, false); } }
void ResourcesLoader::loadGameData() { MapLoader mapLoader; mapLoader.loadFromFile(); _resHolder->setData(mapLoader.getMapsData()); _resHolder->setData(mapLoader.loadSpecialMaps(), true); EnemiesLoader enemiesLoader(_errorHandler); enemiesLoader.loadFromFile(); _resHolder->setData(enemiesLoader.getEnemiesData()); _resHolder->setData(enemiesLoader.getSpecialEnemiesData(), true); WeaponsLoader weaponsLoader(_errorHandler); weaponsLoader.loadFromFile(); _resHolder->setData(weaponsLoader.getWeaponsData()); ArmoursLoader armoursLoader(_errorHandler); armoursLoader.loadFromFile(); _resHolder->setData(armoursLoader.getArmoursData()); ConsumablesLoader consumablesLoader(_errorHandler); consumablesLoader.loadFromFile(); _resHolder->setData(consumablesLoader.getConsumablesData()); }
void CoronaRenderer::defineMesh(mtco_MayaObject *obj) { MObject meshObject = obj->mobject; MStatus stat = MStatus::kSuccess; bool hasDisplacement = false; Corona::Abstract::Map *displacementMap = NULL; float displacementMin = 0.0f; float displacementMax = 0.01f; // I do it here for displacement mapping, maybe we should to another place getObjectShadingGroups(obj->dagPath, obj->perFaceAssignments, obj->shadingGroups); if( obj->shadingGroups.length() > 0) { MFnDependencyNode shadingGroup(obj->shadingGroups[0]); MString sgn = shadingGroup.name(); MObject displacementObj = getConnectedInNode(obj->shadingGroups[0], "displacementShader"); MString doo = getObjectName(displacementObj); if( (displacementObj != MObject::kNullObj) && (displacementObj.hasFn(MFn::kDisplacementShader))) { MObject displacementMapObj = getConnectedInNode(displacementObj, "displacement"); if( (displacementMapObj != MObject::kNullObj) && (displacementMapObj.hasFn(MFn::kFileTexture))) { MFnDependencyNode displacmentMapNode(displacementObj); getFloat("mtco_displacementMin", displacmentMapNode, displacementMin); getFloat("mtco_displacementMax", displacmentMapNode, displacementMax); MString fileTexturePath = getConnectedFileTexturePath(MString("displacement"), displacmentMapNode); if( fileTexturePath != "") { MapLoader loader; displacementMap = loader.loadBitmap(fileTexturePath.asChar()); hasDisplacement = true; } } } } MFnMesh meshFn(meshObject, &stat); CHECK_MSTATUS(stat); MItMeshPolygon faceIt(meshObject, &stat); CHECK_MSTATUS(stat); MPointArray points; meshFn.getPoints(points); MFloatVectorArray normals; meshFn.getNormals( normals, MSpace::kWorld ); MFloatArray uArray, vArray; meshFn.getUVs(uArray, vArray); //logger.debug(MString("Translating mesh object ") + meshFn.name().asChar()); MString meshFullName = makeGoodString(meshFn.fullPathName()); Corona::TriangleData td; Corona::IGeometryGroup* geom = NULL; geom = this->context.scene->addGeomGroup(); obj->geom = geom; for( uint vtxId = 0; vtxId < points.length(); vtxId++) { geom->getVertices().push(Corona::Pos(points[vtxId].x,points[vtxId].y,points[vtxId].z)); } for( uint nId = 0; nId < normals.length(); nId++) { geom->getNormals().push(Corona::Dir(normals[nId].x,normals[nId].y,normals[nId].z)); } for( uint tId = 0; tId < uArray.length(); tId++) { geom->getMapCoords().push(Corona::Pos(uArray[tId],vArray[tId],0.0f)); geom->getMapCoordIndices().push(geom->getMapCoordIndices().size()); } MPointArray triPoints; MIntArray triVtxIds; MIntArray faceVtxIds; MIntArray faceNormalIds; for(faceIt.reset(); !faceIt.isDone(); faceIt.next()) { int faceId = faceIt.index(); int numTris; faceIt.numTriangles(numTris); faceIt.getVertices(faceVtxIds); MIntArray faceUVIndices; faceNormalIds.clear(); for( uint vtxId = 0; vtxId < faceVtxIds.length(); vtxId++) { faceNormalIds.append(faceIt.normalIndex(vtxId)); int uvIndex; faceIt.getUVIndex(vtxId, uvIndex); faceUVIndices.append(uvIndex); } for( int triId = 0; triId < numTris; triId++) { int faceRelIds[3]; faceIt.getTriangle(triId, triPoints, triVtxIds); for( uint triVtxId = 0; triVtxId < 3; triVtxId++) { for(uint faceVtxId = 0; faceVtxId < faceVtxIds.length(); faceVtxId++) { if( faceVtxIds[faceVtxId] == triVtxIds[triVtxId]) { faceRelIds[triVtxId] = faceVtxId; } } } uint vtxId0 = faceVtxIds[faceRelIds[0]]; uint vtxId1 = faceVtxIds[faceRelIds[1]]; uint vtxId2 = faceVtxIds[faceRelIds[2]]; uint normalId0 = faceNormalIds[faceRelIds[0]]; uint normalId1 = faceNormalIds[faceRelIds[1]]; uint normalId2 = faceNormalIds[faceRelIds[2]]; uint uvId0 = faceUVIndices[faceRelIds[0]]; uint uvId1 = faceUVIndices[faceRelIds[1]]; uint uvId2 = faceUVIndices[faceRelIds[2]]; if( hasDisplacement ) { Corona::DisplacedTriangleData tri; tri.displacement.map = displacementMap; MPoint p0 = points[vtxId0]; MPoint p1 = points[vtxId1]; MPoint p2 = points[vtxId2]; tri.v[0] = Corona::AnimatedPos(Corona::Pos(p0.x, p0.y, p0.z)); tri.v[1] = Corona::AnimatedPos(Corona::Pos(p1.x, p1.y, p1.z)); tri.v[2] = Corona::AnimatedPos(Corona::Pos(p2.x, p2.y, p2.z)); MVector n0 = normals[normalId0]; MVector n1 = normals[normalId1]; MVector n2 = normals[normalId2]; Corona::Dir dir0(n0.x, n0.y, n0.z); Corona::Dir dir1(n1.x, n1.y, n1.z); Corona::Dir dir2(n2.x, n2.y, n2.z); tri.n[0] = Corona::AnimatedDir(dir0); tri.n[1] = Corona::AnimatedDir(dir1); tri.n[2] = Corona::AnimatedDir(dir2); Corona::Pos uv0(uArray[uvId0],vArray[uvId0],0.0); Corona::Pos uv1(uArray[uvId1],vArray[uvId1],0.0); Corona::Pos uv2(uArray[uvId2],vArray[uvId2],0.0); Corona::StaticArray<Corona::Pos, 3> uvp; uvp[0] = uv0; uvp[1] = uv1; uvp[2] = uv2; tri.t.push(uvp); tri.materialId = 0; tri.displacement.min = displacementMin; tri.displacement.max = displacementMax; geom->addPrimitive(tri); }else{ Corona::TriangleData tri; tri.v = Corona::AnimatedPosI3(vtxId0, vtxId1, vtxId2); tri.n = Corona::AnimatedDirI3(normalId0, normalId1, normalId2); tri.t[0] = uvId0; tri.t[1] = uvId1; tri.t[2] = uvId2; tri.materialId = 0; geom->addPrimitive(tri); } } } }
CBSSearch::CBSSearch(MapLoader& ml, const AgentsLoader& al, const EgraphReader& egr, double e_w, bool tweak_g_val) { cols = ml.cols; num_expanded = 0; num_of_types = al.num_of_types; nums_of_agents = al.nums_of_agents; map_size = ml.rows*ml.cols; solution_found = false; solution_cost = -1; current_makespan = 0; max_makespan = 1.5 * (ml.rows + ml.cols); start_locations = vector<vector<int>>(num_of_types); goal_locations = vector<vector<int>>(num_of_types); search_engines = vector < SingleTypeSearch* >(num_of_types); for (int t = 0; t < num_of_types; t++) { vector<int> init_locs_list(nums_of_agents[t]); vector<int> goal_locs_list(nums_of_agents[t]); for (int i = 0; i < nums_of_agents[t]; i++) { int init_loc = ml.linearize_coordinate(al.initial_locations[t][i].first, al.initial_locations[t][i].second); int goal_loc = ml.linearize_coordinate(al.goal_locations[t][i].first, al.goal_locations[t][i].second); init_locs_list[i] = init_loc; goal_locs_list[i] = goal_loc; } start_locations[t] = init_locs_list; goal_locations[t] = goal_locs_list; //determine starting makespan for (int i = 0; i < nums_of_agents[t]; i++) { int min_distance_to_a_goal = map_size; //vector<int> distances = ml.getDistancesToAllLocations(init_locs_list[i]); //ComputeHeuristic ch(goal_locs_list[i], ml.get_map(), ml.rows*ml.cols, ml.actions_offset, e_w, &egr); for (int j = 0; j < nums_of_agents[t]; j++) { //int manhattan_distance = distances[goal_locs_list[j]]; int manhattan_distance = abs(ml.row_coordinate(init_locs_list[i]) - ml.row_coordinate(goal_locs_list[j])) + abs(ml.col_coordinate(init_locs_list[i]) - ml.col_coordinate(goal_locs_list[j])); min_distance_to_a_goal = (manhattan_distance < min_distance_to_a_goal) ? manhattan_distance : min_distance_to_a_goal; } current_makespan = (current_makespan < min_distance_to_a_goal) ? min_distance_to_a_goal : current_makespan; } } // initialize paths_found_initially (contain all individual optimal policies) paths_found_initially.resize(num_of_types); bool all_agents_found_path = true; std::clock_t start; start = std::clock(); for (int t = 0; t < num_of_types; t++) { paths = paths_found_initially; search_engines[t] = new SingleTypeSearch(t, start_locations[t], goal_locations[t], NULL, ml.get_map(), ml.rows, ml.cols, ml.actions_offset, &egr, e_w, tweak_g_val); for (this->current_makespan; this->current_makespan <= max_makespan; this->current_makespan++) { if (search_engines[t]->findPath(paths, current_makespan) == true) { paths_found_initially[t] = new vector<vector<int> >(*search_engines[t]->getPath()); break; } } if (current_makespan == max_makespan) { all_agents_found_path = false; } } pre_time = (std::clock() - start); if (all_agents_found_path == false) { cout << "NO SOLUTION EXISTS"; } paths = paths_found_initially; dummy_start = new CBSNode(); dummy_start->type_id = -1; dummy_start->g_val = current_makespan;//compute_g_val(num_of_types); dummy_start->open_handle = heap.push(dummy_start); current_makespan = dummy_start->g_val; }
void InGameState::restart() { if (m_io) { m_victoryTime = 0; m_defeatTime = 0; m_toneOutTimer = 0; m_io->clearSpriteInfos(); for (unsigned int i = 0; i < m_gameObjects.size(); i++) { if( m_gameObjects[i] != NULL) { delete m_gameObjects[i]; m_gameObjects[i] = NULL; } } m_gameObjects.clear(); m_monsters.clear(); m_bombs.clear(); if (m_tileMap) { delete m_tileMap; m_tileMap = NULL; } if (m_gui) { delete m_gui; m_gui = NULL; } m_tileMap = 0; MapLoader mapParser; int tscore = 0; if (m_stats) { tscore = m_stats->getTotalScore(); delete m_stats; } m_stats = new GameStats(m_parent->getNewTimerInstance(), m_maps[m_currentMap].parTime, tscore); stringstream ss; ss << m_currentMap; string mapString = "../Maps/" + m_maps[m_currentMap].filename; mapParser.parseMap(mapString, m_io, m_stats, m_factory); m_tileMap = mapParser.getTileMap(); m_gameObjects = mapParser.getGameObjects(); m_avatar = mapParser.getAvatar(); m_monsters = mapParser.getMonsters(); m_traps = mapParser.getTraps(); m_gui = mapParser.getGUI(); m_paused = false; if (m_avatar) m_startTile = m_avatar->getCurrentTile(); m_io->fadeSceneToBlack(1.0f); } m_parent->stopMainTimer(); m_parent->startMainTimer(); //Ugly - Should be corrected. Leave for now if (m_backgroundMusic) { m_backgroundMusic->deleted = true; } m_backgroundMusic = new SoundInfo(); m_backgroundMusic->id = "../Sounds/Music/" + m_maps[m_currentMap].backgroundMusic; m_backgroundMusic->play = true; m_backgroundMusic->volume = 0; m_io->addSong(m_backgroundMusic); //Add sound effects if (m_clock) { m_clock->deleted = true; } m_clock = m_factory->CreateSoundInfo("../Sounds/bell.wav", 100); if (m_defeat) { m_defeat->deleted = true; } m_defeat = m_factory->CreateSoundInfo("../Sounds/failure.wav", 100); if (m_victory) { m_victory->deleted = true; } m_victory = m_factory->CreateSoundInfo("../Sounds/victory.wav", 100); //ANTON FIX! //Makes sure the game starts at time 0 m_stats->getGameTimer()->stop(); m_stats->getGameTimer()->start(); }
void OgitorWorld::Load(const MapLoader &loader, const Register::Table &worldEntityDef) { const auto &hive = loader.GetStaticEntitiesHive(); for(auto it : hive) { Register::Table *dict = static_cast<Register::Table *>(it.second); try { const String_t &name = dict->GetString("name"); const String_t &type = dict->GetString("typename"); if(this->LoadGlobalObject(type, *dict)) continue; //make sure this is not duplicated StaticObjectsMap_t::iterator objIt = m_mapStaticObjects.lower_bound(name); if((objIt != m_mapStaticObjects.end()) && !(m_mapStaticObjects.key_comp()(name, objIt->first))) { LogMakeStream() << "[OgitorWorld::Load] Static object " << name << " is duplicated\n"; continue; } StaticObject_s object; if(!this->LoadStaticObject(object, name, type, *dict)) continue; m_mapStaticObjects.insert(objIt, std::make_pair(name, object)); } catch(Exception &ex) { LogMakeStream() << "[OgitorWorld::Load] Exception loading static object: " << ex.what(); } } //time to fix parents for(StaticObjectsMap_t::value_type &pair : m_mapStaticObjects) { StaticObject_s &object = pair.second; if(StringIsBlank(object.strParent) || (object.strParent.compare("SceneManager") == 0)) continue; StaticObjectsMap_t::iterator it = m_mapStaticObjects.find(object.strParent); if(it == m_mapStaticObjects.end()) { LogMakeStream() << "[OgitorWorld::Load] Static object " << pair.first << " without parent " << object.strParent << "\n"; continue; } if(object.m_pclSceneNode->getParent()) object.m_pclSceneNode->getParent()->removeChild(object.m_pclSceneNode); it->second.m_pclSceneNode->addChild(object.m_pclSceneNode); } //configure physics Physics::Manager &physicsManager = Physics::Manager::GetInstance(); Physics::CollisionTag staticCollisionTag = Physics::Settings::CreateStaticWorldCollisionTag(); for(auto &pair : m_mapStaticObjects) { StaticObject_s &object = pair.second; if(object.m_pclEntity == NULL) continue; //Why using those _ functions: http://89.151.96.106/forums/viewtopic.php?f=22&t=62386 //http://www.ogre3d.org/forums/viewtopic.php?p=221113 //http://www.ogre3d.org/tikiwiki/-SceneNode Engine::Math::Transform transform( object.m_pclSceneNode->_getDerivedPosition(), object.m_pclSceneNode->_getDerivedOrientation() ); BaseOgreWorld::CreateStaticObjectRigidBody(object, transform, object.m_pclSceneNode->_getDerivedScale(), staticCollisionTag); } if(m_pclTerrainGroupTable != NULL) { this->LoadTerrainGroup(*m_pclTerrainGroupTable); m_pclTerrainGroupTable = NULL; } if(m_pclTerrainPageTable != NULL) { this->LoadTerrainPage(*m_pclTerrainPageTable, worldEntityDef); m_pclTerrainPageTable = NULL; } }
void Scene::load(bool loadGameObjects) { CoreSubsystem::getSingleton().getWorld()->clearScene(); MapLoader* loader = new MapLoader(); loader->loadScene(mMaps, loadGameObjects); }
ECBSSearch::ECBSSearch(const MapLoader& ml, const AgentsLoader& al, const EgraphReader& egr, double e_w, double f_w, bool tweak_g_val) { focal_w = f_w; HL_num_expanded = 0; HL_num_generated = 0; LL_num_expanded = 0; LL_num_generated = 0; num_of_agents = al.num_of_agents; map_size = ml.rows*ml.cols; solution_found = false; solution_cost = -1; ll_min_f_vals = vector <double> (num_of_agents); paths_costs = vector <double> (num_of_agents); ll_min_f_vals_found_initially = vector <double> (num_of_agents); paths_costs_found_initially = vector <double> (num_of_agents); search_engines = vector < SingleAgentECBS* > (num_of_agents); for (int i = 0; i < num_of_agents; i++) { int init_loc = ml.linearize_coordinate((al.initial_locations[i]).first, (al.initial_locations[i]).second); int goal_loc = ml.linearize_coordinate((al.goal_locations[i]).first, (al.goal_locations[i]).second); ComputeHeuristic ch(goal_loc, ml.get_map(), ml.rows*ml.cols, ml.moves_offset, ml.actions_offset, e_w, &egr); search_engines[i] = new SingleAgentECBS(init_loc, goal_loc, MapLoader::orientation_t::FACE_EAST, ch.getHVals(), ml.get_map(), ml.rows*ml.cols, ml.moves_offset, ml.actions_offset, &egr, e_w, tweak_g_val); } // initialize allNodes_table (hash table) empty_node = new ECBSNode(); empty_node->time_generated = -2; empty_node->agent_id = -2; deleted_node = new ECBSNode(); deleted_node->time_generated = -3; deleted_node->agent_id = -3; allNodes_table.set_empty_key(empty_node); allNodes_table.set_deleted_key(deleted_node); // initialize all initial paths to NULL paths_found_initially.resize(num_of_agents); for (int ag=0; ag < num_of_agents; ag++) paths_found_initially[ag] = NULL; // initialize paths_found_initially for (int i = 0; i < num_of_agents; i++) { // cout << "Computing initial path for agent " << i << endl; fflush(stdout); paths = paths_found_initially; size_t max_plan_len = getPathsMaxLength(); bool* res_table = new bool[map_size * max_plan_len](); // initialized to false updateReservationTable(res_table, max_plan_len, i); // cout << "*** CALCULATING INIT PATH FOR AGENT " << i << ". Reservation Table[MAP_SIZE x MAX_PLAN_LEN]: " << endl; // printResTable(res_table, max_plan_len); if ( search_engines[i]->findPath ( f_w, NULL, res_table, max_plan_len ) == false) cout << "NO SOLUTION EXISTS"; paths_found_initially[i] = new vector<pathEntry> (*(search_engines[i]->getPath())); ll_min_f_vals_found_initially[i] = search_engines[i]->min_f_val; paths_costs_found_initially[i] = search_engines[i]->path_cost; LL_num_expanded += search_engines[i]->num_expanded; LL_num_generated += search_engines[i]->num_generated; delete[] res_table; // cout << endl; } paths = paths_found_initially; ll_min_f_vals = ll_min_f_vals_found_initially; paths_costs = paths_costs_found_initially; // generate dummy start and update data structures dummy_start = new ECBSNode(); dummy_start->agent_id = -1; dummy_start->g_val = 0; for (int i = 0; i < num_of_agents; i++) dummy_start->g_val += paths_costs[i]; dummy_start->ll_min_f_val = 0; dummy_start->sum_min_f_vals = compute_hl_lower_bound(); dummy_start->open_handle = open_list.push(dummy_start); dummy_start->focal_handle = focal_list.push(dummy_start); HL_num_generated++; dummy_start->time_generated = HL_num_generated; allNodes_table[dummy_start] = dummy_start; min_sum_f_vals = dummy_start->sum_min_f_vals; focal_list_threshold = focal_w * dummy_start->sum_min_f_vals; // cout << "Paths in START (high-level) node:" << endl; // printPaths(); // cout << "SUM-MIN-F-VALS: " << dummy_start->sum_min_f_vals << endl; }
int main() { init(); map = mapLoader.FileMapper(); int x = mapLoader.GetX(); int y = mapLoader.GetY(); char** mapArr = mapLoader.GetMap(map, x, y); char** safetyCopy = mapLoader.GetMap(map, x, y); ostringstream os; Image title = Image("title.txt"); renderEngine.Render(title); getch(); system("cls"); mapArr[playerX][playerY] = '0'; renderEngine.DrawMap(mapArr, x, y); while(true) { mapArr[playerX][playerY] = safetyCopy[playerX][playerY]; switch(getch()) { case 'w': if(playerCanMove('w', safetyCopy[playerX][playerY-1])) { playerY--; } break; case 's': if(playerCanMove('s', safetyCopy[playerX][playerY+1])) { playerY++; } break; case 'a': if(playerCanMove('a', safetyCopy[playerX-1][playerY])) { playerX--; } break; case 'd': if(playerCanMove('d', safetyCopy[playerX+1][playerY])) { playerX++; } break; case '0': return EXIT_SUCCESS; break; default: break; } switch(command.Interact(safetyCopy[playerX][playerY])) { case 'a': pos++; os.str(""); os << "next" << pos << ".txt"; mapLoader.SetPath(os.str()); renderEngine.SetEnvironment("fields"); map = mapLoader.FileMapper(); x = mapLoader.GetX(); y = mapLoader.GetY(); playerX = 20; playerY = 2; mapArr = mapLoader.GetMap(map, x, y); safetyCopy = mapLoader.GetMap(map, x, y); break; case 'p': pos--; os.str(""); os << "next" << pos << ".txt"; mapLoader.SetPath(os.str()); renderEngine.SetEnvironment("house"); map = mapLoader.FileMapper(); x = mapLoader.GetX(); y = mapLoader.GetY(); playerX = 8; playerY = 12; mapArr = mapLoader.GetMap(map, x, y); safetyCopy = mapLoader.GetMap(map, x, y); break; case 'n': break; } system("cls"); mapArr[playerX][playerY] = '0'; renderEngine.DrawMap(mapArr, x, y); } return EXIT_SUCCESS; }