#define OLC_PGE_APPLICATION #include "pixelGameEngine.h" #include "olcutils.h" using namespace olc; struct node{ char elevation='a'; bool visited=false; std::vectorconnections; int myDist=INFINITY; int storedDist=INFINITY; vi2d pos; node*parent=nullptr; node(char elevation){ this->elevation=elevation; }; }; vi2d playerPos={0,0}; vi2d endingPos={0,0}; std::vector>grid; node*startNode; node*endNode; int main() { std::ifstream file("testinput2"); while (file.good()){ std::string line; std::getline(file,line); std::vectorrow; if (line.length()>0){ for (int x=0;x0){ grid[y][x].connections.push_back(&grid[y][x-1]); } if (x0){ grid[y][x].connections.push_back(&grid[y-1][x]); } if (ysearchNodes; searchNodes.push_back(startNode); while (searchNodes.size()>0){ node*currentNode=searchNodes.front(); if (currentNode==startNode){ currentNode->myDist=pow(currentNode->pos.x-endNode->pos.x,2)+pow(currentNode->pos.y-endNode->pos.y,2); } currentNode->visited=true; if (currentNode->elevation=='S'){ currentNode->elevation='a'-1; } if (currentNode->elevation=='E'){ currentNode->elevation='z'+1; } for (int i=0;iconnections.size();i++){ node*neighbor=currentNode->connections[i]; if (neighbor==endNode){ //We can't go any higher. endNode->parent=currentNode; break; } if (neighbor->elevation-1<=currentNode->elevation){ if (neighbor->parent==nullptr||currentNode->myDiststoredDist){ neighbor->parent=currentNode; neighbor->storedDist=currentNode->myDist; neighbor->myDist=pow(neighbor->pos.x-endNode->pos.x,2)+pow(neighbor->pos.y-endNode->pos.y,2); if (!neighbor->visited){ searchNodes.push_back(neighbor); } } } } searchNodes.erase(searchNodes.begin()); } node*searchNode=endNode; int jumps=0; while (searchNode!=startNode){ std::cout<<"Node goes from "<pos<<" to "<parent->pos<parent; } std::cout<<"Shortest path is "<