Greetings guys I ask to help with the program which should make:
To find the minimum number of chess horses on a chessboard such which should hold under fight all a board and draw their arrangement!!
Very much I ask to help as soon as possible!!
Greetings guys I ask to help with the program which should make:
To find the minimum number of chess horses on a chessboard such which should hold under fight all a board and draw their arrangement!!
Very much I ask to help as soon as possible!!
Yes but the matter is that the program is very long compiled about 6 hours and many errors and to eliminate them very long as process there are 6 hours!!
And one more my program is written on C and it is necessary to me to write it on With, but also not badly it to write on C++,
Better on C
Code:#include "stdafx.h" #include <stdio.h> #include <stdlib.h> #include <string.h> #define N 64 char enabled[] ="10"; char result[5]; char A[5]; char enabled_cnt[] = { 14,50}; void generate(char *pos); void f(int A[N]); void output(char A[N]); char B[N]; int right(char *B); void ris(char *A); void generate(char *pos) { int n; int printflag = 1; *pos = 0; for(n = 0; enabled[n]; n++) { if(enabled_cnt[n] > 0) { *pos = enabled[n]; enabled_cnt[n]--; generate(pos + 1); enabled_cnt[n]++; printflag = 0; } } if(printflag) { if(int g=right(B)) output(B); // printf("%s\n", result); } } int main() { generate(A); } void output(char A[N]) { for(int i=0; i<N; i++) printf("%c", A[i]); printf("\n"); } void ris(char *A) { for(int i=0; i<64; i++) B[i]='0'; for(int a=0; a<64; a++) { int i=0, j=0; if (A[a]=='1') { B[a]='!'; if((a-11)>=0) { if(B[a-11]!='!') B[a-11]='*'; if(B[a-9]!='!') B[a-9]='*'; if(B[a-7]!='!') B[a-7]='*'; if(B[a-3]!='!') B[a-3]='*'; } else { if((a-9)>=0) { if(B[a-9]!='!') B[a-9]='*'; if(B[a-7]!='!')B[a-7]='*'; if(B[a-3]!='!') B[a-3]='*'; } else { if((a-7)>=0) { if(B[a-7]!='!') B[a-7]='*'; if(B[a-3]!='!') B[a-3]='*'; } else { if((a-3)>=0) if(B[a-3]!='!') B[a-3]='*'; } } } if((a+11)<=N) { if(B[a+11]!='!') B[a+11]='*'; if(B[a+9]!='!') B[a+9]='*'; if(B[a+7]!='!') B[a+7]='*'; if(B[a+3]!='!') B[a+3]='*'; } else { if((a+9)<=N) { if(B[a+9]!='!') B[a+9]='*'; if(B[a+7]!='!') B[a+7]='*'; if(B[a+3]!='!') B[a+3]='*'; } else { if((a+7)<=N) { if(B[a+7]!='!') B[a+7]='*'; if(B[a+3]!='!') B[a+3]='*'; } else { if((a+3)<=N) if(B[a+3]!='!') B[a+3]='*'; } } } } } } int right(char *B) { ris(A); int a=0, b; for(int i=0; i<N; i++) { if (B[i]=='0') { a++; } } if(a==0) b=1; else b=0; return b; }
Last edited by Salem; 12-22-2010 at 12:47 PM. Reason: [code][/code] tags go around the code!
Line 37 has a compile error of "expected expression before int:" when I compiled in C99 mode.
If it takes 6 hours to compile and your program is in parts, I suggest you compile those parts seperately and fix those errors within those parts. The compiler is our friend. It may not pick up logic errors but it will pick up most syntax and expression errors.
I think he meant that it takes 6 hours to execute. He's probably using a brute force approach (though I can't make sense of the code at all), and it's giving bad output for some unknown reason.If it takes 6 hours to compile
Consider this post signed
Guys I know about these errors and I can not correct them therefore and I address to you!
Can offer you pair of ideas how to alter this program simply I 3 nights I do not sleep all I write it and I write.... But to check up errors it is necessary a heap of time
You do not have ideas on this problem about chess horses??
I'm not even clear what problem you're trying to solve. Are you trying to do Knight's Tour?
Quzah.
Hope is the first step on the road to disappointment.
The problem is: on a chess board to place the smallest number of horses that they had a blow all the board
tasks:
programa to put on the screen is the smallest number of chess horses
and drew their placement
line 37, take the "int" out of the if statement and add int g; where you have other variable declared. It will then compile correctly in C99. As for what the program is supposed to do, I have no idea. It started running and the cursor just blinked. Any Idea what your output is supposed to be?
I have no idea what is being said. Else I might give it a try.
I know the correct answer and the location of horses, but when it comes to software I do not know how to write all that I could write the above
here is the solution
14 horses
...and the approximate map
********
****++**
*++*++**
**+*****
********
**++*++*
**+**++*
********
*-cell which keeps the horse under attack
+ - horse
If anyone can write a program that will be a display on the screen would be very grateful
Your solution has a flaw. The knight in the third row, second column, isn't covered by any knights. That means that square isn't able to be attacked. Being on a square in chess doesn't mean that square can be attacked.
Quzah.
Hope is the first step on the road to disappointment.
Sounds like you want the positions of the minimum number of knights that would make all remaining squares accessible by one move from any of the knights.