diff --git a/Day 10/day10 b/Day 10/day10 new file mode 100755 index 0000000..c999890 Binary files /dev/null and b/Day 10/day10 differ diff --git a/Day 10/main.cpp b/Day 10/main.cpp index e8b66ce..c11a268 100644 --- a/Day 10/main.cpp +++ b/Day 10/main.cpp @@ -5,7 +5,7 @@ #define OLC_IMAGE_STB #define OLC_PGE_APPLICATION #include "olcPixelGameEngine.h" - +#include using namespace olc; enum Run{ @@ -51,18 +51,21 @@ struct Pipe{ std::vector>tiles; +std::vectorpipeEdges; + vi2d startingPipe; +int tileCounts=0; + std::optionalGetPipe(vi2d coords){ if(coords.x<0||coords.y<0||coords.y>=tiles.size()||coords.x>=tiles[coords.y].size())return {}; return &tiles[coords.y][coords.x]; } -std::vectortilesRemaining; - void MarkAndMove(vi2d&pos,Direction dir){ tiles[pos.y][pos.x].partOfLoop=true; tiles[pos.y][pos.x].traversed=true; + pipeEdges.push_back(pos); switch(dir){ case UP:{ pos.y-=1; @@ -117,6 +120,41 @@ void AddPipe(std::string row1,std::string row2,std::string row3,std::vectorpartOfLoop){ + return false; //Hit one of our edge pipes. + } + }else{ + return true; + } + } +} + +void FloodFill(vi2d coord){ + auto pipe=GetPipe(coord); + if(pipe&&!pipe.value()->partOfLoop&&!pipe.value()->originalChar!=' '){ + pipe.value()->originalChar=' '; + auto downPipe=GetPipe(coord+vi2d{0,1}); + if(downPipe&&!downPipe.value()->partOfLoop&&downPipe.value()->originalChar!=' ')FloodFill(coord+vi2d{0,1}); + auto upPipe=GetPipe(coord+vi2d{0,-1}); + if(upPipe&&!upPipe.value()->partOfLoop&&upPipe.value()->originalChar!=' ')FloodFill(coord+vi2d{0,-1}); + auto leftPipe=GetPipe(coord+vi2d{-1,0}); + if(leftPipe&&!leftPipe.value()->partOfLoop&&leftPipe.value()->originalChar!=' ')FloodFill(coord+vi2d{-1,0}); + auto rightPipe=GetPipe(coord+vi2d{1,0}); + if(rightPipe&&!rightPipe.value()->partOfLoop&&rightPipe.value()->originalChar!=' ')FloodFill(coord+vi2d{1,0}); + } +} + + void doStuff2(){ while(true){ //lines is accessible as a global. for(std::string&line:lines){ @@ -176,11 +214,14 @@ void doStuff2(){ throw; } } + tileCounts++; } tiles.push_back(upperRow); tiles.push_back(middleRow); tiles.push_back(lowerRow); } + + std::cout<down)tiles[startingPipe.y+2][startingPipe.x+1].originalChar=symbol; - if(initialPipe.value()->right)tiles[startingPipe.y+1][startingPipe.x+2].originalChar=symbol; - if(initialPipe.value()->up)tiles[startingPipe.y][startingPipe.x+1].originalChar=symbol; - if(initialPipe.value()->left)tiles[startingPipe.y+1][startingPipe.x].originalChar=symbol; + if(initialPipe.value()->down){tiles[startingPipe.y+2][startingPipe.x+1].originalChar=symbol;tiles[startingPipe.y+2][startingPipe.x+1].partOfLoop=true;} + if(initialPipe.value()->right){tiles[startingPipe.y+1][startingPipe.x+2].originalChar=symbol;tiles[startingPipe.y+1][startingPipe.x+2].partOfLoop=true;} + if(initialPipe.value()->up){tiles[startingPipe.y][startingPipe.x+1].originalChar=symbol;tiles[startingPipe.y][startingPipe.x+1].partOfLoop=true;} + if(initialPipe.value()->left){tiles[startingPipe.y+1][startingPipe.x].originalChar=symbol;tiles[startingPipe.y+1][startingPipe.x].partOfLoop=true;} tiles[startingPipe.y+1][startingPipe.x+1].originalChar=symbol; vi2d currentPos=startingPipe+vi2d{1,1}; @@ -248,6 +289,25 @@ void doStuff2(){ //Test runs in all directions of looped pipes, see if they hit outer walls. //If they do, starting from the wall, flood fill all adjacent tiles. + //Start at any other edge, traverse in all directions and try to find a way out. + for(vi2d&coord:pipeEdges){ + //Try to draw a line going in all directions and see if we hit an edge. + vi2d tempCoord=coord; + if(HitEdge(coord,DOWN)){std::cout<<"Flood Fill from "<