利用C语言编程序

来源:百度知道 编辑:UC知道 时间:2024/05/21 23:53:39
题目:马的遍历问题
要求:在10*9的中国象棋的棋盘中,马只能走“日”字。马从位置(0,1)处出发,把棋盘的每一格都走一次,且只走一次。要求在屏幕上画出棋盘和马所有经过的路径。
呵呵,我对C语言不是很了解,望能提供一个更为准确点的,谢谢了

#include <stdio.h>

typedef struct {
long x;
long y;
}POSITION;

//马可以跳的8个方向。
const POSITION pNext[8] = {
{-2,-1}, {-2,1}, {-1,-2}, {-1,2},
{1,-2}, {1,2}, {2,-1}, {2,1}
};

//为了测试算法,用小的棋盘试试。
const long SIZEX = 8;
const long SIZEY = 5;
//const long SIZEX = 9;
//const long SIZEY = 10;

bool Jump(long Buffer[SIZEY][SIZEX], POSITION pnt, long nCount);
__inline
void PrintBuffer(long Buffer[SIZEY][SIZEX])
{
long i,j;
for (j=0; j<SIZEY; j++)
{
for (i=0; i<SIZEX; i++)
{
printf("%5d", Buffer[j][i]);
}
printf("\n");
}
//getchar();
}

__inline
bool HasInvalidPos(long Buffer[SIZEY][SIZEX], long nCurrentCount)
{
long i,j,k;
bool bResult=false;
for (j=0; j<SIZEY; j++)
for (i=0; i<SIZEX; i++)
{
if (Buffer[j][i]!=0)