diff --git a/C++ProjectTemplate b/C++ProjectTemplate index 36df910..ea43974 100755 Binary files a/C++ProjectTemplate and b/C++ProjectTemplate differ diff --git a/input b/input index 3005358..7395583 100644 --- a/input +++ b/input @@ -1,41 +1,41 @@ -abacccaaaacccccccccccaaaaaacccccaaaaaaccccaaacccccccccccccccccccccccccccccccccccccccccccaaaaa -abaaccaaaacccccccccccaaaaaaccccccaaaaaaaaaaaaaccccccccccccccccccccccccccccccccccccccccccaaaaa -abaaccaaaacccccccccccaaaaacccccaaaaaaaaaaaaaaaccccccccccccccccccccccccccccccccccccccccccaaaaa -abccccccccccccccccccccaaaaacccaaaaaaaaaaaaaaaacccccccccccccccccccccccccccaaaccccccccccccaaaaa -abccccccccccccccccccccaacaacccaaaaaaaaccaaaaaccccccccccccccccccccccccccccaaaccccccccccccaccaa -abcccccccccccccaacccaaaccccccaaaaaaaaaccaaaaaccccccccccccccccccccccccccccccacccccccccccccccca -abcccccccccccaaaaaaccaaaccacccccaaaaaaacccccccccccccccccccccccccciiiicccccccddddddccccccccccc -abcccccccccccaaaaaaccaaaaaaaccccaaaaaacccccaacccccccaaaccccccccciiiiiiiicccdddddddddacaaccccc -abccccccccccccaaaaaaaaaaaaacccccaaaaaaacaaaacccccccaaaacccccccchhiiiiiiiiicddddddddddaaaccccc -abcccccccccccaaaaaaaaaaaaaacccccccaaacccaaaaaacccccaaaaccccccchhhipppppiiiijjjjjjjddddaaccccc -abcccccccccccaaaaaaaaaaaaaaccccccccccccccaaaaaccccccaaaccccccchhhpppppppiijjjjjjjjjddeeaccccc -abcccccccccccccccccaaaaaaaacccccccccccccaaaaaccccccccccccccccchhppppppppppjjqqqjjjjjeeeaacccc -abccccccccccccccccccaaaaaaaacccccccccccccccaacccccccccccccccchhhpppuuuupppqqqqqqqjjjeeeaacccc -abcccccccccccccccccccaacccacccccccccccccccccccccccccccccccccchhhopuuuuuuppqqqqqqqjjjeeecccccc -abacccccccccccccaaacaaaccccccccccccccccccccccccccccaaccccccchhhhoouuuuuuuqvvvvvqqqjkeeecccccc -abaccccccccccccaaaaaacccccaaccccccccccccccccccccccaaaccccccchhhooouuuxxxuvvvvvvqqqkkeeecccccc -abaccccccccccccaaaaaacccaaaaaaccccccccccccccccccaaaaaaaaccchhhhooouuxxxxuvyyyvvqqqkkeeecccccc -abcccccccccccccaaaaacccaaaaaaaccccccccccccccccccaaaaaaaaccjjhooooouuxxxxyyyyyvvqqqkkeeecccccc -abccccccccccccccaaaaaacaaaaaaaccccccccaaaccccccccaaaaaaccjjjooootuuuxxxxyyyyyvvqqkkkeeecccccc -abccccccccccccccaaaaaaaaaaaaacccccccccaaaacccccccaaaaaacjjjooootttuxxxxxyyyyvvrrrkkkeeecccccc -SbccccccccccccccccccaaaaaaaaacccccccccaaaacccccccaaaaaacjjjoootttxxxEzzzzyyvvvrrrkkkfffcccccc -abcccccccccccaaacccccaaaaaaacaaaccccccaaaccccccccaaccaacjjjoootttxxxxxyyyyyyvvvrrkkkfffcccccc -abcccccccccaaaaaacccaaaaaacccaaacacccaacccccccccccccccccjjjoootttxxxxyxyyyyyywvvrrkkkfffccccc -abcccccccccaaaaaacccaaaaaaaaaaaaaaaccaaacaaacccccaacccccjjjnnnttttxxxxyyyyyyywwwrrkkkfffccccc -abcaacacccccaaaaacccaaacaaaaaaaaaaaccaaaaaaacccccaacaaacjjjnnnntttttxxyywwwwwwwwrrrlkfffccccc -abcaaaaccccaaaaacccccccccaacaaaaaaccccaaaaaacccccaaaaacccjjjnnnnnttttwwywwwwwwwrrrrllfffccccc -abaaaaaccccaaaaaccccccaaaaaccaaaaacaaaaaaaaccccaaaaaaccccjjjjinnnntttwwwwwsssrrrrrllllffccccc -abaaaaaaccccccccccccccaaaaacaaaaaacaaaaaaaaacccaaaaaaacccciiiiinnnntswwwwssssrrrrrlllfffccccc -abacaaaaccccccccccccccaaaaaacaaccccaaaaaaaaaaccccaaaaaaccccciiiinnnssswwsssssllllllllfffccccc -abccaaccccccccccccccccaaaaaaccccccccccaaacaaaccccaaccaacccccciiiinnsssssssmmllllllllfffaacccc -abccccccccccccccccccccaaaaaaccccccccccaaaccccccccaaccccccccccciiinnmsssssmmmmlllllgggffaacccc -abcccccccccccccccaccccccaaacccccccccccaaccccccccccccccccccccccciiimmmsssmmmmmgggggggggaaacccc -abcccccccccaaaaaaaaccccccccccccccccccccccccccccaaaaaccccccccccciiimmmmmmmmmgggggggggaaacccccc -abccccccccccaaaaaaccccccccccccccccccaacccccccccaaaaacccccccccccciiimmmmmmmhhggggcaaaaaaaccccc -abccccccccccaaaaaacccccccccccccccccaacccccccccaaaaaacccccccccccciihhmmmmhhhhgccccccccaacccccc -abccccaacaaaaaaaaaaccccccccccccccccaaaccccccccaaaaaaccccccccccccchhhhhhhhhhhaaccccccccccccccc -abccccaaaaaaaaaaaaaaccccccccccaaccaaaaccccccccaaaaaacccaaacccccccchhhhhhhhaaaaccccccccccccccc -abcccaaaaaaaaaaaaaaaccccccccaaaaaacaaaacacaccccaaaccccaaaacccccccccchhhhccccaaccccccccccaaaca -abcccaaaaaacacaaacccccccccccaaaaaaaaaaaaaaacccccccccccaaaacccccccccccaaaccccccccccccccccaaaaa -abcccccaaaacccaaaccccccccccaaaaaaaaaaaaaaaaccccccccccccaaacccccccccccaaacccccccccccccccccaaaa -abcccccaacccccaacccccccccccaaaaaaaaaaaaaccccccccccccccccccccccccccccccccccccccccccccccccaaaaa +abacccaaaacccccccccccaaaaaacccccadaaaaccccaaacccccccccccccccccccccccccccccccccccccccccccaaaaa +abaaccaaaacccccccccccaaaaaaccccccdaaaaaaaaaaaaccccccccccccccccccccccccccccccccccccccccccaaaaa +abaaccaaaacccccccccccaaaaacccccaadaaaaaaaaaaaaccccccccccccccccccccccccccccccccccccccccccaaaaa +abccccccccccccccccccccaaaaacccaaadaaaaaaaaaaaacccccccccccccccccccccccccccaaaccccccccccccaaaaa +abccccccccccccccccccccaacaacccaaadaaaaccaaaaaccccccccccccccccccccccccccccaaaccccccccccccaccaa +abcccccccccccccaacccaaaccccccaaaadaaaaccaaaaaccccccccccccccccccccccccccccccacccccccccccccccca +abcccccccccccaaaaaaccaaaccacccccadaaaaacccccccccccccccccccccccccciiiicccccccddddddccccccccccc +abcccccccccccaaaaaaccaaaaaaaccccadaaaacccccaacccccccaaaccccccccciiiiiiiicccdddddddddacaaccccc +abccccccccccccaaaaaaaaaaaaacccccadaaaaacaaaacccccccaaaacccccccchhiiiiiiiiicddddddddddaaaccccc +abcccccccccccaaaaaaaaaaaaaaccccccdaaacccaaaaaacccccaaaaccccccchhhipppppiiiijjjjjjjddddaaccccc +abcccccccccccaaaaaaaaaaaaaaccccccdcccccccaaaaaccccccaaaccccccchhhpppppppiijjjjjjjjjddeeaccccc +abcccccccccccccccccaaaaaaaaccccccdccccccaaaaaccccccccccccccccchhppppppppppjjqqqjjjjjeeeaacccc +abccccccccccccccccccaaaaaaaacccccdcccccccccaacccccccccccccccchhhpppuuuupppqqqqqqqjjjeeeaacccc +abcccccccccccccccccccaacccaccccccdccccccccccccccccccccccccccchhhopuuuuuuppqqqqqqqjjjeeecccccc +abacccccccccccccaaacaaaccccccccccdcccccccccccccccccaaccccccchhhhoouuuuuuuqvvvvvqqqjkeeecccccc +abaccccccccccccaaaaaacccccaacccccdccccccccccccccccaaaccccccchhhooouuuxxxuvvvvvvqqqkkeeecccccc +abaccccccccccccaaaaaacccaaaaaacccdccccccccccccccaaaaaaaaccchhhhooouuxxxxuvyyyvvqqqkkeeecccccc +abcccccccccccccaaaaacccaaaaaaacccdccccccccccccccaaaaaaaaccjjhooooouuxxxxyyyyyvvqqqkkeeecccccc +abccccccccccccccaaaaaacaaaaaaacccdccccaaaccccccccaaaaaaccjjjooootuuuxxxxyyyyyvvqqkkkeeecccccc +abccccccccccccccaaaaaaaaaaaaaccccdccccaaaacccccccaaaaaacjjjooootttuxxxxxyyyyvvrrrkkkeeecccccc +SbccccccccccccccccccaaaaaaaaaccccdccccaaaacccccccaaaaaacjjjoootttxxxEzzzzyyvvvrrrkkkfffcccccc +abcccccccccccaaacccccaaaaaaacaaacdccccaaaccccccccaaccaacjjjoootttxxxxxyyyyyyvvvrrkkkfffcccccc +abcccccccccaaaaaacccaaaaaacccaaacdcccaacccccccccccccccccjjjoootttxxxxyxyyyyyywvvrrkkkfffccccc +abcccccccccaaaaaacccaaaaaaaaaaaaadaccaaacaaacccccaacccccjjjnnnttttxxxxyyyyyyywwwrrkkkfffccccc +abcaacacccccaaaaacccaaacaaaaaaaaadaccaaaaaaacccccaacaaacjjjnnnntttttxxyywwwwwwwwrrrlkfffccccc +abcaaaaccccaaaaacccccccccaacaaaaadccccaaaaaacccccaaaaacccjjjnnnnnttttwwywwwwwwwrrrrllfffccccc +abaaaaaccccaaaaaccccccaaaaaccaaaadcaaaaaaaaccccaaaaaaccccjjjjinnnntttwwwwwsssrrrrrllllffccccc +abaaaaaaccccccccccccccaaaaacaaaaadcaaaaaaaaacccaaaaaaacccciiiiinnnntswwwwssssrrrrrlllfffccccc +abacaaaaccccccccccccccaaaaaacaaccdcaaaaaaaaaaccccaaaaaaccccciiiinnnssswwsssssllllllllfffccccc +abccaaccccccccccccccccaaaaaacccccdccccaaacaaaccccaaccaacccccciiiinnsssssssmmllllllllfffaacccc +abccccccccccccccccccccaaaaaacccccdccccaaaccccccccaaccccccccccciiinnmsssssmmmmlllllgggffaacccc +abcccccccccccccccaccccccaaaccccccdccccaaccccccccccccccccccccccciiimmmsssmmmmmgggggggggaaacccc +abcccccccccaaaaaaaaccccccccccccccdcccccccccccccaaaaaccccccccccciiimmmmmmmmmgggggggggaaacccccc +abccccccccccaaaaaacccccccccccccccdccaacccccccccaaaaacccccccccccciiimmmmmmmhhggggcaaaaaaaccccc +abccccccccccaaaaaacccccccccccccccdcaacccccccccaaaaaacccccccccccciihhmmmmhhhhgccccccccaacccccc +abccccaacaaaaaaaaaaccccccccccccccdcaaaccccccccaaaaaaccccccccccccchhhhhhhhhhhaaccccccccccccccc +abccccaaaaaaaaaaaaaaccccccccccaacdaaaaccccccccaaaaaacccaaacccccccchhhhhhhhaaaaccccccccccccccc +abcccaaaaaaaaaaaaaaaccccccccaaaaadcaaaacacaccccaaaccccaaaacccccccccchhhhccccaaccccccccccaaaca +abcccaaaaaacacaaacccccccccccaaaaadaaaaaaaaacccccccccccaaaacccccccccccaaaccccccccccccccccaaaaa +abcccccaaaacccaaaccccccccccaaaaaadaaaaaaaaaccccccccccccaaacccccccccccaaacccccccccccccccccaaaa +abcccccaacccccaacccccccccccaaaaaadaaaaaaccccccccccccccccccccccccccccccccccccccccccccccccaaaaa diff --git a/main.cpp b/main.cpp index 4d675c3..539c336 100644 --- a/main.cpp +++ b/main.cpp @@ -32,8 +32,9 @@ struct node{ vi2d playerPos={0,0}; vi2d endingPos={0,0}; std::vector>grid; +std::vectorpossibleStartingLocs; node*startNode; -node*endNode; +node *endNode; int main() { @@ -61,6 +62,9 @@ int main() for (int x=0;x0&&grid[y][x-1].getElevation()-1<=grid[y][x].getElevation()){ grid[y][x].connections.push_back(&grid[y][x-1]); } @@ -75,47 +79,70 @@ int main() } if (x==playerPos.x&&y==playerPos.y){ startNode=&grid[y][x]; - std::cout<<"Starting node set."<searchNodes; - searchNodes.push_back(startNode); - startNode->myDist=0.0f; - while (searchNodes.size()>0){ - node*currentNode=searchNodes.front(); - if (currentNode->visited){ - searchNodes.erase(searchNodes.begin()); - continue; + int bestPath=INFINITY; + node*testNode; + for (int l=0;lpos<visited=true; - for (int i=0;iconnections.size();i++){ - node*neighbor=currentNode->connections[i]; - if (!neighbor->visited){ - searchNodes.push_back(neighbor); + std::vectorsearchNodes; + searchNodes.push_back(testNode); + testNode->myDist=0.0f; + while (searchNodes.size()>0){ + node*currentNode=searchNodes.front(); + if (currentNode->visited){ + searchNodes.erase(searchNodes.begin()); + continue; } - float lowerGoal=currentNode->myDist+pow(neighbor->pos.x-currentNode->pos.x,2)+pow(neighbor->pos.y-currentNode->pos.y,2); - if (lowerGoalmyDist){ - neighbor->parent=currentNode; - neighbor->myDist=lowerGoal; + currentNode->visited=true; + for (int i=0;iconnections.size();i++){ + node*neighbor=currentNode->connections[i]; + if (!neighbor->visited){ + searchNodes.push_back(neighbor); + } + float lowerGoal=currentNode->myDist+pow(neighbor->pos.x-currentNode->pos.x,2)+pow(neighbor->pos.y-currentNode->pos.y,2); + if (lowerGoalmyDist){ + neighbor->parent=currentNode; + neighbor->myDist=lowerGoal; + } + } + } + node *searchNode = endNode; + bool completed=false; + int jumps=0; + while (searchNode!=testNode){ + if (searchNode->parent!=nullptr){ + //std::cout<<"Node goes from "<pos<<" to "<parent->pos<parent; + }else{ + break; + } + } + if (searchNode==testNode){ + if (jumpspos<<" to "<parent->pos<parent; - } - std::cout<<"Shortest path is "<