Last active
March 30, 2018 23:43
-
-
Save Dman757/48e6e619e572a445ee9d8a91f922a6f6 to your computer and use it in GitHub Desktop.
Pop Pop watching particles drop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
. | |
T . | |
.T . | |
: : .: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "stdafx.h" | |
#include <iostream> | |
#include <fstream> | |
#include <vector> | |
#include <string> | |
using namespace std; | |
void printV(std::vector<std::vector<int>>&); | |
void parseIn(std::vector<std::vector<int>>&); | |
void havokPhysicsTM(std::vector<std::vector<int>>&); | |
int main() | |
{ | |
std::vector<std::vector<int>> v; | |
//Read in data | |
parseIn(v); | |
//Input Print | |
cout << "Input"<< endl; | |
printV(v); | |
cout << endl; | |
//RUN THE PHYSIX | |
havokPhysicsTM(v); | |
//Output Print | |
cout << "Output" << endl; | |
printV(v); | |
return 0; | |
} | |
void printV(std::vector<std::vector<int>>& data) | |
{ | |
int x = data.size(); | |
int y = data[0].size(); | |
for (int j = 0; j < y; j++) | |
{ | |
for (int i = 0; i < x; i++) | |
{ | |
switch (data[i][j]) { | |
case 0: cout << " "; | |
break; | |
case 1: cout << "."; | |
break; | |
case 2: cout << ":"; | |
break; | |
case 3: cout << "T"; | |
break; | |
default: cout << "bro we didn't agree on this character"; | |
break; | |
} | |
} | |
cout << endl; | |
} | |
} | |
void parseIn(std::vector<std::vector<int>>& data) | |
{ | |
int x, y; | |
int j = 0; | |
cin >> x >> y; | |
data.resize(x, std::vector<int>(y)); //Resize our vector to the STDIN input | |
for (string line; getline(cin, line);) | |
{ | |
for (int i = 0; i < line.length(); i++) | |
{ | |
switch (line[i]) { | |
case ' ': data[i][j] = 0; | |
break; | |
case '.': data[i][j] = 1; | |
break; | |
case ':': data[i][j] = 2; | |
break; | |
case 'T': data[i][j] = 3; | |
break; | |
default: cout << "bro we didn't agree on this character"; | |
break; | |
} | |
if ( (i != 0) && ((i % (x-1)) == 0)) | |
{ | |
j++; | |
} | |
} | |
} | |
} | |
void havokPhysicsTM(std::vector<std::vector<int>>& data) //Embrace teh jank. Become the jank. | |
{ | |
int x = data.size(); | |
int y = data[0].size(); | |
for (int i = 0; i < x; i++) | |
{ | |
for (int j = 0; j < y; j++) | |
{ | |
if (data[i][j] == 1) | |
{ | |
if (j < (y-1)) | |
{ | |
if (data[i][j + 1] == 0) //we are a . //move down if there's nothing below | |
{ | |
data[i][j + 1] = 1; | |
data[i][j] = 0; | |
} | |
else | |
if (data[i][j + 1] == 1) //we are a . //combine if dot below . -> : | |
{ | |
data[i][j + 1] = 2; | |
data[i][j] = 0; | |
} | |
else | |
if ((data[i][j + 1] == 2) && (j + 2 <= y - 1)) //we are a .//below is a : | |
{ | |
if (data[i][j + 2] == 0) //Not totally sure if this check is nessicary | |
{ | |
data[i][j + 1] = 1; | |
data[i][j + 2] = 2; | |
data[i][j] = 0; | |
} | |
} | |
} | |
} | |
if (data[i][j] == 2) //We are a : at start | |
{ | |
if (j < (y - 1)) | |
{ | |
if (data[i][j + 1] == 0) //We are a : //There's nothing below | |
{ | |
data[i][j + 1] = 2; | |
data[i][j] = 0; | |
} | |
else | |
if (data[i][j + 1] == 1) //We are a : //There's a . below | |
{ | |
if ((j + 2 <= y - 1)) | |
{ | |
if (data[i][j + 2] == 0) //We swap places //Can we move both : and . below down? | |
{ | |
data[i][j + 2] = 2; | |
data[i][j + 1] = 1; | |
data[i][j] = 0; | |
} | |
} | |
else //Can't move both : and . down so we just swap places. | |
{ | |
data[i][j + 1] = 2; | |
data[i][j] = 1; | |
} | |
} | |
} | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 4 | |
.....: | |
.T | |
.T . | |
. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment