diff --git a/C++ProjectTemplate b/C++ProjectTemplate index e5296a0..e0694dd 100755 Binary files a/C++ProjectTemplate and b/C++ProjectTemplate differ diff --git a/main.cpp b/main.cpp index 97d7c04..9408fa7 100644 --- a/main.cpp +++ b/main.cpp @@ -15,20 +15,85 @@ enum Direction{ struct Blizzard{ vi2d pos; Direction dir; + bool moved=false; }; + int maxWidth=0; +vi2d playerPos={1,0}; +std::vector>>boardState; + +std::vector> getBoard(int minute){ + if (minute> prevBoardState=getBoard(minute-1); + for (int y=0;y&blizzardList=prevBoardState[y]; + for (int x=0;x&blizzardList=prevBoardState[y]; + blizzardList.reserve(100); + for (int x=0;xpush_back(b); + blizzardList.erase(blizzardList.begin()+x--); + }break; + case EAST:{ + vi2d dest={b.pos.x+1,b.pos.y}; + if (dest.x>=maxWidth-1){ + dest.x=1; + } + b.pos=dest; + }break; + case SOUTH:{ + vi2d dest={b.pos.x,b.pos.y+1}; + if (dest.y>=prevBoardState.size()-1){ + dest.y=1; + } + b.pos=dest; + (&prevBoardState[dest.y])->push_back(b); + blizzardList.erase(blizzardList.begin()+x--); + }break; + case WEST:{ + vi2d dest={b.pos.x-1,b.pos.y}; + if (dest.x<1){ + dest.x=maxWidth-2; + } + b.pos=dest; + }break; + } + } + } + } + boardState.push_back(prevBoardState); + return prevBoardState; + } +} int main() { - std::ifstream file("input"); - std::vector>>boardState; + std::ifstream file("smallinput"); + std::vector>board; while (file.good()){ std::string line; - std::vector>board; std::getline(file,line); if (line.length()>0){ std::cout<boardRow; + boardRow.reserve(100); for (int i=0;i'?Direction::EAST:line[i]=='v'?Direction::SOUTH:line[i]=='<'?Direction::WEST:Direction::INVALID}); @@ -37,9 +102,9 @@ int main() maxWidth=line.length(); board.push_back(boardRow); } - boardState.push_back(board); } - for (int d=0;d>board=getBoard(i+1); + for (int y=0;ysorted=board[y]; + std::sort(sorted.begin(),sorted.end(),[](Blizzard&b1,Blizzard&b2){return b1.pos.x'; + }break; + case SOUTH:{ + std::cout<<'v'; + }break; + case WEST:{ + std::cout<<'<'; + }break; + case INVALID:{ + std::cout<<'?'; + }break; + } + prevBlizzard=b.pos.x; + } + } + for (int k=prevBlizzard;k^...# +#.<...# +#...v.# +#.....# +#####.# \ No newline at end of file diff --git a/testinput b/testinput new file mode 100644 index 0000000..6b9b892 --- /dev/null +++ b/testinput @@ -0,0 +1,6 @@ +#.###### +#>>.<^<# +#.<..<<# +#>v.><># +#<^v^^># +######.# \ No newline at end of file