Chess horse

This is a discussion on Chess horse within the C Programming forums, part of the General Programming Boards category; Greetings guys I ask to help with the program which should make: To find the minimum number of chess horses ...

  1. #1
    Registered User
    Join Date
    Dec 2010
    Posts
    10

    Question Chess horse

    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!!

  2. #2
    Registered User
    Join Date
    Jul 2010
    Posts
    178
    Quote Originally Posted by muted View Post
    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!!
    Have you done any code yourself? If so, why not post what you have and where your problem lies.

  3. #3
    Registered User
    Join Date
    Dec 2010
    Posts
    10

    Exclamation code

    Quote Originally Posted by csharp100 View Post
    Have you done any code yourself? If so, why not post what you have and where your problem lies.
    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!

  4. #4
    Registered User
    Join Date
    Jul 2010
    Posts
    178
    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.

  5. #5
    Just a pushpin. bernt's Avatar
    Join Date
    May 2009
    Posts
    426
    If it takes 6 hours to compile
    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.
    Consider this post signed

  6. #6
    Registered User
    Join Date
    Jul 2010
    Posts
    178
    Quote Originally Posted by bernt View Post
    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.
    I could not get it to run because of the compile error I mentioned earlier. Using MinGW with gcc in C99 mode.

  7. #7
    Registered User
    Join Date
    Dec 2010
    Posts
    10
    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??

  8. #8
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    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.

  9. #9
    Registered User
    Join Date
    Dec 2010
    Posts
    10
    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

  10. #10
    Registered User
    Join Date
    Jul 2010
    Posts
    178
    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?

  11. #11
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,831
    I have no idea what is being said. Else I might give it a try.

  12. #12
    Registered User
    Join Date
    Dec 2010
    Posts
    10
    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

  13. #13
    Registered User
    Join Date
    Dec 2010
    Posts
    10
    If anyone can write a program that will be a display on the screen would be very grateful

  14. #14
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    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.

  15. #15
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,831
    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.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. SDL Chess Game problem
    By Lesshardtofind in forum Game Programming
    Replies: 0
    Last Post: 07-02-2010, 04:49 PM
  2. Chess problem Horse
    By Cyberman86 in forum C Programming
    Replies: 18
    Last Post: 05-03-2009, 02:20 PM
  3. chess ai contest
    By Raven Arkadon in forum Contests Board
    Replies: 7
    Last Post: 07-09-2005, 06:38 AM
  4. Ultra chess engine contest
    By yodacpp in forum Projects and Job Recruitment
    Replies: 8
    Last Post: 11-21-2004, 06:58 AM
  5. Ultra chess engine
    By yodacpp in forum Game Programming
    Replies: 2
    Last Post: 11-19-2004, 11:33 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21