怎么用c语言定义棋盘大小,求数据结构C语言大神们解释下马踏棋盘程序

//宏定义棋盘大小#define SIZE 100int board[M][M];typedef struct direct { int r,c,pathnum ;}dir ;typedef struct nodetype { int r,c,p

//宏定义棋盘大小#define SIZE 100int board[M][M];typedef struct direct { int r,c,pathnum ;}dir ;typedef struct nodetype { int r,c,pathnum ; //在棋盘中的位置坐标r,c及结点可走方向数目 pathnum struct nodetype*next,*prior ;}node ;//用来计算当前位置可走的方向数目int pathnum(int row,int cn){ int a,b,count=0 ; a=row ; b=cn ; //当前位置可选方向可以走通,则数目加一 if(a-2>=0&&b-1>=0&&board[a-2][b-1]==0) count++; if(a-2>=0&&b+1=0&&board[a+2][b-1]==0) count++; if(a+2=0&&b+2=0&&b-2>=0&&board[a-1][b-2]==0) count++; if(a+1=0&&board[a+1][b-2]==0) count++; return count ;}//寻找路径函数void findway(int m,int n){ dir f[8],path ; int i,j,k, stepnum ; stepnum=1 ; i=m ; j=n ; while(stepnum=0&&j>=0) { board[i][j]=stepnum ; printf("%d,%d,%d ",i,j,board[i][j]); //用来标志可走方向数的最小值 thnum=8 ; //对方向数组赋初值 for(k=0;k<8;k++) { f[k].r=-1 ; f[k].c=-1 ; } //如果第一个方向可走,则将坐标及可选方向数赋给f[0],以下同理 if(i-2>=0&&j-1>=0) { f[0].r=i-2 ; f[0].c=j-1 ; f[0].pathnum=pathnum(f[0].r,f[0].c); } if(i-2>=0&&j+1=0) { f[2].r=i+2 ; f[2].c=j-1 ; f[2].pathnum=pathnum(f[2].r,f[2].c); } if(i+2=0&&j+2=0&&j-2>=0) { f[5].r=i-1 ; f[5].c=j-2 ; f[5].pathnum=pathnum(f[5].r,f[5].c); } if(i+1=0) { f[6].r=i+1 ; f[6].c=j-2 ; f[6].pathnum=pathnum(f[6].r,f[6].c); } if(i+1=0&&f[k].c>=0&&f[k].pathnum<= thnum&&board[f[k].r][f[k].c]==0&&f[k].pathnum>0) { thnum=f[k].pathnum; path.r=f[k].r ; path.c=f[k].c ; } i=path.r ; j=path.c ; stepnum++; }还有一段代码, 字数不够了,各模块的功能,个功能的实现方法和原理,

展开

全部

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值