📄 chessman.cpp
字号:
#include<stdio.h>
#include<string.h>
#define MAX 100
char Chess[MAX][3];
int step=0,temp,n;
void Evaluate(int n) //赋值
{
for(int i=1;i<=n;i++)
strcpy(Chess[i],"○");
for(i=n+1;i<=2*n;i++)
strcpy(Chess[i],"●");
strcpy(Chess[2*n+1],"_ ");
strcpy(Chess[2*n+2],"_ ");
}
void Display() //输出
{
printf("Step %-2d: ",++step);
for(int i=1;i<=2*n+2;i++)
printf("%s",Chess[i]);
printf("\n");
}
void mvtosp(int k)
{
for(int j=0;j<=1;j++)
{
strcpy(Chess[temp+j],Chess[k+j]);
strcpy(Chess[k+j],"_ ");
}
temp=k;
Display();
}
void Move(int n)
{
if(n==4)
{
mvtosp(4);mvtosp(8);mvtosp(2);mvtosp(7);mvtosp(1);
}
else
{
mvtosp(n);mvtosp(2*n-1);Move(n-1);
}
}
void main()
{
do
{
printf("Please input the value of n:");
scanf("%d",&n);
}while(n<4);
Evaluate(n);
temp=2*n+1;
printf("The move process:\n");
Move(n);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -