111,120
社区成员
发帖
与我相关
我的任务
分享 bool[] Nine ={ true, true, true, true, true, true, true, true, true };
private void button1_Click(object sender, EventArgs e)
{
DownAll(6);
for (int i = 0; i < 9; i++)
{
textBox1.Text += Nine[i].ToString() + "\r\n";
}
textBox1.Text += "-----------\r\n";
UpAll(9);
for (int i = 0; i < 9; i++)
{
textBox1.Text += Nine[i].ToString() + "\r\n";
}
}
private void UpAll(int index)//把index及其以下的全部装上
{
switch (index)
{
case 1:
UpOne(1);
break;
case 2:
UpOne(1);
UpOne(2);
break;
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
UpAll(index - 1);
DownAll(index - 2);
UpOne(index);
UpAll(index - 2);
break;
default:
break;
}
}
private void DownAll(int index)//把index及其以下的全部卸下
{
switch (index)
{
case 1:
DownOne(1);
break;
case 2:
UpOne(1);
DownOne(2);
DownOne(1);
break;
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
UpAll(index - 1);
DownAll(index - 2);
DownOne(index);
DownAll(index - 1);
break;
default:
break;
}
}
private void UpOne(int index)//装上某一个,若不合规则则无动作
{
if (Nine[index - 1]) { return; }
switch (index)
{
case 1:
Nine[index - 1] = true;
break;
case 2:
if (Nine[0])
{ Nine[index - 1] = true; }
break;
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
if (!Nine[index - 2]) { break; }
for (int i = 1; i <= index - 2; i++)
{
if (Nine[i - 1]) { break; }
}
Nine[index - 1] = true;
break;
default:
break;
}
}
private void DownOne(int index)//卸下某一个,若不合规则则无动作
{
if (!Nine[index - 1]) { return; }
switch (index)
{
case 1:
Nine[index - 1] = false;
break;
case 2:
if (Nine[0])
{ Nine[index - 1] = false; }
break;
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
if (!Nine[index - 2]) { break; }
for (int i = 1; i <= index - 2; i++)
{
if (Nine[i - 1]) { break; }
}
Nine[index - 1] = false;
break;
default:
break;
}
}