I know what Im asking here is too much work, but I want to give a try, can someone, translate this code for
java. I already try to work with something, but I always get stuck with a lot of things, the only I could do right is the array for the list. Ok, here is all I have for now.
-----------------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
/* List of valid moves a knight can make from any square */
int [] [] list = {{0, 0, 0, 0, 0, 0, 0, 0, 0, },
{11, 18, 0, 0, 0, 0, 0, 0, 0}, //1
{12, 17, 19, 0, 0, 0, 0, 0, 0}, //2
{9, 13, 18, 20, 0, 0, 0, 0, 0}, //3
{10, 14, 19, 21, 0, 0, 0, 0, 0}, //4
{11, 15, 20, 22, 0, 0, 0, 0, 0}, //5
{12, 16, 21, 23, 0, 0, 0, 0, 0}, //6
{13, 22, 24, 0, 0, 0, 0, 0, 0}, //7
{14, 23, 0, 0, 0, 0, 0, 0, 0}, //8
{3, 19, 26, 0, 0, 0, 0, 0, 0}, //9
{4, 20, 25, 27, 0, 0, 0, 0, 0}, //10
{1, 5, 17, 21, 26, 28, 0, 0, 0}, //11
{2, 6, 18, 22, 27, 29, 0, 0, 0}, //12
{3, 7, 19, 23, 28, 30, 0, 0, 0}, //13
{4, 8, 20, 24, 29, 31, 0, 0, 0}, //14
{5, 21, 30, 32, 0, 0, 0, 0, 0}, //15
{6, 22, 31, 0, 0, 0, 0, 0, 0}, //16
{2, 11, 27, 34, 0, 0, 0, 0, 0}, //17
{1, 3, 12, 28, 33, 35, 0, 0, 0}, //18
{2, 4, 9, 13, 25, 29, 34, 36, 0}, //19
{3, 5, 10, 14, 26, 30, 35, 37, 0}, //20
{4, 6, 11, 15, 27, 31, 36, 38, 0}, //21
{5, 7, 12, 16, 28, 32, 37, 39, 0}, //22
{6, 8, 13, 29, 38, 40, 0, 0, 0}, //23
{7, 14, 30, 39, 0, 0, 0, 0, 0}, //24
{10, 19, 35, 42, 0, 0, 0, 0, 0}, //25
{9, 11, 20, 36, 41, 43, 0, 0, 0}, //26
{10, 12, 17, 21, 33, 37, 42, 44, 0}, //27
{11, 13, 18, 22, 34, 38, 43, 45, 0}, //28
{12, 14, 19, 23, 35, 39, 44, 46, 0}, //29
{13, 15, 20, 24, 36, 40, 45, 47, 0}, //30
{14, 16, 21, 37, 46, 48, 0, 0, 0}, //31
{15, 22, 38, 47, 0, 0, 0, 0, 0}, //32
{18, 27, 43, 50, 0, 0, 0, 0, 0}, //33
{17, 19, 28, 44, 49, 51, 0, 0, 0}, //34
{18, 20, 25, 29, 41, 45, 50, 52, 0}, //35
{19, 21, 26, 30, 42, 46, 51, 53, 0}, //36
{20, 22, 27, 31, 43, 47, 52, 54, 0}, //37
{21, 23, 28, 32, 44, 48, 53, 55, 0}, //38
{22, 24, 29, 45, 54, 56, 0, 0, 0}, //39
{23, 30, 46, 55, 0, 0, 0, 0, 0}, //40
{26, 35, 51, 58, 0, 0, 0, 0, 0}, //41
{25, 27, 36, 52, 57, 59, 0, 0, 0}, //42
{26, 28, 33, 37, 49, 53, 58, 60, 0}, //43
{27, 29, 34, 38, 50, 54, 59, 61, 0}, //44
{28, 30, 35, 39, 51, 55, 60, 62, 0}, //45
{29, 31, 36, 40, 52, 56, 61, 63, 0}, //46
{30, 32, 37, 53, 62, 64, 0, 0, 0}, //47
{31, 38, 54, 63, 0, 0, 0, 0, 0}, //48
{34, 43, 59, 0, 0, 0, 0, 0, 0}, //49
{33, 35, 44, 60, 0, 0, 0, 0, 0}, //50
{34, 36, 41, 45, 57, 61, 0, 0, 0}, //51
{35, 37, 42, 46, 58, 62, 0, 0, 0}, //52
{36, 38, 43, 47, 59, 63, 0, 0, 0}, //53
{37, 39, 44, 48, 60, 64, 0, 0, 0}, //54
{38, 40, 45, 61, 0, 0, 0, 0, 0}, //55
{39, 46, 62, 0, 0, 0, 0, 0, 0}, //56
{42, 51, 0, 0, 0, 0, 0, 0, 0}, //57
{41, 43, 52, 0, 0, 0, 0, 0, 0}, //58
{42, 44, 49, 53, 0, 0, 0, 0, 0}, //59
{43, 45, 50, 54, 0, 0, 0, 0, 0}, //60
{44, 46, 51, 55, 0, 0, 0, 0, 0}, //61
{45, 47, 52, 56, 0, 0, 0, 0, 0}, //62
{46, 48, 53, 0, 0, 0, 0, 0, 0}, //63
{47, 54, 0, 0, 0, 0, 0, 0, 0}} //64
;
void play( int );
void winner( void );
int board[65] = {0}; /* the Chess board */
int moves[65]; /* list of moves */
int k = 0; /* move counter */
long wincount = 0; /* winning counter */
long iterl = 0; /* iteration counter */
long iterh = 0; /* iteration counter */
void main(int argc, char *argv[])
{
if (argc != 2)
{
printf("\nPlease provide the starting square: 1 to 64\n");
return;
}
if (atoi(argv[1]) < 1) return;
if (atoi(argv[1]) > 64) return;
play(atoi(argv[1]));
printf("%ld%ld Total Iterations!\n", iterh, iterl);
printf("%ld Total Winning combinations!\n", wincount);
}
void play( int square )
{
int i;
if (++iterl == (long) 100000000)
{
iterl = 0; iterh++;
if (((iterh/10)*10) == iterh)
printf("%ld Billion iterations %ld Winners\n",iterh/10, wincount);
else
printf("%ld Hundred Million iterations %ld Winners\n",iterh, wincount);
}
board[square] = 1;
moves[k++] = square;
if (k == 64)
{
/*
winner();
*/
wincount++;
board[square] = 0;
k--;
return;
}
for (i = 0; list[square][i] != 0; i++)
{
if (board[list[square][i]] == 0)
play(list[square][i]);
}
board[square] = 0;
k--;
return;
}
/* Print the winning info */
void winner( void )
{
/*
wincount++;
printf("Winner %d iteration %ld%ld\n", wincount, iterh, iterl);
int i;
for (i = 0; i < 16; i++) printf("%2d ",moves[i]);
printf("\n");
for (i = 16; i < 32; i++) printf("%2d ",moves[i]);
printf("\n");
for (i = 32; i < 48; i++) printf("%2d ",moves[i]);
printf("\n");
for (i = 48; i < 64; i++) printf("%2d ",moves[i]);
printf("\n\n");
}
-------------------------------------------------------------------------
I hope someone can help me, I really need this.