Пример #1
0
Matrix DataCollector::readFromText(string filename, vector<string> &assetNames)
{
	//filename = "Stocks.txt";

	unsigned int numAssets, numDates;

	countStuff(filename, numAssets, numDates);

	//cout << numAssets << "\t" << numDates << endl;

	Matrix priceMatrix(numDates, numAssets);

	ifstream infile; //input file stream object
	infile.open(filename);

	if (!infile) {
		cerr << "Bad input! Can't open " << filename << endl;
		exit(1);
	}

	unsigned int i = 0;
	unsigned int j = 0;

	string line;
	string token;
	double price;
	getline(infile, line, '\n');
	stringstream ss(line);
	while (getline(ss, token, ' '))
	{
		//cout << token << "\t";
		assetNames.push_back(token);
	}
	//cout << endl;
	while (!infile.eof())
	{
		getline(infile, line, '\n');
		stringstream ss(line);
		j = 0;
		while (getline(ss, token, ','))
		{
			price = stod(token);
			priceMatrix(i, j) = price;
			j++;
			//cout << price << "\t";
		}
		//cout << endl;
		i++;
	}
	//cout << priceMatrix << endl;
	return priceMatrix;
}
Пример #2
0
int MapGenerator::placeSomethingOnTheMap() {
    Message("place_intermediate_world_thing()\n");
    int placed_puzzles = 0;
    int travel_count = 0, puzzles_count = 0, blockades_count = 0;;
    countStuff(&travel_count, &blockades_count, &puzzles_count);
    
    int total_puzzle_count = puzzles_count / 4 + win_rand() % (puzzles_count / 5 + 1) - blockades_count - travel_count - 2;
    if ( total_puzzle_count < 4 ) total_puzzle_count = 4;
    
    placed_puzzles = choosePuzzlesBehindBlockades();
    placed_puzzles = choosePuzzlesOnIslands(placed_puzzles);
    placed_puzzles = chooseAdditionalPuzzles(placed_puzzles, total_puzzle_count);
    
    makeSureLastPuzzleIsNotTooCloseToCenter(placed_puzzles);
    
    return placed_puzzles;
}