示例#1
0
void GameInterface::processHits (GLint hits, GLuint buffer[]) 
{
	GLuint *ptr = buffer;
	GLuint mindepth = 0xFFFFFFFF;
	GLuint *selected=NULL;
	GLuint nselected;

	// iterate over the list of hits, and choosing the one closer to the viewer (lower depth)
	for (int i=0;i<hits;i++) {
		int num = *ptr; ptr++;
		GLuint z1 = *ptr; ptr++;
		ptr++;
		if (z1 < mindepth && num>0) {
			mindepth = z1;
			selected = ptr;
			nselected=num;
		}
		for (int j=0; j < num; j++) 
			ptr++;
	}

	// if there were hits, the one selected is in "selected", and it consist of nselected "names" (integer ID's)
	if (selected!=NULL)
	{
		// this should be replaced by code handling the picked object's ID's (stored in "selected"), 
		// possibly invoking a method on the scene class and passing "selected" and "nselected"
		printf("Picked ID's: ");
		for (unsigned int i=0; i<nselected; i++)
		{
			printf("%d ",selected[i]);
		}
		printf("\n");
		vector<int> play;
		play.push_back(selected[0]);
		play.push_back(selected[1]);
		play.push_back(selected[2]);
		makePlay(play);
	}
	else
		printf("Nothing selected while picking \n");	
}
示例#2
0
int solveMineSweeper(Board boardh, Board boardv) {
	// Initialize groups
	groupListArrayNumber = 0;
	for (int x = 0; x < boardv.width; x++) {
		for (int y = 0; y < boardv.height; y++) {
			char cell = get(boardv, x,y);
			
			if (cell == MINE || cell == UNKNOWN) {	// Not a number!
				continue;
			}
			
			Group newGroup = buildGroup(boardv, x, y);
			if (newGroup.size != 0) {
				addToList(newGroup);
			}
		}
	}

	while (1) {
		
MAYBE(printf("creation of groups complete\n"));
		for (int i = 0; i < groupListArrayNumber; i++) {
			for (int j = i + 1; j < groupListArrayNumber; j++) {
MAYBE(printf("G%d[%d/%d]; G%d[%d/%d]; GLAN: %d)\n", i, groupList[i].mines, groupList[i].size, j, groupList[j].mines, groupList[j].size, groupListArrayNumber));
				if (groupList[i].size == groupList[j].size	// Groups are
				&& containedIn(groupList[i], groupList[j])) {	// the same
					removeFromList(j);
MAYBE(printf("remove\n"));
				} 
				else if (containedIn(groupList[i], groupList[j])) { 
					//remove elements of i from j
MAYBE(printf("SUB: G%d - G%d\n", j, i));
MAYBE(printGroup(groupList[j]));
MAYBE(printGroup(groupList[i]));
					groupList[j] = subtract(groupList[j],groupList[i]);
MAYBE(printGroup(groupList[j]));
				}
				else if (containedIn(groupList[j], groupList[i])) {
					//remove elements of j from i
					
MAYBE(printf("SUB: G%d - G%d\n", i, j));
MAYBE(printGroup(groupList[i]));
MAYBE(printGroup(groupList[j]));
					groupList[i] = subtract(groupList[i],groupList[j]);
MAYBE(printGroup(groupList[i]));
				}
				else if (intersectSolver(groupList[i], groupList[j])>=0) {
					int x = intersectSolver(groupList[i], groupList[j]);
MAYBE(printf("FIRST: %d, SECOND: %d\n", groupList[i].mines - (groupList[i].size - x), groupList[j].mines - (groupList[j].size - x)));


MAYBE(printf("\nINTERCEPTION: mine:%d\n", x));
MAYBE(printGroup(groupList[i]));
MAYBE(printGroup(groupList[j]));


					Group a, b;
					a = subtract(groupList[i], groupList[j]);	// LEFT
					b = subtract(groupList[i], a);  //isto vai dar merda!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
					b.mines = x;
					addToList(b);
					groupList[i] = subtract(groupList[i], b);
					groupList[j] = subtract(groupList[j], b);
				}
				else {
					continue;
				}
				
				i = -1;	// Reset outer for
				break;
			}
		}

MAYBE(printf("cleaning of groups complete\n"));
		bool stallAlert = 0;
		int forMax = groupListArrayNumber;
		for (int i = 0; i < forMax; i++){
MAYBE(printf("for i:%d forMax:%d\n",i,forMax));
			int result = NEUTRAL;
			if (groupList[i].mines == 0) {
				for (int  j =0; j < groupList[i].size; j++) {
					makePlay(boardh, boardv, groupList[i].positions[j][0], groupList[i].positions[j][1], CLEAR);
MAYBE(printf("Marking Clear (%d,%d)\n", groupList[i].positions[j][0], groupList[i].positions[j][1]));
				}
			} 
			else if (groupList[i].mines == groupList[i].size) {
				for (int  j = 0; j < groupList[i].size; j++) {
					makePlay(boardh, boardv, groupList[i].positions[j][0], groupList[i].positions[j][1], MINE);
MAYBE(printf("Marking Mine (%d,%d)\n", groupList[i].positions[j][0], groupList[i].positions[j][1]));
					
				}
				removeFromList(i);
				i--;
				forMax--;
			} 
			else {
				continue;
			}
			
			// Delete group
			stallAlert = 1;
			// maybe break;
		}
		
		for (int i = 0; i < forMax; i++){
			int result = NEUTRAL;
			if (groupList[i].mines == 0) {
				for (int  j =0; j < groupList[i].size; j++) {
					Group newGroup = buildGroup(boardv, groupList[i].positions[j][0], groupList[i].positions[j][1]); 
					if (newGroup.size > 0) {
						addToList(newGroup);
					}
				}
				
				// Delete group
				removeFromList(i);
				i--;
				forMax--;
			} 
		}
		
		printBoard(boardv);
		
		if (stallAlert == 0) {
			printBoard(boardv);
			printBoard(boardh);
			printf("Stalled!\n glan: %d \n", groupListArrayNumber);
			
			for (int i = 0; i < groupListArrayNumber; i++) {
				printGroup(groupList[i]);
			}
			return NEUTRAL;
		}
	}
}
示例#3
0
void GameInterface::processHits (GLint hits, GLuint buffer[]) 
{
	GLuint *ptr = buffer;
	GLuint mindepth = 0xFFFFFFFF;
	GLuint *selected=NULL;
	GLuint nselected;

	// iterate over the list of hits, and choosing the one closer to the viewer (lower depth)
	for (int i=0;i<hits;i++) {
		int num = *ptr; ptr++;
		GLuint z1 = *ptr; ptr++;
		ptr++;
		if (z1 < mindepth && num>0) {
			mindepth = z1;
			selected = ptr;
			nselected=num;
		}
		for (int j=0; j < num; j++) 
			ptr++;
	}

	// if there were hits, the one selected is in "selected", and it consist of nselected "names" (integer ID's)
	if (selected!=NULL)
	{
		for (unsigned int i=0; i<nselected; i++)
		{
			printf("%d ",selected[i]);
		}
		printf("\n");

		if(selected[0]==0)
		{
			if(selected[1]==1)
			{
				((XMLScene*) scene)->data->gameMode=1;
			}

			else if(selected[1]==2)
			{
				((XMLScene*) scene)->data->gameMode=2;
				((XMLScene*) scene)->data->difficulties[0]=1;
			}

			else if(selected[1]==3)
			{
				((XMLScene*) scene)->data->gameMode=2;
				((XMLScene*) scene)->data->difficulties[0]=2;
			}

			else if(selected[1]==4)
			{
				((XMLScene*) scene)->data->gameMode=3;
				((XMLScene*) scene)->data->difficulties[0]=1;
				((XMLScene*) scene)->data->difficulties[1]=1;
			}

			else if(selected[1]==5)
			{
				((XMLScene*) scene)->data->gameMode=3;
				((XMLScene*) scene)->data->difficulties[0]=1;
				((XMLScene*) scene)->data->difficulties[1]=2;
			}

			else if(selected[1]==6)
			{
				((XMLScene*) scene)->data->gameMode=3;
				((XMLScene*) scene)->data->difficulties[0]=2;
				((XMLScene*) scene)->data->difficulties[1]=2;
			}

			else if(selected[1]==7)
				exit(0);

			((XMLScene*) scene)->isMenu=false;
			((XMLScene*) scene)->gameTime=0;
			((XMLScene*) scene)->lastTime=0;
			((XMLScene*) scene)->data->start();
		}
		// this should be replaced by code handling the picked object's ID's (stored in "selected"), 
		// possibly invoking a method on the scene class and passing "selected" and "nselected"
		else
		{
		printf("Picked ID's: ");
		vector<int> play;
		play.push_back(selected[0]);
		play.push_back(selected[1]);
		play.push_back(selected[2]);
		makePlay(play);
		}
	}
	else
		printf("Nothing selected while picking \n");	
}