|
|
|
@ -5,10 +5,11 @@ |
|
|
|
|
|
|
|
|
|
using namespace olc; |
|
|
|
|
|
|
|
|
|
std::array<std::array<char,7>,30000000>playfieldRows; |
|
|
|
|
|
|
|
|
|
int main() |
|
|
|
|
{ |
|
|
|
|
std::ifstream file("input"); |
|
|
|
|
std::vector<std::array<char,7>>playfieldRows; |
|
|
|
|
std::ifstream file("testinput"); |
|
|
|
|
std::array<std::array<char,4>,4>piece{{ |
|
|
|
|
{' ',' ',' ',' '}, |
|
|
|
|
{' ',' ',' ',' '}, |
|
|
|
@ -37,8 +38,16 @@ int main() |
|
|
|
|
{' ',' ',' ',' '}, |
|
|
|
|
{' ',' ',' ',' '}}},{2,2}},}}; |
|
|
|
|
int currentPiece=0; |
|
|
|
|
int topRow=0; |
|
|
|
|
int topRow=playfieldRows.size(); |
|
|
|
|
int stackSize=0; |
|
|
|
|
int jetMarker=0; |
|
|
|
|
std::cout<<"Initializing array..."<<std::endl; |
|
|
|
|
for (int y=0;y<playfieldRows.size();y++){ |
|
|
|
|
for (int x=0;x<7;x++){ |
|
|
|
|
playfieldRows[y][x]=' '; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
std::cout<<"Starting."<<std::endl; |
|
|
|
|
while (file.good()){ |
|
|
|
|
std::string line; |
|
|
|
|
std::getline(file,line); |
|
|
|
@ -50,16 +59,7 @@ int main() |
|
|
|
|
currentPiece=(currentPiece+1)%5; |
|
|
|
|
int newRows=3-topRow+piece.second.y; |
|
|
|
|
//std::cout<<"Adding "<<newRows<<" rows..."<<std::endl;
|
|
|
|
|
if (newRows>0){ |
|
|
|
|
for (int j=0;j<newRows;j++){ |
|
|
|
|
std::array<char,7>newRow={' ',' ',' ',' ',' ',' ',' '}; |
|
|
|
|
playfieldRows.insert(playfieldRows.begin(),newRow); |
|
|
|
|
topRow++; |
|
|
|
|
} |
|
|
|
|
piecePos={2,0}; |
|
|
|
|
} else { |
|
|
|
|
piecePos={2,topRow-3-piece.second.y}; |
|
|
|
|
} |
|
|
|
|
piecePos={2,topRow-3-piece.second.y}; |
|
|
|
|
while (!pieceLanded) { |
|
|
|
|
char direction=line[jetMarker]; |
|
|
|
|
//std::cout<<direction;
|
|
|
|
@ -125,12 +125,68 @@ int main() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (piecePos.y<topRow){ |
|
|
|
|
stackSize+=topRow-piecePos.y; |
|
|
|
|
topRow=piecePos.y; |
|
|
|
|
} |
|
|
|
|
pieceLanded=true; |
|
|
|
|
} else { |
|
|
|
|
piecePos.y++; |
|
|
|
|
} |
|
|
|
|
for (int yy=0;yy<piece.second.y;yy++){ |
|
|
|
|
bool completeRow=true; |
|
|
|
|
for (int xx=0;xx<7;xx++){ |
|
|
|
|
if (playfieldRows[piecePos.y+yy][xx]==' '){ |
|
|
|
|
completeRow=false; |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (completeRow){ |
|
|
|
|
//std::cout<<"Complete row found! @"<<piecePos.y<<std::endl;
|
|
|
|
|
int chopPoint=piecePos.y+yy; |
|
|
|
|
int topRowDiff=chopPoint-topRow; |
|
|
|
|
//std::cout<<"Top Row Diff: "<<topRowDiff<<std::endl;
|
|
|
|
|
/*for (int yyy=chopPoint-topRowDiff;yyy<playfieldRows.size();yyy++){
|
|
|
|
|
for (int xxx=0;xxx<9;xxx++){ |
|
|
|
|
if (xxx==0||xxx==8){ |
|
|
|
|
std::cout<<'|'; |
|
|
|
|
} else { |
|
|
|
|
std::cout<<playfieldRows[yyy][xxx-1]; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
std::cout<<std::endl; |
|
|
|
|
}*/ |
|
|
|
|
//std::cout<<"==========="<<std::endl;
|
|
|
|
|
for (int yyy=chopPoint;yyy<playfieldRows.size();yyy++){ |
|
|
|
|
for (int xxx=0;xxx<7;xxx++){ |
|
|
|
|
playfieldRows[yyy][xxx]=' '; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
//std::cout<<"Cleared current board!"<<std::endl;
|
|
|
|
|
topRow=playfieldRows.size(); |
|
|
|
|
for (int yyy=chopPoint-topRowDiff;yyy<chopPoint;yyy++){ |
|
|
|
|
for (int xxx=0;xxx<7;xxx++){ |
|
|
|
|
playfieldRows[yyy+playfieldRows.size()-chopPoint][xxx]=playfieldRows[yyy][xxx]; |
|
|
|
|
if (playfieldRows[yyy+playfieldRows.size()-chopPoint][xxx]!=' '&&yyy+playfieldRows.size()-chopPoint<topRow){ |
|
|
|
|
topRow=yyy+playfieldRows.size()-chopPoint; |
|
|
|
|
} |
|
|
|
|
playfieldRows[yyy][xxx]=' '; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
/*std::cout<<"New board:"<<std::endl;
|
|
|
|
|
for (int yyy=playfieldRows.size()-topRowDiff;yyy<playfieldRows.size();yyy++){ |
|
|
|
|
for (int xxx=0;xxx<9;xxx++){ |
|
|
|
|
if (xxx==0||xxx==8){ |
|
|
|
|
std::cout<<'|'; |
|
|
|
|
} else { |
|
|
|
|
std::cout<<playfieldRows[yyy][xxx-1]; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
std::cout<<std::endl; |
|
|
|
|
} |
|
|
|
|
std::cout<<"Shifted down elements. New Top:"<<topRow<<std::endl;*/ |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
jetMarker=(jetMarker+1)%line.length(); |
|
|
|
|
//std::cout<<"jetMarker is now "<<jetMarker<<std::endl;
|
|
|
|
|
/*for (int y=0;y<playfieldRows.size();y++){
|
|
|
|
@ -163,7 +219,7 @@ int main() |
|
|
|
|
}*/ |
|
|
|
|
} |
|
|
|
|
std::cout<<std::endl; |
|
|
|
|
std::cout<<"The tower is "<<playfieldRows.size()-topRow<<" tall!"<<std::endl; |
|
|
|
|
std::cout<<"The tower is "<<stackSize<<" tall!"<<std::endl; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|