当前位置: 首页>>代码示例>>C++>>正文


C++ Puzzle::canMoveDown方法代码示例

本文整理汇总了C++中Puzzle::canMoveDown方法的典型用法代码示例。如果您正苦于以下问题:C++ Puzzle::canMoveDown方法的具体用法?C++ Puzzle::canMoveDown怎么用?C++ Puzzle::canMoveDown使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Puzzle的用法示例。


在下文中一共展示了Puzzle::canMoveDown方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: progressiveDeepeningSearch

string progressiveDeepeningSearch(string const initialState, string const goalState, int &numberOfStateExpansions, int maxDepth){
	string path;
	int i=0;
	int c=0;
	int len;
	string strState;
	stack<Puzzle *> Q;
	Puzzle *state;
	Puzzle *nextState;
	state = new Puzzle(initialState, goalState);
	strState=state->toString();
	AddNode(A,strState);
	while(i<500000){
		   i++;	//RLDU   
			if(state->canMoveRight()){
				nextState = state->moveRight();
				if(Search(A,nextState->toString())==false&&nextState->getDepth()<=maxDepth){
				Q.push(nextState);
				AddNode(A,nextState->toString());
				}
			 }
			if(state->canMoveLeft()){
				nextState = state->moveLeft();
				if(Search(A,nextState->toString())==false&&nextState->getDepth()<=maxDepth){
				Q.push(nextState);
				AddNode(A,nextState->toString());
				}
			 }
			if(state->canMoveDown()){
				nextState = state->moveDown();
				if(Search(A,nextState->toString())==false&&nextState->getDepth()<=maxDepth){
				Q.push(nextState);
				AddNode(A,nextState->toString());
				}
			 }
			if(state->canMoveUp()){
				nextState = state->moveUp();
				if(Search(A,nextState->toString())==false&&nextState->getDepth()<=maxDepth){
				Q.push(nextState);
				AddNode(A,nextState->toString());
				}
			 }

		if(Q.empty()){
			 cout<<"no solution"<<endl;
			 break;
		}
	 	 state=Q.top();
	    Q.pop();
		if(state->goalMatch()){
			 len=state->getPathLength();
			 cout<<"have solution and length is : "<<len<<endl;
			 break;
	   }
   }
	path=state->getPath();
	return path;
}
开发者ID:Jinpeiqi,项目名称:Searching-Algorithms,代码行数:58,代码来源:algorithm.cpp

示例2: depthFirstSearch

string depthFirstSearch(string const initialState, string const goalState, int &numberOfStateExpansions){
	string path;
	int i=0;
	string strState;
	stack<Puzzle *> Q;
	Puzzle *state;
	Puzzle *nextState;
	state = new Puzzle(initialState, goalState);
	strState=state->toString();
	AddNode(A,strState);
	while(true){
			i++;	//UDLR

		if(state->canMoveDown()){
			nextState = state->moveDown();
			if(Search(A,nextState->toString())==false){
			Q.push(nextState);
			AddNode(A,nextState->toString());
			}
		 }
		if(state->canMoveRight()){
			nextState = state->moveRight();
			if(Search(A,nextState->toString())==false){
			Q.push(nextState);
			AddNode(A,nextState->toString());
			}
		 }
		if(state->canMoveUp()){
			nextState = state->moveUp();
			if(Search(A,nextState->toString())==false){
			Q.push(nextState);
			AddNode(A,nextState->toString());
			}
		 }
		if(state->canMoveLeft()){
			nextState = state->moveLeft();
			if(Search(A,nextState->toString())==false){
			Q.push(nextState);
			AddNode(A,nextState->toString());
			}
		 }
		 state=Q.top();
	    Q.pop();
		 if(state->goalMatch()){
	    break;
	    }
   }
	path=state->getPath();
	return path;
}
开发者ID:Jinpeiqi,项目名称:Searching-Algorithms,代码行数:50,代码来源:algorithm.cpp

示例3: A7

string A7(string const initialState, string const goalState, int &numberOfStateExpansions, int maxDepth){
	//A* Search with the Strict Expanded List, Heuristic = Sum of Manhattan Distance
	string path;
	int i=0;
	int c=0;
	int len;
	string strState;
	queue<Puzzle *> Q;	//queue
	queue<Puzzle *> Q2;
	Puzzle *state;
	Puzzle *nextState;
	state = new Puzzle(initialState, goalState);
	state->updateHCost(manhattanDistance);
	state->updateFCost();
	strState=state->toString();
	AddNode(A,strState);//Expanded List
	while(i<500000){
		   i++;	//UDLR
			if(state->canMoveUp()){
				nextState = state->moveUp();
				nextState->updateHCost(manhattanDistance);
				nextState->updateFCost();
				if(Search(A,nextState->toString())==false&&nextState->getDepth()<=maxDepth){
				Q.push(nextState);
				//AddNode(A,nextState->toString());
				}
			 }
			if(state->canMoveDown()){
				nextState = state->moveDown();
				nextState->updateHCost(manhattanDistance);
				nextState->updateFCost();
				if(Search(A,nextState->toString())==false&&nextState->getDepth()<=maxDepth){
				Q.push(nextState);
				//AddNode(A,nextState->toString());
				}
			 }
			if(state->canMoveLeft()){
				nextState = state->moveLeft();
				nextState->updateHCost(manhattanDistance);
				nextState->updateFCost();
				if(Search(A,nextState->toString())==false&&nextState->getDepth()<=maxDepth){
				Q.push(nextState);
				//AddNode(A,nextState->toString());
				}
			 }
			if(state->canMoveRight()){
				nextState = state->moveRight();
				nextState->updateHCost(manhattanDistance);
				nextState->updateFCost();
				if(Search(A,nextState->toString())==false&&nextState->getDepth()<=maxDepth){
				Q.push(nextState);
				//AddNode(A,nextState->toString());
				}
			 }
		if(Q.empty()){
			 cout<<"no solution"<<endl;
			 break;
		}
		state=Q.front();
		while(!Q.empty()){
			if(Q.front()->getFCost()<=state->getFCost()){
				state=Q.front();
			}
		Q2.push(Q.front());
		Q.pop();
		}
		while(!Q2.empty()){
			if(Q2.front()!=state){
				Q.push(Q2.front());
				Q2.pop();
			}else{
				Q2.pop();
			}
		}
		AddNode(A,state->toString());
	 	 //state=Q.front();
	    //Q.pop();
		if(state->goalMatch()){
			 len=state->getPathLength();
			 cout<<"have solution and length is : "<<len<<endl;
			 break;
	   }
   }
	path=state->getPath();
	return path;
}
开发者ID:Jinpeiqi,项目名称:Searching-Algorithms,代码行数:86,代码来源:algorithm.cpp


注:本文中的Puzzle::canMoveDown方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。