#define OLC_PGE_APPLICATION #include "pixelGameEngine.h" #include "olcutils.h" using namespace olc; void tailFollow(vi2d&tail,std::array&head,std::map&posmap){ //std::cout<=2&&std::abs(head[i-1].y-head[i].y)>=1|| std::abs(head[i-1].x-head[i].x)>=1&&std::abs(head[i-1].y-head[i].y)>=2){ head[i].x+=(head[i-1].x-head[i].x)/std::abs(head[i-1].x-head[i].x); head[i].y+=(head[i-1].y-head[i].y)/std::abs(head[i-1].y-head[i].y); } else if (std::abs(head[i-1].x-head[i].x)>=2){ //std::cout<<" "<<"Move X: "<=2){ //std::cout<<" "<<"Move Y: "<=2&&std::abs(head[8].y-tail.y)>=1|| std::abs(head[8].x-tail.x)>=1&&std::abs(head[8].y-tail.y)>=2){ tail.x+=(head[8].x-tail.x)/std::abs(head[8].x-tail.x); tail.y+=(head[8].y-tail.y)/std::abs(head[8].y-tail.y); } else if (std::abs(head[8].x-tail.x)>=2){ //std::cout<<" "<<"Move X: "<=2){ //std::cout<<" "<<"Move Y: "<&head,std::map&posmap){ int maxX=tail.x; int maxY=tail.y; int minX=tail.x; int minY=tail.y; for (int i=0;i<9;i++){ maxX=std::max(maxX,head[i].x); maxY=std::max(maxY,head[i].y); minX=std::min(minX,head[i].x); minY=std::min(minY,head[i].y); } for (std::map::iterator it=posmap.begin();it!=posmap.end();it++){ if (std::atoi(it->first.substr(0,it->first.find_first_of('_')).c_str())>maxX){ maxX=std::atoi(it->first.substr(0,it->first.find_first_of('_')).c_str()); } } for (std::map::iterator it=posmap.begin();it!=posmap.end();it++){ if (std::atoi(it->first.substr(it->first.find_first_of('_')+1,std::string::npos).c_str())>maxY){ maxY=std::atoi(it->first.substr(it->first.find_first_of('_')+1,std::string::npos).c_str()); } } for (std::map::iterator it=posmap.begin();it!=posmap.end();it++){ if (std::atoi(it->first.substr(0,it->first.find_first_of('_')).c_str())first.substr(0,it->first.find_first_of('_')).c_str()); } } for (std::map::iterator it=posmap.begin();it!=posmap.end();it++){ if (std::atoi(it->first.substr(it->first.find_first_of('_')+1,std::string::npos).c_str())first.substr(it->first.find_first_of('_')+1,std::string::npos).c_str()); } } for (int y=minY;y<=maxX;y++){ for (int x=minX;x<=maxX;x++){ if (tail.x==x&&tail.y==y){ std::cout<<"T"; continue; } for (int i=0;i<9;i++){ if (head[i].x==x&&head[i].y==y){ std::cout<::iterator it=posmap.begin();it!=posmap.end();it++){ if (std::atoi(it->first.substr(0,it->first.find_first_of('_')).c_str())==x&& std::atoi(it->first.substr(it->first.find_first_of('_')+1,std::string::npos).c_str())==y){ std::cout<<"#"; goto next; } } std::cout<<"."; next:; } std::cout<posmap; vi2d tail={0,0}; std::arrayhead={vi2d{0,0}}; while (file.good()){ std::string line; std::getline(file,line); posmap[std::to_string(tail.x)+"_"+std::to_string(tail.y)]=true; if (line.length()>0){ char dir=line[0]; int amt=std::atoi(line.substr(1,std::string::npos).c_str()); std::cout<0){ head[0].y++; tailFollow(tail,head,posmap); amt--; } }break; case 'R':{ while (amt>0){ head[0].x++; tailFollow(tail,head,posmap); amt--; } }break; case 'L':{ while (amt>0){ head[0].x--; tailFollow(tail,head,posmap); amt--; } }break; case 'U':{ while (amt>0){ head[0].y--; tailFollow(tail,head,posmap); amt--; } }break; } //DrawMap(tail,head,posmap); } } DrawMap(tail,head,posmap); std::cout<<"Key count:"<