#define OLC_PGE_APPLICATION #include "pixelGameEngine.h" #include "olcutils.h" using namespace olc; const vi2d INVALID={-9999999,-99999999}; enum Direction{ NORTH, EAST, SOUTH, WEST }; struct Elf{ vi2d pos; int orderMarker=0; std::arrayorderList={Direction::NORTH,Direction::SOUTH,Direction::WEST,Direction::EAST}; vi2d dest=INVALID; }; vi2d upperLeft={0,0}; vi2d lowerRight={0,0}; std::mapelves; int iterations=1; int main() { std::ifstream file("input"); int y=0; while (file.good()){ std::string line; std::getline(file,line); if (line.length()>0){ std::cout<plannedMoves; for (std::map::iterator it=elves.begin();it!=elves.end();++it){ Elf&e=elves[it->first]; int neighbors=0; for (int x=-1;x<=1;x++){ for (int y=-1;y<=1;y++){ if (x!=0||y!=0){ if (elves.find({x+it->first.x,y+it->first.y})!=elves.end()){ neighbors++; goto neighborCheck; } } } } neighborCheck: if (neighbors>0){ for (int j=0;jfirst.x,it->first.y-1})==elves.end()&& elves.find({it->first.x-1,it->first.y-1})==elves.end()&& elves.find({it->first.x+1,it->first.y-1})==elves.end() ){ vi2d dest={it->first.x,it->first.y-1}; if (plannedMoves.find(dest)!=plannedMoves.end()){ if (elves.find(plannedMoves[dest])==elves.end()){ std::cout<<"WARNING! Could not find Elf @"<first; e.dest=dest; //std::cout<<"Elf @"<first<<"Plans to move NORTH"<first.x,it->first.y+1})==elves.end()&& elves.find({it->first.x-1,it->first.y+1})==elves.end()&& elves.find({it->first.x+1,it->first.y+1})==elves.end() ){ vi2d dest={it->first.x,it->first.y+1}; if (plannedMoves.find(dest)!=plannedMoves.end()){ if (elves.find(plannedMoves[dest])==elves.end()){ std::cout<<"WARNING! Could not find Elf @"<first; e.dest=dest; //std::cout<<"Elf @"<first<<"Plans to move SOUTH"<first.x-1,it->first.y})==elves.end()&& elves.find({it->first.x-1,it->first.y-1})==elves.end()&& elves.find({it->first.x-1,it->first.y+1})==elves.end() ){ vi2d dest={it->first.x-1,it->first.y}; if (plannedMoves.find(dest)!=plannedMoves.end()){ if (elves.find(plannedMoves[dest])==elves.end()){ std::cout<<"WARNING! Could not find Elf @"<first; e.dest=dest; } //std::cout<<"Elf @"<first<<"Plans to move WEST"<first.x+1,it->first.y})==elves.end()&& elves.find({it->first.x+1,it->first.y-1})==elves.end()&& elves.find({it->first.x+1,it->first.y+1})==elves.end() ){ vi2d dest={it->first.x+1,it->first.y}; if (plannedMoves.find(dest)!=plannedMoves.end()){ if (elves.find(plannedMoves[dest])==elves.end()){ std::cout<<"WARNING! Could not find Elf @"<first; e.dest=dest; } //std::cout<<"Elf @"<first<<"Plans to move EAST"<newElves; bool moved=false; for (std::map::iterator it=elves.begin();it!=elves.end();++it){ Elf&e=elves[it->first]; if (e.dest!=INVALID){ e.pos=e.dest; if (e.dest.xlowerRight.x){ lowerRight.x=e.dest.x; } if (e.dest.y>lowerRight.y){ lowerRight.y=e.dest.y; } e.dest=INVALID; Direction temp=e.orderList[0]; for (int j=0;jlowerRight.x){ lowerRight.x=e.pos.x; } if (e.pos.y>lowerRight.y){ lowerRight.y=e.pos.y; } Direction temp=e.orderList[0]; for (int j=0;j