Пример #1
0
int main()
{
	setRandSeed();

	std::vector<std::string> studentNames =
	{
		"俳持1", "俳持2", "俳持3", "俳持4",
		"俳持5", "俳持6", "俳持7", "俳持8"
	};

	int studentSize = studentNames.size();
	int team = 1;

	while (!studentNames.empty())
	{
		int index = rand() % studentSize;

		if (studentSize % 2 == 0)
		{
			std::cout << "----- team" << team << "-----" << std::endl;
			team++;
		}

		std::cout << studentNames[index] << std::endl;
		studentNames.erase(studentNames.begin() + index);
		studentSize--;
	}

	pressEnterToExit();
	return 0;
}
Пример #2
0
int main(int argc, char** argv)
{
	_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
	setRandSeed(12345679);
	if (argc != 2)
		exitWithUsageError();
	if (strcmp(argv[1], "-t") == 0)
	{
		std::cerr << "Testing basic graph activity.\n";
		testBasic();
		std::cerr << "Testing Tarjan`s algorithm.\n";
		testTarjan();
		std::cerr << "Testing 2-SAT solution.\n";
		test2SAT();
		return 0;
	}

	std::unique_ptr<IDigraph> graph = prepareInput(argv[1]);
	int variables = graph->getNumberOfVertices() / 2;
	std::vector<int> result = solve2SAT(graph, variables);
	if (result[0] == -1) std::cout << "No solution." << std::endl;
	else
	{
		std::cout << "Solution is:" << std::endl;
		for (int i = 0; i < variables; i++)
			std::cout << i + 1 << " -- " << (result[i] == 0 ? "false" : "true") << std::endl;
	}
	return 0;
}
Пример #3
0
terrain* terrain_genDiamondSquare(int size, float range, float factor, const char* texturePath) {
    terrain* ret = (terrain*)malloc(sizeof(terrain));
    ret->model = NULL;
    ret->heightMap = (float**)malloc(sizeof(float) * size * size);
    ret->size = size;

	*((float*)ret->heightMap + 0 * size + 0) = 0;
	*((float*)ret->heightMap + 0 * size + (size-1)) = 0;
	*((float*)ret->heightMap + (size-1) * size + 0) = 0;
	*((float*)ret->heightMap + (size-1) * size + (size-1)) = 0;

    setRandSeed();
	int i, j, k;

	// NOTE: this is not correct, square values are not using the value of adjacent diamonds correctly
	for (i = size - 1; i >= 2; i /= 2, range *= pow(2,-factor)) {
		for (j = 0; j < size - 1; j += i) {
			for (k = 0; k < size - 1; k += i) {
				float a = access_2df_array(ret->heightMap, size, j, k);
				float b = access_2df_array(ret->heightMap, size, j, k+i);
				float c = access_2df_array(ret->heightMap, size, j+i, k);
				float d = access_2df_array(ret->heightMap, size, j+i, k+i);

				float e = access_2df_array(ret->heightMap, size, j + i/2, k + i/2) = (a + b + c + d)/4.0f + randomValue(range);

				access_2df_array(ret->heightMap, size, j, k+i/2) = (access_2df_array(ret->heightMap, size, j, k) + access_2df_array(ret->heightMap, size, j, k+i) + e)/3.0f + randomValue(range);
				access_2df_array(ret->heightMap, size, j+i/2, k) = (access_2df_array(ret->heightMap, size, j, k) + access_2df_array(ret->heightMap, size, j+i, k) + e)/3.0f + randomValue(range);
				access_2df_array(ret->heightMap, size, j+i, k+i/2) = (access_2df_array(ret->heightMap, size, j+i, k) + access_2df_array(ret->heightMap, size, j+i, k+i) + e)/3.0f + randomValue(range);
				access_2df_array(ret->heightMap, size, j+i/2, k+i) = (access_2df_array(ret->heightMap, size, j, k+i) + access_2df_array(ret->heightMap, size, j+i, k+i) + e)/3.0f + randomValue(range);
			}
		}
	}

	ret->model = (mesh*)malloc(sizeof(mesh));
		
	mesh_init(ret->model);
	ret->model->indexCount = 6 * (ret->size - 1) * (ret->size - 1);
	ret->model->vertexCount = ret->size * ret->size;

	GLfloat *vertices = (GLfloat*)malloc(sizeof(GLfloat) * ret->model->vertexCount * 8);
	GLuint *indices = (GLuint*)malloc(sizeof(GLuint) * ret->model->indexCount);

	for (i = 0, k = 0; i < ret->size; i++)
		for (j = 0; j < ret->size; j++, k+=8) {
			vertices[k] = (-ret->size/2 + i);
			vertices[k+1] = access_2df_array(ret->heightMap, ret->size, i, j);
			vertices[k+2] = (ret->size/2 - j);
			vertices[k+3] = (float)((int)j % 2);
			vertices[k+4] = (float)((int)i % 2);
			vertices[k+5] = 0;
			vertices[k+6] = 1;
			vertices[k+7] = 0;
			// TODO: fix normals
		}

	for (i = 0, k = 0; i < ret->size - 1; i++) {
		for (j = 0; j < ret->size - 1; j++, k+=6) {
			indices[k] = i + ret->size*j;
			indices[k+1] = i + ret->size + 1 + ret->size*j;
			indices[k+2] = i + 1 + ret->size*j;
		}
	}

	for (i = 0, k = 3; i < ret->size - 1; i++) {
		for (j = 0; j < ret->size - 1; j++, k+=6) {
			indices[k] = i + ret->size*j;
			indices[k+1] = ret->size + i + ret->size*j;
			indices[k+2] = i + ret->size + 1 + ret->size*j;
		}
	}

	mesh_loadToVAO(ret->model, vertices, indices);
	mesh_textureFromFile(ret->model, texturePath);

	free(indices);
	free(vertices);

    return ret;
}