Что я должен изменить в этом коде, чтобы отобразить точку каждого узла на маршруте?

В MonoDroid / Xamarin.Android вы можете сделать:

 var resourceId = Resources.GetIdentifier("icon", "drawable", PackageName);

Но поскольку GetIdentifier не рекомендуется в Android - вы можете использовать Reflection следующим образом:

 var resourceId = (int)typeof(Resource.Drawable).GetField("icon").GetValue(null);

где Я предлагаю поставить try / catch или проверить строки, которые вы передаете.

0
задан Jean 2 March 2019 в 07:12
поделиться

1 ответ

Проще всего использовать std :: stringstream для такого рода вещей. Я добавил его в рассматриваемый цикл:

#include <sstream>

и:

while (!pq[pqi].empty())
    {
        // get the current node w/ the highest priority
        // from the list of open nodes
        n0 = new node(pq[pqi].top().getxPos(), pq[pqi].top().getyPos(),
            pq[pqi].top().getLevel(), pq[pqi].top().getPriority());

        x = n0->getxPos(); y = n0->getyPos();

        pq[pqi].pop(); // remove the node from the open list
        open_nodes_map[x][y] = 0;
        // mark it on the closed nodes map
        closed_nodes_map[x][y] = 1;

        // quit searching when the goal state is reached
        //if((*n0).estimate(xFinish, yFinish) == 0)
        if (x == xFinish && y == yFinish)
        {
            // generate the path from finish to start
            // by following the directions
            std::stringstream sstr;

            string path = "";
            while (!(x == xStart && y == yStart))
            {
                j = dir_map[x][y];
                c = '0' + (j + dir / 2) % dir;
                sstr << (j + dir / 2) % dir << ",";
                path = c + path;
                x += dx[j];
                y += dy[j];
            }

            // garbage collection
            delete n0;
            // empty the leftover nodes
            while (!pq[pqi].empty()) pq[pqi].pop();
            path = sstr.str();
            return path;
        }

Обратите внимание, что я просто назначил значение sstr для вашего path в конце петля. Я не вижу, какие цифры вы ищете, но это нечто другое.

0
ответ дан lakeweb 2 March 2019 в 07:12
поделиться
Другие вопросы по тегам:

Похожие вопросы: