void Processor::setNode (DWORD node) { if (!isValidNode(node)) return; selectedNode=node; }
bool GAStar::searchPath() { m_open.clear(); m_close.clear(); m_best.clear(); this->insertNodeToOpen(m_start); int x[8] = {1,-1,0,0,-1,-1,1,1}; int y[8] = {0,0,1,-1,1,-1,1,-1}; int size = 0; if(m_searchMode == ASTAR_FOUR) { size = 4; } else if(m_searchMode == ASTAR_EIGHT) { size = 8; } bool bFind = false; while(1) { if(m_open.size() == 0) { break; } if(isEndNodeInOpen() == true) { bFind = true; break; } int currentIndex = this->deleteMinfIndexInOpen(); this->addNodeToClose(currentIndex); GAStarNode* parent = this->nodeAt(currentIndex); int currentX = currentIndex%m_width; int currentY = currentIndex/m_width; for(int k = 0; k < size; ++k) { int i = currentX + x[k]; int j = currentY + y[k]; int s = 1; if(isValidNode(i, j) == true) { GAStarNode* node = this->nodeAt(i, j); if(node->m_tag == ASTAR_OPEN) { if(node->m_g > parent->m_g + s) { node->m_parent = parent; node->m_g = parent->m_g + s; } } else if(node->m_tag == ASTAR_CLOSE) { if(parent->m_parent != node) { if(node->m_g > parent->m_g + s) { //may not use node->m_parent = parent; node->m_g = parent->m_g + s; this->deleteNodeFromClose(j*m_width + i); this->insertNodeToOpen(j*m_width + i); } } } else if(node->m_tag == ASTAR_NONE) { node->m_parent = parent; node->m_g = parent->m_g + s; node->m_h = this->calculateHValue(i, j); this->insertNodeToOpen(j*m_width + i); } } } } if(bFind == true) { GAStarNode* node = this->nodeAt(m_end); while(1) { m_best.push_front(node->m_index); if(node->m_parent == 0) { break; } else { node = node->m_parent; } } } return bFind; }