在一个8*8象棋棋盘中,定义马的起始位置,如何让马踏遍整个棋盘
使用递归求解,从起始位置开始,往其四周可去的点行走,走到之后,再以到达点为起始点再向四周可去点走,直到走完
#include<iostream>
#include<cstdlib>
using namespace std;
#define wei 8 //定义棋盘维度
typedef struct point //棋盘上的点
{
int x;
int y;
};
int qipan[wei][wei] = { 0 };
point pgo[8] = { {1,2},{1,-2},{-1,2},{-1,-2},{2,1},{2,-1},{-2,1},{-2,-1} }; //可行走方向集合
int bu = 0;
void MA(point p)
{
int x = p.x;
int y = p.y;
//if (qipan[x][y] != 0)
//return;
if (qipan[x][y] == 0)
{
bu++;
qipan[x][y] = bu;
cout << "第 " << bu << " 步 ,到了" << x+1 << " ," << y+1 << endl;
for (int i = 0; i < 8; i++)
{
point pp;
pp.x = x +