Advertisement
Guest User

Untitled

a guest
Dec 17th, 2013
294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.58 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int ruch(int tab[12][12], int pozx, int pozy, int licznik)
  5. {
  6.     tab[pozx][pozy]=licznik;
  7.  
  8. printf("%d ",licznik);
  9.  
  10.     if(tab[pozx+2][pozy+1]==0){return ruch(tab,pozx+2,pozy+1,licznik+1);}
  11.     else
  12.     {
  13.         if(tab[pozx+2][pozy-1]==0){return ruch(tab,pozx+2,pozy-1,licznik+1);}
  14.         else
  15.         {
  16.             if(tab[pozx+1][pozy+2]==0){return ruch(tab,pozx+1,pozy+2,licznik+1); }
  17.             else
  18.             {
  19.                 if(tab[pozx+1][pozy-2]==0){return ruch(tab,pozx+1,pozy-2,licznik+1);}
  20.                 else
  21.                 {
  22.                     if(tab[pozx-2][pozy+1]==0){return ruch(tab,pozx-2,pozy+1,licznik+1);}
  23.                     else
  24.                     {
  25.                         if(tab[pozx-2][pozy-1]==0){return ruch(tab,pozx-2,pozy-1,licznik+1);}
  26.                         else
  27.                         {
  28.                             if(tab[pozx-1][pozy+2]==0){return ruch(tab,pozx-1,pozy+2,licznik+1);}
  29.                             else
  30.                             {
  31.                                 if(tab[pozx-1][pozy-2]==0){return ruch(tab,pozx-1,pozy-2,licznik+1);}
  32.                                 else
  33.                                     {
  34.                                         if(licznik==64) //nie weszlem
  35.                                         {
  36.                                             for(int i=2;i<10;i++)
  37.                                             {   printf("\n");
  38.                                                 for(int j=2;j<10;j++)
  39.                                                 {
  40.                                                     printf("%4d",tab[i][j]);
  41.                                                 }
  42.                                             }
  43.                                         }else
  44.                                         {printf("\nczemu nie potrafi zawrocic?!");
  45.                                             tab[pozx][pozy] = 0;
  46.                                             return 0;
  47.                                         }
  48.  
  49.                                     }
  50.                             }
  51.                         }
  52.                     }
  53.                 }
  54.             }
  55.         }
  56.     }
  57.  
  58. }
  59.  
  60. int main()
  61. {
  62.     int tab[12][12];
  63.  
  64.        for(int i=0;i<12;i++)
  65.        {
  66.            for(int j=0;j<12;j++)
  67.            {
  68.                tab[i][j] = 1;
  69.            }
  70.        }
  71.  
  72.        for(int i=2; i<10; i++)
  73.     {
  74.  
  75.         for(int j=2; j<10; j++)
  76.         {
  77.             tab[i][j] = 0;
  78.  
  79.         }
  80.     }
  81.  
  82.     printf("\n%d",ruch(tab,2,2,1));
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91. return 0;
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement