コード例 #1
0
void SearchTree::calculateBranchAndDeadEnds(vector<GameState*> states){
		int j = 0;
		for(vector<GameState*>::iterator it = states.begin(); it != states.end(); it++){
				GameState* state = *it;
				j++;
				cout << j << "/" << states.size() << endl;
				GameState* cloneState = state->clone();
				for(int i = 0; i < state->solvedStep; i++){
					Node* node = new Node(cloneState->clone());

					vector<Node*> leaf = this->expand(node);
					state->nBranch += leaf.size();
					state->nNode += 1;
					state->nDeadEnd += node->state->nDeadEnd;
					for(vector<Node*>::iterator it2 = leaf.begin(); it2 != leaf.end(); it2++){
						Node* n = *it2;
						delete n;
						n = NULL;
					}


					delete node;
					node = NULL;


					int step = (state->solvedStep - (cloneState->countBoard() / state->crossOut));
					Grid a1 = state->solvedSequence[step][0];
					Grid a2 = state->solvedSequence[step][state->crossOut - 1];
					GameControl::getInstance()->operation(cloneState, a1, a2);
		
					
				}
				delete cloneState;
				cloneState = NULL;
		}
}
コード例 #2
0
ファイル: main.cpp プロジェクト: dorgonman/Cross_Block
void startGame(){

	float x, y;
	hge->Input_GetMousePos(&x, &y);

	GameControl::getInstance()->render();


	if(bdeath){
		//fnt->printf(250, 30, 0, "dead road"); // bug 因為用的是state裡的board的緣故,將該功能移到game control裡做
	}

	//取得消除線的起點
	static int lineBeginx = 0;
	static int lineBeginy = 0;
	if(hge->Input_KeyDown(HGEK_LBUTTON)){
		lineBeginx = x;
		lineBeginy = y;
	}
			
	//畫出消除線
	if(hge->Input_GetKeyState(HGEK_LBUTTON)){
			float mousex = 0;
			float mousey = 0;
			hge->Input_GetMousePos(&mousex, &mousey);

			if(mousex > 0 && mousey > 0 && mousex < 600 && mousey < 600){

				hge->Gfx_RenderLine(lineBeginx, lineBeginy , x, y, 0xFFFF00000);
			}
	}

	if(hge->Input_KeyUp(HGEK_LBUTTON)){
		Grid g1;
		Grid g2;
		g1.x = lineBeginx / SQUARE;
		g1.y = lineBeginy / SQUARE;
		g2.x = x / SQUARE;
		g2.y = y / SQUARE;
		if(GameControl::getInstance()->operation(g1, g2)){
				cout << "cross out" << endl;
				if(GameControl::getInstance()->isDead()){
					bdeath = true;
				}
				//GameControl::getInstance()->printTwoDimDynamicArray();
		}

	}


	GameState* state = GameControl::getInstance()->getCurrentState();
	if(hge->Input_KeyDown(HGEK_Z)){
		int step = (state->solvedStep - (state->countBoard() / state->crossOut));
		Grid a1 = state->solvedSequence[step][0];
		Grid a2 = state->solvedSequence[step][state->crossOut - 1];
		
		if(GameControl::getInstance()->operation(a1, a2)){
			cout << "cross out " << endl;
		}
	}

	

	fnt->printf(350, 5, HGETEXT_LEFT, "cross out: %d", state->crossOut);
	fnt->printf(350, 25, HGETEXT_LEFT, "solvedStep: %d", state->solvedStep);
	//fnt->printf(150, 555, HGETEXT_LEFT, "nDeadEnd: %.2f", state->nDeadEnd );
	//fnt->printf(5, 555, HGETEXT_LEFT, "nBranch:%.2f", state->nBranch );
	//fnt->printf(5, 580, HGETEXT_LEFT, "complexity:%f", state->complexity);

	fnt->printf(170, 25, HGETEXT_LEFT, "id:%d", state->id);
	timePast += hge->Timer_GetDelta();


	
}