帮我看看我的"骑士旅行"还能怎么改进.
#include <iostream.h>
#include <iomanip.h>
#include <conio>
const int horizontal[] = { 2, 1, -1, -2, -2, -1, 1, 2 } ;
const int vertical[] = { -1, -2, -2, -1, 1, 2, 2, 1 } ;
const int arraySize = 8 ;
int board[ arraySize ][ arraySize ] = { 0 } ;
int accessibility[ arraySize ][ arraySize ] =
{ { 2, 3, 4, 4, 4, 4, 3, 2 }, { 3, 4, 6, 6, 6, 6, 4, 3 },
{ 4, 6, 8, 8, 8, 8, 6, 4 }, { 4, 6, 8, 8, 8, 8, 6, 4 },
{ 4, 6, 8, 8, 8, 8, 6, 4 }, { 4, 6, 8, 8, 8, 8, 6, 4 },
{ 3, 4, 6, 6, 6, 6, 4, 3 }, { 2, 3, 4, 4, 4, 4, 3, 2 } } ;
int currentRow, currentColumn, counter = 1 ;
void choose( int &, int & ) ;
void printBoard( void ) ;
int main()
{
cout << "Input the start row: " ;
cin >> currentRow ;
cout << "Input the start column: " ;
cin >> currentColumn ;
board[ currentRow ][ currentColumn ] = counter ;
choose( currentRow, currentColumn ) ;
getch();
return 0 ;
}
void choose( int &row, int &col )
{
int best = 9, tempInt, num, tempRow, tempCol ;
bool canTravel = false ;
for ( int i = 0; i <= 7; i++ ) {
tempRow = row + horizontal[ i ] ;
tempCol = col + vertical[ i ] ;
tempInt = accessibility[ tempRow ][ tempCol ] ;
if ( tempRow < 0 || tempRow > 7 || tempCol < 0 || tempCol > 7 ) continue ;
if ( tempInt < best && 0 == board[ tempRow ][ tempCol ] ) {
best = tempInt ;
num = i ;
canTravel = true ;
}
}
if ( canTravel ) {
row += horizontal[ num ] ;
col += vertical[ num ] ;
if ( counter ++ <= 64 ) {
board[ row ][ col ] = counter ;
choose( row, col ) ;
}
}
else printBoard();
}
void printBoard( void )
{
for ( int i = 0; i < arraySize; i++ ) {
for ( int j = 0; j < arraySize; j++ ) {
cout.fill( '0' ) ;
cout << setw( 2 ) << board[ i ][ j ] << " " ;
}
cout << endl ;
}
cout << endl ;
}