Created
February 13, 2011 23:24
-
-
Save ACUVE/825295 to your computer and use it in GitHub Desktop.
ぷよぷよ超適当バージョン
This file contains hidden or 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 <iostream> | |
#include <fstream> | |
#include <string> | |
#include <stack> | |
#include <tuple> | |
#include <vector> | |
int main(int argc, char **argv){ | |
std::vector<std::vector<std::tuple<char, bool>>> f; | |
{ | |
std::vector<std::vector<char>> field; | |
if(argc < 2) return 0; | |
std::ifstream ifs(argv[1]); | |
{ | |
std::string line; | |
unsigned int ind = 0; | |
while(std::getline(ifs, line)){ | |
if(line.length() > 1){ | |
field.push_back(std::vector<char>(6)); | |
for(unsigned int i = 0; i < 6; ++i){ | |
field[ind][i] = line[i]; | |
} | |
ind++; | |
}else{ | |
break; | |
} | |
} | |
} | |
f.resize(field.size()); | |
for(unsigned int i = 0; i < field.size(); ++i){ | |
f[field.size() - i - 1] = std::vector<std::tuple<char, bool>>(6); | |
for(unsigned int j = 0; j < 6; ++j){ | |
f[field.size() - i - 1][j] = std::make_tuple(field[i][j], true); | |
} | |
} | |
} | |
bool endflag = false; | |
while(!endflag){ | |
endflag = true; | |
//初期化 | |
for(unsigned int i = 0; i < f.size(); ++i){ | |
for(unsigned int j = 0; j < 6; ++j){ | |
std::get<1>(f[i][j]) = true; | |
} | |
} | |
for(unsigned int i = 0; i < f.size(); ++i){ | |
for(unsigned int j = 0; j < 6; ++j){ | |
if(std::get<1>(f[i][j]) && std::get<0>(f[i][j]) != ' '){ | |
char current = std::get<0>(f[i][j]); | |
std::stack<std::tuple<int, int>> st; | |
st.push(std::make_tuple(i, j)); | |
std::vector<std::tuple<int, int>> killpos; | |
while(!st.empty()){ | |
std::tuple<int, int> &fr = st.top(); | |
st.pop(); | |
int x = std::get<0>(fr), y = std::get<1>(fr); | |
std::tuple<char, bool> &pos = f[x][y]; | |
if(current == std::get<0>(pos) && std::get<1>(pos)){ | |
std::get<1>(pos) = false; | |
killpos.push_back(fr); | |
if(0 <= x - 1){ | |
st.push(std::make_tuple(x - 1, y)); | |
} | |
if(0 <= y - 1){ | |
st.push(std::make_tuple(x, y - 1)); | |
} | |
if(x + 1 < f.size()){ | |
st.push(std::make_tuple(x + 1, y)); | |
} | |
if(y + 1 < 6){ | |
st.push(std::make_tuple(x, y + 1)); | |
} | |
} | |
} | |
if(killpos.size() >= 4){ | |
endflag = false; | |
for(unsigned int k = 0; k < killpos.size(); ++k){ | |
std::get<0>(f[std::get<0>(killpos[k])][std::get<1>(killpos[k])]) = ' '; | |
} | |
} | |
} | |
} | |
} | |
for(unsigned int y = 0; y <= 6; ++y){ | |
unsigned int xx = 0; | |
for(unsigned int x = 0; x < f.size(); ++x){ | |
if(std::get<0>(f[x][y]) != ' '){ | |
std::get<0>(f[xx++][y]) = std::get<0>(f[x][y]); | |
} | |
} | |
for(; xx < f.size(); ++xx){ | |
std::get<0>(f[xx][y]) = ' '; | |
} | |
} | |
for(unsigned int i = 0; i < f.size(); ++i){ | |
for(unsigned int j = 0; j < 6; ++j){ | |
std::cout << std::get<0>(f[f.size() - i - 1][j]); | |
} | |
std::cout << std::endl; | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment