help! anyone here with a knight's tour turbo c source code? please email me at [email protected] really am desperate!! thanks!!
help! anyone here with a knight's tour turbo c source code? please email me at [email protected] really am desperate!! thanks!!
Have you written any code yourself?
People here are willing to help you, but you have to help yourself first. Show that you've made an effort, and post the code you're stuck on.
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
this is the best i could do.. please help.. this program doesn't work ryt... i cannot test whether a move is valid or there still is a possible path for me to display its a game over or not
[edit]Code tags added by Hammer.Code:/*#include <stdio.h> #include <stdlib.h> main(){ int x,y,inputx,inputy,ctr1,ctr2,land=1,space[8][8],possible; for(ctr1=1;ctr1<=8;ctr1++) for(ctr2=1;ctr2<=8;ctr2++) space[ctr1][ctr2]=NULL; clrscr(); randomize(); x=random(8)+1; y=random(8)+1; for(ctr1=15;ctr1<=23;ctr1++) for(ctr2=3;ctr2<=10;ctr2++){ gotoxy(ctr1+(ctr1+1),ctr2); printf("|");} do{ gotoxy(1,1); printf("x: %d\ny: %d",x,y); gotoxy(1,3); printf(" "); gotoxy(1,5); printf(" "); possible=0; if(space[x+2][y+1]==NULL) possible+=1; if(space[x+2][y-1]==NULL) possible+=1; if(space[x-2][y+1]==NULL) possible+=1; if(space[x-2][y-1]==NULL) possible+=1; if(space[x+1][y+2]==NULL) possible+=1; if(space[x+1][y-2]==NULL) possible+-1; if(space[x-1][y+2]==NULL) possible+-1; if(space[x-1][y-2]==NULL) possible+-1; if(possible!=0){ gotoxy(30+(x*2),y+2); printf("*"); space[x][y]=land;} if(possible==0) break; do{ do{ gotoxy(1,3); printf("\nenter x-coordinate: "); gotoxy(21,4); scanf("%d",&inputx);} while(x>8); do{ gotoxy(1,5); printf("enter y-coordinate: "); gotoxy(21,5); scanf("%d",&inputy);} while(y>8); possible=0; if(inputx==x+2&&inputy==y+1) possible+-1 if(inputx==x+2&&inputy==y-1) possible+-1 if(inputx==x-2&&inputy==y+1) possible+-1 if(inputx==x-2&&inputy==y-1) possible+-1 if(inputx==x+1&&inputy==y+2) possible+-1 if(inputx==x+1&&inputy==y-2) possible+-1 if(inputx==x-1&&inputy==y+2) possible+-1 if(inputx==x-1&&inputy==y-2) possible+-1} while(space[x][y]!=NULL&&possible==0); land++;} while(land!=64); clrscr(); for(ctr1=0;ctr1<8;ctr1++) for(ctr2=0;ctr2<8;ctr2++) printf("\nspace[%d][%d]: %d",ctr1,ctr2,space[ctr1][ctr2]) ; getch(); }*/
not just a homework bro.. it's a case study...
Good lord! Use code tags! No one wants to read that crap!
[code]
Your code here...
[/code]
Quzah.
Hope is the first step on the road to disappointment.
What Quzah was not so tactfulling saying was:
In the furture please use Code Tags. They make your code MUCH easier to read and people will be much more likely to help you if you do. And they'll be happy about helping you
Information on code tags may be found at the link on my signature.
(Hammer added them for you this time. Thank you Hammer from both of us)
Well since I have nothing better to do...
1) Please use more than one space of indentation. That's a nightmare to read.
2) There's an easier way to set your array to whatever you want.
This could be written:Code:for(ctr1=1;ctr1<=8;ctr1++) for(ctr2=1;ctr2<=8;ctr2++) space[ctr1][ctr2]=NULL;
memset( space, 0, 64 );
Or, even simpler, at creation time:
int space[8][8] = {0};
3) You use multiple non-ANSI function, which is fine, if you include the correct headers, and if you don't want your program to be portable. If you don't care about portability, by all means. Functions in question:
randomize( )
random( )
gotoxy( )
4) There's a much easier way to check if your move is in bounds:
to_x, to_y;
to_x = at_x + move_x;
to_y = at_y + move_y;
if( to_x < 0 || to_x > 7 || to_y < 0 || to_y > 7 )
... out of bounds...
Ah. Phone call. Time to get back to work...
Quzah.
Hope is the first step on the road to disappointment.
The knight's tour problem is a classic recursive problem. Check some search engines or a data structures book to help. You can write the code you have now - in a cleaner and and more consise way.
Mr. C
sorry bout that!Code:/*#include <stdio.h> #include <stdlib.h> main(){ int x,y,inputx,inputy,ctr1,ctr2,land=1,space[8][8],pos sible; for(ctr1=1;ctr1<=8;ctr1++) for(ctr2=1;ctr2<=8;ctr2++) space[ctr1][ctr2]=NULL; clrscr(); randomize(); x=random(8)+1; y=random(8)+1; for(ctr1=15;ctr1<=23;ctr1++) for(ctr2=3;ctr2<=10;ctr2++){ gotoxy(ctr1+(ctr1+1),ctr2); printf("|");} do{ gotoxy(1,1); printf("x: %d\ny: %d",x,y); gotoxy(1,3); printf(" "); gotoxy(1,5); printf(" "); possible=0; if(space[x+2][y+1]==NULL) possible+=1; if(space[x+2][y-1]==NULL) possible+=1; if(space[x-2][y+1]==NULL) possible+=1; if(space[x-2][y-1]==NULL) possible+=1; if(space[x+1][y+2]==NULL) possible+=1; if(space[x+1][y-2]==NULL) possible+-1; if(space[x-1][y+2]==NULL) possible+-1; if(space[x-1][y-2]==NULL) possible+-1; if(possible!=0){ gotoxy(30+(x*2),y+2); printf("*"); space[x][y]=land;} if(possible==0) break; do{ do{ gotoxy(1,3); printf("\nenter x-coordinate: "); gotoxy(21,4); scanf("%d",&inputx);} while(x>8); do{ gotoxy(1,5); printf("enter y-coordinate: "); gotoxy(21,5); scanf("%d",&inputy);} while(y>8); possible=0; if(inputx==x+2&&inputy==y+1) possible+-1 if(inputx==x+2&&inputy==y-1) possible+-1 if(inputx==x-2&&inputy==y+1) possible+-1 if(inputx==x-2&&inputy==y-1) possible+-1 if(inputx==x+1&&inputy==y+2) possible+-1 if(inputx==x+1&&inputy==y-2) possible+-1 if(inputx==x-1&&inputy==y+2) possible+-1 if(inputx==x-1&&inputy==y-2) possible+-1} while(space[x][y]!=NULL&&possible==0); land++;} while(land!=64); clrscr(); for(ctr1=0;ctr1<8;ctr1++) for(ctr2=0;ctr2<8;ctr2++) printf("\nspace[%d][%d]: %d",ctr1,ctr2,space[ctr1][ctr2]) ; getch(); }*/
i'm supposed to pass this in 2 days time and i still have no idea how to make this.. please help me.. thanks..
Free the weed!! Class B to class C is not good enough!!
And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi
anyone who knows what is the super move on knight's move
it is the movement pattern that is applicable anywhere u start on the board.. please help.. thanks
This is way off topic, but if you run the following knight's tour, place a dot at each point and connect the dots across legal moves you should end up with a 4D hypercube.
d8, b7, a5, b3, d2, f3, g5, f7, d6, c4, e5, c6, d4, e6, c5, e4
-Prelude
My best code is written with the delete key.
Good evening, I ask you to help me with the program on this topic
if you honestly need as soon as possible
Chess horse