generated from sigonasr2/CPlusPlusProjectTemplate
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
127 lines
3.7 KiB
127 lines
3.7 KiB
#define OLC_PGE_APPLICATION
|
|
#include "pixelGameEngine.h"
|
|
#include "olcutils.h"
|
|
|
|
using namespace olc;
|
|
|
|
|
|
vi2d upperLeftCoords={500,0};
|
|
vi2d lowerRightCoords={500,0};
|
|
std::vector<std::vector<char>>board;
|
|
|
|
struct Connection{
|
|
std::vector<vi2d>coords;
|
|
};
|
|
|
|
enum ReadState{
|
|
READX,
|
|
READY,
|
|
WAIT
|
|
};
|
|
|
|
vi2d getArrayCoords(vi2d pos){
|
|
return pos-upperLeftCoords;
|
|
}
|
|
|
|
void modifyBoard(vi2d pos,char val){
|
|
vi2d actualCoords=getArrayCoords(pos);
|
|
board[actualCoords.y][actualCoords.x]=val;
|
|
}
|
|
|
|
int main()
|
|
{
|
|
std::vector<Connection>connections;
|
|
std::ifstream file("input");
|
|
ReadState state=READX;
|
|
while (file.good()){
|
|
std::string line;
|
|
std::getline(file,line);
|
|
std::string num1;
|
|
std::string num2;
|
|
if (line.length()>0){
|
|
state=READX;
|
|
Connection c;
|
|
for (int i=0;i<line.length();i++){
|
|
switch (state){
|
|
case READX:{
|
|
if (line[i]==','){
|
|
state=READY;
|
|
break;
|
|
}
|
|
num1+=line[i];
|
|
}break;
|
|
case READY:{
|
|
if (line[i]==' '){
|
|
state=WAIT;
|
|
int numb1=std::atoi(num1.c_str());
|
|
int numb2=std::atoi(num2.c_str());
|
|
c.coords.push_back({numb1,numb2});
|
|
upperLeftCoords.x=std::min(numb1,upperLeftCoords.x);
|
|
upperLeftCoords.y=std::min(numb2,upperLeftCoords.y);
|
|
lowerRightCoords.x=std::max(numb1,lowerRightCoords.x);
|
|
lowerRightCoords.y=std::max(numb2,lowerRightCoords.y);
|
|
std::cout<<"read "<<num1<<"//"<<num2<<std::endl;
|
|
num1="";
|
|
num2="";
|
|
break;
|
|
}
|
|
num2+=line[i];
|
|
}break;
|
|
case WAIT:{
|
|
if (line[i]==' '){
|
|
state=READX;
|
|
break;
|
|
}
|
|
}break;
|
|
}
|
|
}
|
|
connections.push_back(c);
|
|
}
|
|
std::cout<<line<<std::endl;
|
|
}
|
|
std::cout<<"Upper-Left Bounds: "<<upperLeftCoords<<std::endl;
|
|
std::cout<<"Lower-Right Bounds: "<<lowerRightCoords<<std::endl;
|
|
|
|
|
|
|
|
for (int y=upperLeftCoords.y;y<=lowerRightCoords.y;y++){
|
|
std::vector<char>b;
|
|
for (int x=upperLeftCoords.x;x<=lowerRightCoords.x;x++){
|
|
b.push_back(' ');
|
|
}
|
|
board.push_back(b);
|
|
}
|
|
|
|
for(int i=0;i<connections.size();i++){
|
|
Connection&c=connections[i];
|
|
vi2d&startPos=c.coords[0];
|
|
for (int j=1;j<c.coords.size();j++){
|
|
vi2d&endPos=c.coords[j];
|
|
while (startPos!=endPos){
|
|
modifyBoard(startPos,'#');
|
|
if (startPos.x!=endPos.x){
|
|
startPos.x+=(endPos.x-startPos.x)/std::abs(startPos.x-endPos.x);
|
|
}
|
|
if (startPos.y!=endPos.y){
|
|
startPos.y+=(endPos.y-startPos.y)/std::abs(startPos.y-endPos.y);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
for (int y=0;y<board.size();y++){
|
|
for (int x=0;x<board[y].size();x++){
|
|
if (board[y][x]!=' '){
|
|
std::cout<<board[y][x];
|
|
} else
|
|
if (x+upperLeftCoords.x==500){
|
|
std::cout<<'|';
|
|
} else {
|
|
std::cout<<board[y][x];
|
|
}
|
|
}
|
|
std::cout<<std::endl;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|