void EnemyData::countRoute(short routeIndex, vector<CCPoint> *pathData) { CCPoint tpoint = EnemyData::data->getTerminalPoint(); CCPoint endPoint; endPoint.x = tpoint.x; endPoint.y = tpoint.y; list<PathNode*> openList; list<PathNode*> closeList; //0.\u00F8\u2019\u00B5\u0192 1.\u2018\u2044close\u00BF\u00D4\u221A\u00CA 2.\u2018\u2044open\u00BF\u00D4\u221A\u00CA short closeData[mapCol][mapRow]; for (short i = 0; i < mapCol; ++i) { for (short j = 0; j < mapRow; ++j) { closeData[i][j] = 0; } } PathNode *panode = NULL; panode = new PathNode(routeStartPoint[routeIndex].x, routeStartPoint[routeIndex].y); panode->set(0, fabs(panode->col - endPoint.x) + fabs(panode->row - endPoint.y)); panode->setFather(NULL); openList.push_back(panode); short col = 0; short row = 0; //\u2248\u2013\u2202\u0153\u00A0\u00AB\u2211\u00D2\u2019\u201C\u00B5\u03A9\u00AC\u2211\u00E6\u2202\u00A1\u00C0 bool is = false; //\u25CA\u00D3\u00F7\u2019\u00B5\u201E PathNode *end = NULL; while (!openList.empty()) { PathNode *node = openList.front(); openList.pop_front(); closeList.push_back(node); closeData[node->col][node->row] = 1; col = node->col; row = node->row; PathNode *node1; if (row - 1 >= 0) //\u25CA\u00DB\u00B1\uFB02 { if (EnemyData::data->mapData[col][row - 1] != 1 && closeData[col][row - 1] != 1) { if (closeData[col][row - 1] != 2) //\u2248\u2013\u2202\u0153\u00A0\u00AB\u2211\u00D2\u2018\u2044Open\u00BF\u00D4\u221A\u00CA { node1 = new PathNode(col, row - 1); node1->set(node->G + 1, fabs(node1->col - endPoint.x) + fabs(node1->row - endPoint.y)); //\u2026\u00CB\u00F7\u221AFGH node1->setFather(node); //\u2026\u00CB\u00F7\u221A\u220F\u220F\u03A9\u2044\u00B5\u201E\u0152\u00AA\u00F7\u221A openList.push_back(node1); closeData[col][row - 1] = 2; if (node1->col == endPoint.x && node1->row == endPoint.y) { is = true; end = node1; break; } } } } if (row + 1 < mapRow) //\u25CA\u00DB\u00B1\uFB02 { if (EnemyData::data->mapData[col][row + 1] != 1 && closeData[col][row + 1] != 1) { if (closeData[col][row + 1] != 2) //\u2248\u2013\u2202\u0153\u00A0\u00AB\u2211\u00D2\u2018\u2044Open\u00BF\u00D4\u221A\u00CA { node1 = new PathNode(col, row + 1); node1->set(node->G + 1, fabs(node1->col - endPoint.x) + fabs(node1->row - endPoint.y)); //\u2026\u00CB\u00F7\u221AFGH node1->setFather(node); //\u2026\u00CB\u00F7\u221A\u220F\u220F\u03A9\u2044\u00B5\u201E\u0152\u00AA\u00F7\u221A openList.push_back(node1); closeData[col][row + 1] = 2; if (node1->col == endPoint.x && node1->row == endPoint.y) { is = true; end = node1; break; } } } } if (col - 1 >= 0) //\u2026\u0153\u00B1\uFB02 { if (EnemyData::data->mapData[col - 1][row] != 1 && closeData[col - 1][row] != 1) { if (closeData[col - 1][row] != 2) { node1 = new PathNode(col - 1, row); node1->set(node->G + 1, fabs(node1->col - endPoint.x) + fabs(node1->row - endPoint.y)); //\u2026\u00CB\u00F7\u221AFGH node1->setFather(node); //\u2026\u00CB\u00F7\u221A\u220F\u220F\u03A9\u2044\u00B5\u201E\u0152\u00AA\u00F7\u221A openList.push_back(node1); closeData[col - 1][row] = 2; if (node1->col == endPoint.x && node1->row == endPoint.y) { is = true; end = node1; break; } } } } if (col + 1 < mapCol) //\u0153\u00AC\u00B1\uFB02 { if (EnemyData::data->mapData[col + 1][row] != 1 && closeData[col + 1][row] != 1) { if (closeData[col + 1][row] != 2) { node1 = new PathNode(col + 1, row); node1->set(node->G + 1, fabs(node1->col - endPoint.x) + fabs(node1->row - endPoint.y)); //\u2026\u00CB\u00F7\u221AFGH node1->setFather(node); //\u2026\u00CB\u00F7\u221A\u220F\u220F\u03A9\u2044\u00B5\u201E\u0152\u00AA\u00F7\u221A openList.push_back(node1); closeData[col + 1][row] = 2; if (node1->col == endPoint.x && node1->row == endPoint.y) { is = true; end = node1; break; } } } } openList.sort(Cmpare()); } pathData->push_back(ccp(end->col, end->row)); while (true) { if (end->father == NULL) { break; } pathData->push_back(ccp(end->father->col, end->father->row)); end = end->father; } while (!openList.empty()) { PathNode * pa = openList.front(); delete pa; openList.pop_front(); } while (!closeList.empty()) { PathNode *pa = closeList.front(); delete pa; closeList.pop_front(); } }