课程实验要求做马踏棋盘的问题,并且我实现了设置阻塞棋子的功能
代码比较简单如下,注释已经写得很多了,基本上每条代码都有解释
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<math.h>
#pragma warning(disable:4996)
#define MAXN 10
#define STALL_PIECE 123
int board[MAXN][MAXN] = { 0 }; //define the board , 0 denotes that hasn't been traveld , 1 denotes the contrary
int moveHorizental[8] = { 2,1,-1,-2,-2,-1,1,2 };//move horizental , as well as Y
int moveVertical[8] = { 1,2,2,1,-1,-2,-2,-1 };//move vertical , as well as X
int stallPieceNumber; //number of stall piece
bool Check(int x, int y,int N);
/*
check wether the horse is out of extent
x and y is the current position of horse
N is the size of the board
if position(x,y) is walkable,return true , else return false
*/
void HorseTraversal(int thisX, int thisY, int N,int stepNumer);
/*
main function to solve the problem
thisX and thisY is the current position of horse
N is the size of t