Coding Challenge #2! (115)

111 Name: #!/usr/bin/anonymous : 2008-05-01 07:56 ID:ohi6hRRc

//Coded by drwho
// Update: Thanks to a friend from 2600 I was able to shorten the code for the
// chess board. Now that is real hacking!
// Knight's Tour program where moves are base on on horizontal and vertical
// arrays and are accessed by a random number generator. This does only 64
// moves but can be increased. the 0 on the board is the night
// I didn't know how to get C to print out both characters and integers
// or else I would have made the knight k (%c didn't work and just displays
// weird shit). Question? I idle in #4-ch on synirc so come by
// http://en.wikipedia.org/wiki/Knight's_tour

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <windows.h>

int main(int argc, char *argv[])
{
int j, i, currentrow, currentcolumn, lastmover, lastmovec, counta, moves, check;
static movenumber;
int horizontal[8]={2,1,-1,-2,-2,-1,1,2};
int vertical[8]={-1,-2,-2,-1,1,2,2,1};
int board[8][8]={

     {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}
};

currentrow = 3;
currentcolumn = 3;
board[currentrow][currentcolumn] = 0;
moves = 0;
check = 0;
//time seed
srand ( time(NULL) );
for (counta = 1; counta < 65; counta++){

printf("Knights Round Program\n");
// random move number with time seed
movenumber = rand() % 8;
currentrow += horizontal[movenumber];
currentcolumn += vertical[movenumber];

if(currentrow > 8 || currentrow < 0 || currentcolumn > 8 || currentcolumn < 0){
currentrow = lastmover;
currentcolumn = lastmovec;
}
check = board[currentrow][currentcolumn];
if(check == 0){ board[lastmover][lastmovec]; }
else{board[currentrow][currentcolumn] = 0;}

// The Board
printf("\n");
for(i=0;i<8;i++) { for(j=0;j<8;j++){printf("%d", board[i][j]);} printf("\n"); }
printf("\n");
printf("Row: %d | Column: %d\n", currentrow, currentcolumn);
if(currentrow != lastmover && currentcolumn != lastmovec){moves++;}
lastmover = currentrow;
lastmovec = currentcolumn;
printf("Moves: %d\n", moves);

if(counta == 64){
printf("Knights Round Program\n");
printf("\n");
for(i=0;i<8;i++) { for(j=0;j<8;j++){printf("%d", board[i][j]);} printf("\n"); }
printf("\n");
printf("Row: %d | Column: %d\n", currentrow, currentcolumn);
printf("Moves: %d\n", moves);
system("PAUSE");
return 0;
}

//Time Delay
sleep(1000);
system("cls");

}

}

Name: Link:
Leave these fields empty (spam trap):
More options...
Verification: