diff --git a/C++ProjectTemplate b/C++ProjectTemplate index c1aa29d..b54cf80 100755 Binary files a/C++ProjectTemplate and b/C++ProjectTemplate differ diff --git a/input b/input new file mode 100644 index 0000000..3005358 --- /dev/null +++ b/input @@ -0,0 +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 diff --git a/main.cpp b/main.cpp index 8ab7e53..0acc582 100644 --- a/main.cpp +++ b/main.cpp @@ -4,86 +4,111 @@ using namespace olc; -class Example : public olc::PixelGameEngine -{ -public: - Example() - { - sAppName = "Example"; - } - -public: - bool RayVsRect(const vf2d ray_origin, const vf2d ray_dir, const olc::utils::geom2d::rect target, vf2d&contact_point, vf2d&contact_normal, float&t_hit_near){ - - contact_normal = { 0, 0 }; - contact_point = { 0, 0 }; - - vf2d t_near = {(target.pos.x - ray_origin.x) / ray_dir.x, (target.pos.y - ray_origin.y) / ray_dir.y}; - vf2d t_far = {(target.pos.x + target.size.x - ray_origin.x) / ray_dir.x, (target.pos.y + target.size.y - ray_origin.y) / ray_dir.y}; - - if (t_near.x > t_far.x) {float b; b = t_near.x; t_near.x = t_far.x; t_far.x = b;}; - if (t_near.y > t_far.y) {float b; b = t_near.y; t_near.y = t_far.y; t_far.y = b;}; - - if (t_near.x > t_far.y || t_near.y > t_far.x) return false; - - t_hit_near = fmax(t_near.x, t_near.y); - float t_hit_far = fmin(t_far.x, t_far.y); - - if (t_hit_far < 0) return false; - - contact_point.x = ray_origin.x + t_hit_near * ray_dir.x; - contact_point.y = ray_origin.y + t_hit_near * ray_dir.y; - - if (t_near.x > t_near.y) - if ( 1.0f / ray_dir.x < 0) - contact_normal = { 1, 0 }; - else - contact_normal = { -1, 0}; - else - if ( t_near.x < t_near.y) - if ( 1.0f / ray_dir.y < 0) - contact_normal = { 0, 1 }; - else - contact_normal = { 0, -1 }; - - return true; - - +std::vector validPathStepCounts; +vi2d playerPos={0,0}; +vi2d endingPos={0,0}; +std::vector>grid; +int lowest=2468; + +void step(char currentTile,vi2d pos,int xoffset,int yoffset,int stepCount,std::vector>visitedgrid,std::string currentPath){ + pos.x+=xoffset; + pos.y+=yoffset; + std::cout<{originPoint+velocity,5},olc::utils::geom2d::rect{{32,32},{64,32}})) { - originPoint+=velocity; - DrawCircle(originPoint,5); - } else { - DrawCircle(originPoint,5,RED); + if (stepCount+abs(pos.x-endingPos.x)+abs(pos.y-endingPos.y)>lowest){ + //std::cout<<"Took too long..."<=visitedgrid[0].size()||pos.y>=visitedgrid.size()){ + //std::cout<<"Dead end reached in "<='y')){ + currentPath+=visitedgrid[pos.y][pos.x]; + if (visitedgrid[pos.y][pos.x]=='E'){ + validPathStepCounts.push_back(++stepCount); + if (stepCount{{32,32},{64,32}},contact_point,contact_normal,t_hit_near)&&t_hit_near<1?YELLOW:WHITE); - return true; - } -}; - + ++stepCount; + char newTile=visitedgrid[pos.y][pos.x]; + visitedgrid[pos.y][pos.x]='0'; + if (pos.y+1>newvisitedgrid=visitedgrid; + step(newTile,pos,0,1,stepCount,newvisitedgrid,currentPath); + } + if (pos.y-1>=0&&visitedgrid[pos.y-1][pos.x]!='0'&&yoffset!=1){ + //visitedgrid[pos.y-1][pos.x]='0'; + std::vector>newvisitedgrid=visitedgrid; + step(newTile,pos,0,-1,stepCount,newvisitedgrid,currentPath); + } + if (pos.x-1>=0&&visitedgrid[pos.y][pos.x-1]!='0'&&xoffset!=1){ + //visitedgrid[pos.y][pos.x-1]='0'; + std::vector>newvisitedgrid=visitedgrid; + step(newTile,pos,-1,0,stepCount,newvisitedgrid,currentPath); + } + if (pos.x+1>newvisitedgrid=visitedgrid; + step(newTile,pos,1,0,stepCount,newvisitedgrid,currentPath); + } + } +} int main() { - Example demo; - if (demo.Construct(128, 120, 8, 8)) - demo.Start(); + std::ifstream file("testinput2"); + while (file.good()){ + std::string line; + std::getline(file,line); + std::vectorrow; + if (line.length()>0){ + for (int x=0;x>visitedgrid=grid; + std::vector>visitedgrid2=grid; + std::vector>visitedgrid3=grid; + std::vector>visitedgrid4=grid; + std::cout<<"Part 1"<