All pastes #340950 Raw Edit

Someone

public cpp v1 · immutable
·published 2007-02-05 04:33 UTC
rendered paste body
// knight.cpp : Defines the entry point for the console application.//#include<iostream.h>#include<conio.h>#include<iomanip.h>//using std::cout;//using std::endl;//using std::getch;/* Knight Tour */  const int size = 8;  void initialization();  void print();  void Knight ( int times, int row, int col );  int K[size][size];  int weight[size][size];  bool check( int row, int col);  int move_col[] = {-2, -1, +1, +2, +2, +1, -1, -2};  int move_row[] = {+1, +2, +2, +1, -1, -2, -2, -1};  int index;void initialization(){	int i,j;    index = 0;	// Initialize chess table    for ( i=0; i < size; i++)    {        for ( j=0; j < size; j++)        {            K[i][j] = 0;			weight[i][j] = 0;        }    }	// Calculate chess table's WEIGHT	for ( i=0; i < size; i++)    {        for ( j=0; j < size; j++)        {            K[i][j] = 0;        }    }}bool check ( int row, int col ){    if ( row > 7 || row < 0 || col > 7 || col < 0 || K[row][col] != 0 )        return false;    else        return true;}void print (){    index++;    cout << " Let's go Knight ^^" << endl;    cout << " The : "<< index << "th"<< endl;    for ( int i = 0; i < size; i++ )    {        for ( int j = 0; j < size; j++ )        {              cout << setw(3) << K[i][j] ;        }		cout << endl;    }}void Knight ( int times, int row, int col){	int next_row, next_col;	K[row][col] = times + 1; 	//cout << "times = " << times << endl;	if ( times >= 63 )	{		cout << "-----------------------" << endl;		print();		getch();	}	else	{		for ( int i = 0; i < 8; i++ )  		{			//cout << " row : " << row << endl;			//cout << " col : " << col << endl;			next_col = col + move_col[i];			next_row = row + move_row[i];			if (check( next_row,next_col ))			{ 				Knight (times+1, next_row, next_col);			}		} 	}                 	K[row][col] = 0;}                  void main(){   initialization();   Knight (0,0,0);   getch();}