diff --git a/C++ProjectTemplate b/C++ProjectTemplate index 780dadb..891f6ec 100755 Binary files a/C++ProjectTemplate and b/C++ProjectTemplate differ diff --git a/main.cpp b/main.cpp index 35f0099..28ceb30 100644 --- a/main.cpp +++ b/main.cpp @@ -1,3 +1,4 @@ +#include #define OLC_PGE_APPLICATION #include "pixelGameEngine.h" #include "olcutils.h" @@ -50,44 +51,143 @@ int main() std::cout<>ranges; + const int MAX_VAL=4000000; + std::cout<<"Computing coords..."<=maxX){ - maxX=minX-1; - break; - } - if (ranges[i].first>minX&&ranges[i].second Removed Range "<=maxX){ - maxX=ranges[i].first-1; - } - if (ranges[i].first<=minX&&ranges[i].second>=minX){ - minX=ranges[i].second+1; + int y=0; + for (int x=-s.radius;x<=s.radius;x++){ + if (x!=-s.radius){ + if (x<=0){ + y-=1; + } + if (x>0){ + y+=1; + } + } + if (std::abs(x)+std::abs(y)==s.radius){ + vi2d targetPos={x,y}; + if (x<0){ + targetPos.x--; + } + if (x>0){ + targetPos.x++; + } + if (x==0){ + if (y>0){ + targetPos.y++; + } + if (y<0){ + targetPos.y--; + } + } + if (s.pos.x+targetPos.x>=0&&s.pos.x+targetPos.x<=MAX_VAL&& + s.pos.y+targetPos.y>=0&&s.pos.y+targetPos.y<=MAX_VAL){ + vi2d target=s.pos+targetPos; + for (Sensor ss:sensors){ + if (std::abs(target.x-ss.pos.x)+std::abs(target.y-ss.pos.y)<=ss.radius){ + goto next; + } + } + std::cout<<"Target location found w/no signal! "<0){ + targetPos.y++; + } + if (y==0){ + if (x>0){ + targetPos.x++; + } + if (x<0){ + targetPos.x--; + } + } + if (s.pos.x+targetPos.x>=0&&s.pos.x+targetPos.x<=MAX_VAL&& + s.pos.y+targetPos.y>=0&&s.pos.y+targetPos.y<=MAX_VAL){ + vi2d target=s.pos+targetPos; + for (Sensor ss:sensors){ + if (std::abs(target.x-ss.pos.x)+std::abs(target.y-ss.pos.y)<=ss.radius){ + goto next; + } + } + std::cout<<"Target location found w/no signal! "<0){ + y-=1; } } - if (maxX>=minX){ - std::cout<<" --> Range is truncated to "<0){ + targetPos.x++; + } + if (x==0){ + if (y>0){ + targetPos.y++; + } + if (y<0){ + targetPos.y--; + } + } + if (s.pos.x+targetPos.x>=0&&s.pos.x+targetPos.x<=MAX_VAL&& + s.pos.y+targetPos.y>=0&&s.pos.y+targetPos.y<=MAX_VAL){ + vi2d target=s.pos+targetPos; + for (Sensor ss:sensors){ + if (std::abs(target.x-ss.pos.x)+std::abs(target.y-ss.pos.y)<=ss.radius){ + goto next2; + } + } + std::cout<<"Target location found w/no signal! "<0){ + targetPos.y++; + } + if (y==0){ + if (x>0){ + targetPos.x++; + } + if (x<0){ + targetPos.x--; + } + } + if (s.pos.x+targetPos.x>=0&&s.pos.x+targetPos.x<=MAX_VAL&& + s.pos.y+targetPos.y>=0&&s.pos.y+targetPos.y<=MAX_VAL){ + vi2d target=s.pos+targetPos; + for (Sensor ss:sensors){ + if (std::abs(target.x-ss.pos.x)+std::abs(target.y-ss.pos.y)<=ss.radius){ + goto next2; + } + } + std::cout<<"Target location found w/no signal! "<sensors; + while (file.good()){ + std::string line; + std::getline(file,line); + std::cout<0){ + while (prevMarker!=std::string::npos){ + std::string word=line.substr(prevMarker,marker-prevMarker); + prevMarker=marker; + marker=line.find(' ',prevMarker+1); + if (word[1]=='x'){ + if (sensorPos.x==-999){ + sensorPos.x=std::atoi(word.substr(word.find('=')+1,word.find(',')-word.find('=')-1).c_str()); + std::cout<<"Sensor X: "< Beacon Radius: "<>ranges; + for (Sensor s:sensors){ + int distance=std::abs(s.pos.y-targetY); + if (distance=maxX){ + maxX=minX-1; + break; + } + if (ranges[i].first>minX&&ranges[i].second Removed Range "<=maxX){ + maxX=ranges[i].first-1; + } + if (ranges[i].first<=minX&&ranges[i].second>=minX){ + minX=ranges[i].second+1; + } + } + if (maxX>=minX){ + std::cout<<" --> Range is truncated to "<