主要代码清单:
#include "stdio.h"
#include "conio.h"
int board[8][8] ={
{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0}
};
int tile=0;
void chessBoard(int tr, int tc, int dr, int dc, int size)
{
int t=tile++,
s=size/2;
if (size==1) return;
if (dr<tr+s&&dc<tc+s)
chessBoard(tr,tc,dr,dc,s);
else {
board[tr+s-1][tc+s-1]=t;
chessBoard(tr,tc,tr+s-1,tc+s-1,s);}
if(dr <tr+s && dc >= tc+s)
chessBoard(tr,tc+s,dr,dc,s);
else {
board[tr+s-1][tc+s]=t;
chessBoard(tr,tc+s,tr+s-1,tc+s,s);}
if(dr >= tr+s&&dc<tc+s)
chessBoard(tr+s,tc,dr, dc,s);
else {
board[tr+s][tc+s-1]=t;
chessBoard(tr+s,tc,tr+s,tc+s-1,s);}
if(dr >= tr+s &&dc>=tc+s)
chessBoard(tr+s,tc+s,dr,dc,s);
else {
board[tr+s][tc+s]=t;
chessBoard(tr+s,tc+s,tr+s,tc+s,s);}
}
main()
{
int i ,j;
chessBoard(0,0,5,5,8);
for(i=0;i <8;i++)
{
for( j=0;j <8;j++) {
if(board[i][j]<10)
printf("0");
printf("%d",board[i][j]);
printf(" ");
}
printf( "\n");
}
getchar();
}