Example #1
0
std::set<std::string> getAvailableGameIds()
{
	std::set<std::string> gameids;
	std::set<std::string> gamespaths;
	gamespaths.insert(porting::path_share + DIR_DELIM + "games");
	gamespaths.insert(porting::path_user + DIR_DELIM + "games");

	Strfnd search_paths(getSubgamePathEnv());

	while (!search_paths.at_end())
		gamespaths.insert(search_paths.next(PATH_DELIM));

	for (std::set<std::string>::const_iterator i = gamespaths.begin();
			i != gamespaths.end(); ++i){
		std::vector<fs::DirListNode> dirlist = fs::GetDirListing(*i);
		for(u32 j=0; j<dirlist.size(); j++){
			if(!dirlist[j].dir)
				continue;
			// If configuration file is not found or broken, ignore game
			Settings conf;
			if(!getGameConfig(*i + DIR_DELIM + dirlist[j].name, conf))
				continue;
			// Add it to result
			const char *ends[] = {"_game", NULL};
			std::string shorter = removeStringEnd(dirlist[j].name, ends);
			if(shorter != "")
				gameids.insert(shorter);
			else
				gameids.insert(dirlist[j].name);
		}
	}
	return gameids;
}
Example #2
0
SubgameSpec findSubgame(const std::string &id)
{
	if(id == "")
		return SubgameSpec();
	std::string share = porting::path_share;
	std::string user = porting::path_user;
	std::vector<GameFindPath> find_paths;

	Strfnd search_paths(getSubgamePathEnv());

	while (!search_paths.at_end()) {
		std::string path = search_paths.next(PATH_DELIM);
		find_paths.push_back(GameFindPath(
				path + DIR_DELIM + id, false));
		find_paths.push_back(GameFindPath(
				path + DIR_DELIM + id + "_game", false));
	}

	find_paths.push_back(GameFindPath(
			user + DIR_DELIM + "games" + DIR_DELIM + id + "_game", true));
	find_paths.push_back(GameFindPath(
			user + DIR_DELIM + "games" + DIR_DELIM + id, true));
	find_paths.push_back(GameFindPath(
			share + DIR_DELIM + "games" + DIR_DELIM + id + "_game", false));
	find_paths.push_back(GameFindPath(
			share + DIR_DELIM + "games" + DIR_DELIM + id, false));
	// Find game directory
	std::string game_path;
	bool user_game = true; // Game is in user's directory
	for(u32 i=0; i<find_paths.size(); i++){
		const std::string &try_path = find_paths[i].path;
		if(fs::PathExists(try_path)){
			game_path = try_path;
			user_game = find_paths[i].user_specific;
			break;
		}
	}
	if(game_path == "")
		return SubgameSpec();
	std::string gamemod_path = game_path + DIR_DELIM + "files";
	// Find mod directories
	std::set<std::string> mods_paths;
	if(!user_game)
		mods_paths.insert(share + DIR_DELIM + "files");
	if(user != share || user_game)
		mods_paths.insert(user + DIR_DELIM + "files");
	std::string game_name = getGameName(game_path);
	if(game_name == "")
		game_name = id;
	std::string menuicon_path;
#ifndef SERVER
	menuicon_path = getImagePath(game_path + DIR_DELIM + "menu" + DIR_DELIM + "icon.png");
#endif
	return SubgameSpec(id, game_path, gamemod_path, mods_paths, game_name,
			menuicon_path);
}
Example #3
0
/*
* Tries to find a valid path for r1 to follow. 
* Uses depth-first search with iterative deepening
* */
void get_moves(path *r1, path *r2) {
	int depth = 2;	
	vector<int> *path_x = new vector<int>();
	vector<int> *path_y = new vector<int>();
	printf("(%d, %d)\n", r1->curr_x, r1->curr_y);
    
	r1->moves_x->clear();
	r1->moves_y->clear();
	r1->value = 0;
	
	// come up with a sequence of moves and put them into r1->moves_x and r1->moves_y
	getMap(); // make sure the map data is fresh before we start searching
	while (r1->value == 0 && depth <= 35) {
	    for (int i = 0; i < 5; i++) {
			for (int j = 0; j < 7; j++) {
				maze_visited[i][j] = 1;
			}
	    }
	    
	    // Start searching for moves, depth increases with each iteration
		search_paths(r1, path_x, path_y, 0, 0, 0, depth++, r1->curr_x, r1->curr_y, r2->curr_x, r2->curr_y);
	    
		// Print path information
		printf("Path length: %d\n", r1->moves_x->size());
		printf("Depth: %d\n", depth - 1);
		for (int k = 0; k < r1->moves_x->size(); k++) {
			int x = r1->moves_x->at(k);
			int y = r1->moves_y->at(k);
			printf("(%d %d) -> ", x, y); 
		}
	    
		printf("%d \n", r1->value);
	    
		for (int r = 0; r < 5; r++) {
			for (int c = 0; c < 7; c++) {
				printf("%d\t", maze[r][c]);
			}
			printf("\n");
		}
		printf("\n");
		printf("\n");
		printf("\n");
		//exit(0);
	}
	
	// If we didn't find any valid path, give up
	if (r1->moves_x->size() == 0) {
		printf("No path was found. Exiting.\n");
		exit(0);
	}
}
Example #4
0
std::vector<WorldSpec> getAvailableWorlds()
{
	std::vector<WorldSpec> worlds;
	std::set<std::string> worldspaths;

	Strfnd search_paths(getWorldPathEnv());

	while (!search_paths.at_end())
		worldspaths.insert(search_paths.next(PATH_DELIM));

	worldspaths.insert(porting::path_user + DIR_DELIM + "worlds");
	infostream << "Searching worlds..." << std::endl;
	for (std::set<std::string>::const_iterator i = worldspaths.begin();
			i != worldspaths.end(); ++i) {
		infostream << "  In " << (*i) << ": " <<std::endl;
		std::vector<fs::DirListNode> dirvector = fs::GetDirListing(*i);
		for(u32 j=0; j<dirvector.size(); j++){
			if(!dirvector[j].dir)
				continue;
			std::string fullpath = *i + DIR_DELIM + dirvector[j].name;
			std::string name = dirvector[j].name;
			// Just allow filling in the gameid always for now
			bool can_be_legacy = true;
			std::string gameid = getWorldGameId(fullpath, can_be_legacy);
			WorldSpec spec(fullpath, name, gameid);
			if(!spec.isValid()){
				infostream<<"(invalid: "<<name<<") ";
			} else {
				infostream<<name<<" ";
				worlds.push_back(spec);
			}
		}
		infostream<<std::endl;
	}
	// Check old world location
	do{
		std::string fullpath = porting::path_user + DIR_DELIM + "world";
		if(!fs::PathExists(fullpath))
			break;
		std::string name = "Old World";
		std::string gameid = getWorldGameId(fullpath, true);
		WorldSpec spec(fullpath, name, gameid);
		infostream<<"Old world found."<<std::endl;
		worlds.push_back(spec);
	}while(0);
	infostream<<worlds.size()<<" found."<<std::endl;
	return worlds;
}
Example #5
0
int main(int argc, char **argv)
{
    struct multibfs bfs;

    int size[5] = {4, 4, 4, 4, 2};
    if (argc > 5)
    {
        size[0] = atoi(argv[1]);
        size[1] = atoi(argv[2]);
        size[2] = atoi(argv[3]);
        size[3] = atoi(argv[4]);
        size[4] = atoi(argv[5]);
    }

    bfs.num_dims = 5;
    bfs.num_nodes = 1;
    bfs.diameter = 0;

    for (int i = 0; i < bfs.num_dims; i++) {
        bfs.size[i] = size[i];
        bfs.num_nodes *= size[i];
        bfs.diameter += size[i];
    }

    bfs.neighbors = optiq_topology_get_all_nodes_neighbors(bfs.num_dims, size);

    std::vector<std::pair<int, std::vector<int> > > source_dests;
    source_dests.clear();

    //gen_source_dests_test(source_dests, bfs);
    optiq_cesm_gen_ice_cpl(source_dests, bfs.num_nodes);

    std::vector<struct path *> complete_paths;
    complete_paths.clear();

    search_paths(source_dests, bfs, complete_paths);

    optiq_path_print_paths(complete_paths);   

    return 0;
}
Example #6
0
std::set<std::string> getAvailableGameIds()
{
	std::set<std::string> gameids;
	std::set<std::string> gamespaths;
	gamespaths.insert(porting::path_share + DIR_DELIM + "games");
	gamespaths.insert(porting::path_user + DIR_DELIM + "games");

	Strfnd search_paths(getSubgamePathEnv());

	while (!search_paths.at_end())
		gamespaths.insert(search_paths.next(PATH_DELIM));

	for (const std::string &gamespath : gamespaths) {
		std::vector<fs::DirListNode> dirlist = fs::GetDirListing(gamespath);
		for (const fs::DirListNode &dln : dirlist) {
			if (!dln.dir)
				continue;

			// If configuration file is not found or broken, ignore game
			Settings conf;
			std::string conf_path = gamespath + DIR_DELIM + dln.name +
						DIR_DELIM + "game.conf";
			if (!conf.readConfigFile(conf_path.c_str()))
				continue;

			// Add it to result
			const char *ends[] = {"_game", NULL};
			std::string shorter = removeStringEnd(dln.name, ends);
			if (!shorter.empty())
				gameids.insert(shorter);
			else
				gameids.insert(dln.name);
		}
	}
	return gameids;
}
Example #7
0
/*
* Considers all paths of a given depth for r1 to follow (and picks the best one), 
* using recursive depth-first search
* */
void search_paths(path *r1, vector<int> *path_x, vector<int> *path_y,
	int value, int bonus, int depth,
	int max_depth, int pos_x, int pos_y, int r2x, int r2y) {
	
	if (pos_x >= 0 && pos_y >= 0 && pos_x < 7 && pos_y < 5 
		&& maze[pos_y][pos_x] >= 0 
		/*&& !(pos_x == r2x && pos_y == r2y) */
		&& maze_visited[pos_y][pos_x]) {
	
		maze_visited[pos_y][pos_x] = 0;
		int last = path_x->size() - 1;
		
		// Give a bonus for traveling in a straight line because it is faster
		if (last >= 2) {
			int delta_x1 = path_x->at(last) - path_x->at(last - 1);
			int delta_x2 = path_x->at(last - 1) - path_x->at(last - 2);
			int delta_y1 = path_y->at(last) - path_y->at(last - 1);
			int delta_y2 = path_y->at(last - 1) - path_y->at(last - 2);
	    
			if (delta_x1 == delta_x2 && delta_y1 == delta_y2) {
				bonus += 2; //2;
			}
		}
		// Reduce bonus for first and last rows
		if(pos_y == 0 || pos_y == 4)
			bonus += -4;
		value += maze[pos_y][pos_x];
		depth++;
    
		// If we reach the maximum depth, see if the path is better than the previous best one
		if (depth > max_depth) {
			
			// Update the best path if the new one is better
			if (value > 0 && value + bonus > r1->value) {
				r1->moves_x->clear();
				r1->moves_y->clear();
				r1->value = value + bonus;
		
				for (int i = 0; i < path_x->size(); i++) {
					r1->moves_x->push_back(path_x->at(i));
					r1->moves_y->push_back(path_y->at(i));
				}
			}
		}
		// If we didn't reach max depth, keep searching
		else {
			// Search right
			path_x->push_back(pos_x + 1);
			path_y->push_back(pos_y);
			search_paths(r1, path_x, path_y, value, bonus, depth, max_depth, path_x->back(), path_y->back(), r2x, r2y);
			path_x->pop_back();
			//path_y->pop_back();
	    
			// Search left
			path_x->push_back(pos_x - 1);
			//path_y->push_back(pos_y);
			search_paths(r1, path_x, path_y, value, bonus, depth, max_depth, path_x->back(), path_y->back(), r2x, r2y);
			path_x->pop_back();
			path_y->pop_back();
	    
			// Search down
			path_x->push_back(pos_x);
			path_y->push_back(pos_y + 1);
			search_paths(r1, path_x, path_y, value, bonus, depth, max_depth, path_x->back(), path_y->back(), r2x, r2y);
			//path_x->pop_back();
			path_y->pop_back();
	    
			// Search up
			//path_x->push_back(pos_x);
			path_y->push_back(pos_y - 1);
			search_paths(r1, path_x, path_y, value, bonus, depth, max_depth, path_x->back(), path_y->back(), r2x, r2y);
			path_x->pop_back();
			path_y->pop_back();
		}
	}
}
Example #8
0
int
main(int argc, char **argv)
{
    char *altpath, **ep, *p, **parg;
    char *cleanenv[1];
    int ch, want_clear;
    int rtrn;

    altpath = NULL;
    want_clear = 0;
    while ((ch = getopt(argc, argv, "-iP:S:u:v")) != -1)
        switch(ch) {
        case '-':
        case 'i':
            want_clear = 1;
            break;
        case 'P':
            altpath = strdup(optarg);
            break;
        case 'S':
            /*
             * The -S option, for "split string on spaces, with
             * support for some simple substitutions"...
             */
            split_spaces(optarg, &optind, &argc, &argv);
            break;
        case 'u':
            if (env_verbosity)
                fprintf(stderr, "#env unset:\t%s\n", optarg);
            rtrn = unsetenv(optarg);
            if (rtrn == -1)
                err(EXIT_FAILURE, "unsetenv %s", optarg);
            break;
        case 'v':
            env_verbosity++;
            if (env_verbosity > 1)
                fprintf(stderr, "#env verbosity now at %d\n",
                        env_verbosity);
            break;
        case '?':
        default:
            usage();
        }
    if (want_clear) {
        environ = cleanenv;
        cleanenv[0] = NULL;
        if (env_verbosity)
            fprintf(stderr, "#env clearing environ\n");
    }
    for (argv += optind; *argv && (p = strchr(*argv, '=')); ++argv) {
        if (env_verbosity)
            fprintf(stderr, "#env setenv:\t%s\n", *argv);
        *p = '\0';
        rtrn = setenv(*argv, p + 1, 1);
        *p = '=';
        if (rtrn == -1)
            err(EXIT_FAILURE, "setenv %s", *argv);
    }
    if (*argv) {
        if (altpath)
            search_paths(altpath, argv);
        if (env_verbosity) {
            fprintf(stderr, "#env executing:\t%s\n", *argv);
            for (parg = argv, argc = 0; *parg; parg++, argc++)
                fprintf(stderr, "#env    arg[%d]=\t'%s'\n",
                        argc, *parg);
            if (env_verbosity > 1)
                sleep(1);
        }
        execvp(*argv, argv);
        err(errno == ENOENT ? 127 : 126, "%s", *argv);
    }
    for (ep = environ; *ep; ep++)
        (void)printf("%s\n", *ep);
    exit(0);
}
Example #9
0
SubgameSpec findSubgame(const std::string &id)
{
	if (id.empty())
		return SubgameSpec();
	std::string share = porting::path_share;
	std::string user = porting::path_user;

	// Get games install locations
	Strfnd search_paths(getSubgamePathEnv());

	// Get all possible paths fo game
	std::vector<GameFindPath> find_paths;
	while (!search_paths.at_end()) {
		std::string path = search_paths.next(PATH_DELIM);
		find_paths.emplace_back(path + DIR_DELIM + id, false);
		find_paths.emplace_back(path + DIR_DELIM + id + "_game", false);
	}
	find_paths.emplace_back(
			user + DIR_DELIM + "games" + DIR_DELIM + id + "_game", true);
	find_paths.emplace_back(user + DIR_DELIM + "games" + DIR_DELIM + id, true);
	find_paths.emplace_back(
			share + DIR_DELIM + "games" + DIR_DELIM + id + "_game", false);
	find_paths.emplace_back(share + DIR_DELIM + "games" + DIR_DELIM + id, false);

	// Find game directory
	std::string game_path;
	bool user_game = true; // Game is in user's directory
	for (const GameFindPath &find_path : find_paths) {
		const std::string &try_path = find_path.path;
		if (fs::PathExists(try_path)) {
			game_path = try_path;
			user_game = find_path.user_specific;
			break;
		}
	}

	if (game_path.empty())
		return SubgameSpec();

	std::string gamemod_path = game_path + DIR_DELIM + "mods";

	// Find mod directories
	std::set<std::string> mods_paths;
	if (!user_game)
		mods_paths.insert(share + DIR_DELIM + "mods");
	if (user != share || user_game)
		mods_paths.insert(user + DIR_DELIM + "mods");

	// Get meta
	std::string conf_path = game_path + DIR_DELIM + "game.conf";
	Settings conf;
	conf.readConfigFile(conf_path.c_str());

	std::string game_name;
	if (conf.exists("name"))
		game_name = conf.get("name");
	else
		game_name = id;

	std::string game_author;
	if (conf.exists("author"))
		game_author = conf.get("author");

	int game_release = 0;
	if (conf.exists("release"))
		game_release = conf.getS32("release");

	std::string menuicon_path;
#ifndef SERVER
	menuicon_path = getImagePath(
			game_path + DIR_DELIM + "menu" + DIR_DELIM + "icon.png");
#endif
	return SubgameSpec(id, game_path, gamemod_path, mods_paths, game_name,
			menuicon_path, game_author, game_release);
}