Skip to content

Instantly share code, notes, and snippets.

@Alien-Leon
Created October 23, 2018 10:14
Show Gist options
  • Save Alien-Leon/fb658cd136694db05897870c5c92b1c8 to your computer and use it in GitHub Desktop.
Save Alien-Leon/fb658cd136694db05897870c5c92b1c8 to your computer and use it in GitHub Desktop.
// 消除后对应空位由上方元素填充
void dropdown()
{
vector<pair<int, int>> points;
for(int k = 0; k < n; k++) // 蛮力扫描所有列,效率待提高
{
int count = 0;
// 检查该列是否需要填充
for(int curi = m-1; curi >= 0; curi--)
{
if(ar[curi][k] == 0)
{
int ci = curi - 1;
int ni = curi;
// 计算该列被消除的个数
while(ci >= 0 && ar[ci][k] == 0)
{
count++;
ci--;
}
ci = curi - count - 1;
// 元素下落
while(ci >= 0)
{
ar[ni][k] = ar[ci][k];
points.push_back(make_pair(ni, k));
ni--;
ar[ci--][k] = 0;
}
}
}
}
//cout << "After dropdown" << endl;
//print_array();
// 检查下落后是否还有可消除元素
// 对受下落影响的元素进行扫描
bool can_eliminate = false;
for (int ii = 0; ii < points.size(); ii++)
if (eliminate(points[ii].first, points[ii].second))
can_eliminate = true;
if (can_eliminate)
dropdown();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment