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