|
[x]
Posted via EE Mobile
|
||
Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again. |
||
| Question |
|
[x]
Attachment Details
|
||
|
[x]
The Solution Rating System
|
||
With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.
Your Input Matters If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support. Thank you! |
||
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: |
list<int> Level::planPathAStar(short currentX, short currentY, short goalX, short goalY, short debugMode)
{
list<int> path; // Final path to be constructed
list<graphNode> open; // List of open nodes to be explored
list<graphNode> closed; // List of closed nodes which have been explored
int goalIndex; // Index of the goal node
int currentIndex; // Index of the current node
graphNode currentNode; // Current graph node
goalIndex = index(goalX, goalY); // Set goal node index
currentIndex = index(currentX, currentY); // Set current node index
currentNode.index = currentIndex; // Set the index of the currentgraph node
currentNode.parentIndex = -1; // Set the parent of the current node to NULL
currentNode.score(0.0, currentX, currentY, goalX, goalY); // Score the current node
open.push_back(currentNode); // Put the current node on the open list
while(currentIndex != goalIndex)
{
open.sort(); // Sort the list of open node by list quality
currentNode = open.front(); // Take the node that scored best on the open list
open.pop_front(); // Take it off the open list
closed.push_back(currentNode); // Add that node to the closed list
currentIndex = currentNode.index; // Set the current index
// Look in the adjacency matrix for connections to other nodes
for(int otherIndex = 0; otherIndex < nNodes; otherIndex++)
{
// Check for a connection
if(adjacencyMatrix[currentIndex][otherIndex])
{
// If there is a connection
list<graphNode>::iterator graphListIter;
bool onClosed = false;
bool onOpen = false;
// Find out whether it's on the closed list
for(graphListIter = closed.begin();graphListIter != closed.end();++graphListIter)
{
if((*graphListIter).index == otherIndex)
{
// Found on closed list
onClosed = true;
// Check g value
// If the current g value is less than that of the node found on the closed list
// then update that nodes parent to the current node
if(currentNode.g + 1.0 < (*graphListIter).g)
{
(*graphListIter).parentIndex = currentIndex;
}
}
}
if(!onClosed)
{
// Find out whether it's on the open list list
for(graphListIter = open.begin();graphListIter != open.end();++graphListIter)
{
if((*graphListIter).index == otherIndex)
{
// Found on closed list
onOpen = true;
// Check g values
// If the current g value is less than that of the node found on the closed list
// then update that nodes parent to the current node
if(currentNode.g + 1.0 < (*graphListIter).g)
{
(*graphListIter).parentIndex = currentIndex;
}
}
}
}
if(!onClosed && !onOpen)
{
// It its not on open or closed
graphNode tmpNode;
// Set the parent node to the curretn node
tmpNode.parentIndex = currentIndex;
// Set the node index to other index
tmpNode.index = otherIndex;
// Find the X and Y posiiton of that node
inverseIndex(otherIndex,¤tX, ¤tY);
// Score the node
tmpNode.score(currentNode.g, currentX, currentY, goalX, goalY);
// Add it to the open list
open.push_back(tmpNode);
}
}
}
}
// Reconstruct the path
// Start with goal node working backwards towarsd the first node
// We know that we're at the first node because it has a parent of -1
int parent;
list<graphNode>::iterator graphListIter;
currentNode = closed.back(); // Set the current node to goal node
parent = currentNode.parentIndex; // Set parent to be the parent of the current node
path.push_front(currentIndex); // Add the current node the the start of the path
closed.pop_back(); // Remove the curretn node from the closed list
//Now work backwards throught the closed list reconstructing the path
for(graphListIter = closed.end(), graphListIter--;graphListIter != closed.begin();--graphListIter)
{
currentNode = *graphListIter;
if(currentNode.index == parent) // Fount the node
{
// Add it to the path
path.push_front(parent);
// Set parent to be this nodes parent
parent = currentNode.parentIndex;
// Remove this node from the closed list
closed.erase(graphListIter);
// Start working backward throguht the cloased list again from the end
graphListIter = closed.end();
}
}
return path;
}
|
Advertisement
| Hall of Fame |