資源簡介
中國象棋棋盤上,對任意位置放置的一個馬,均能選擇一個合適的路線,使得棋子能按象棋的規則不重復地走過棋盤的每個位置
實驗要求:(1)依次輸出所走過的各位置坐標
(2)畫出棋盤的圖形形式,并在其上演示動態過程
(3)程序能方便地移植到其他規則的棋盤上
代碼片段和文件信息
#include
#include
using?namespace?std;
#define?M?10
#define?N?9
struct?step
{
int?i;
int?j;
int?di;
}?st[N*M];
?int???move1[8]={2211-1-1-2-2}???
???????move2[8]={1-12-22-21-1};
int?top=-1;int?mg[N+1][N];string?chess[N+1][N];
int?nextstep(int?xint?y)
{
int?count=0i1j1;
for(int?i=0;i<8;i++)
{
i1=x+move1[i];j1=y+move2[i];
if(i1>M-1||i1<0||j1>N-1||j1<0)continue;
if(mg[i1][j1]!=0)continue;
else?count++;
}
return?count;
}
void?horse(int?xint?y)
{
int?ijdifind;
top++;
st[top].i=x;st[top].j=y;st[top].di=-1;
mg[x][y]=1;
while(top>-1)
{
int?count=8;
i=st[top].i;j=st[top].j;di=st[top].di;
if(top+1==M*N)
{
for(int?k=0;k {
system(“cls“);
cout<<“>>>>>>>>>>>>>>>>>>>>數據結構
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????2491??2009-06-11?17:21??課程設計.cpp
-----------?---------??----------?-----??----
?????????????????2491????????????????????1
評論
共有 條評論