Advertisement
Mary_99

LAB 7

Jan 30th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.82 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <string>
  4. using namespace std;
  5.  
  6. int checked_positions[8][8];
  7. int counter=0;
  8. int pos_x[8]= {-2, -1, 1, 2, 2, 1, -1, -2};
  9. int pos_y[8]= {1, 2, 2, 1, -1, -2, -2, -1};
  10.  
  11.  
  12.  
  13. int chess(int tab[][8], int init_x, int init_y, int prev_x, int prev_y, int over)
  14. {
  15.     int value;
  16.     if(over > 1)
  17.     {
  18.     if(init_x == 6 && init_y == 6)
  19.  
  20.     {
  21.  
  22.         char X = init_x;
  23.         X = X+65;
  24.         cout<<"victory"<<endl;
  25.         tab[init_x][init_y]=2;
  26.         cout<<"("<<X<<", "<<init_y+1<<")"<<endl;
  27.         return 8;
  28.     }
  29.     else
  30.     {
  31.     for(int i=0; i<8; i++)
  32.     {
  33.         int x = init_x+pos_x[i];
  34.         int y = init_y+pos_y[i];
  35.         if(x!=prev_x && y!=prev_y)
  36.         if(x<8 && x>0 && y<8 && y>0)
  37.         {
  38.  
  39.             value = chess(tab, x, y, init_x, init_y, --over);
  40.             if(value == 8)
  41.             {
  42.                 char X = init_x;
  43.                 X = X+65;
  44.                 tab[init_x][init_y]=1;
  45.                 cout<<"("<<X<<", "<<init_y+1<<")"<<endl;
  46.                 return 8;
  47.             }
  48.         }
  49.     }
  50.     }
  51.     }
  52.     return 0;
  53. }
  54.  
  55.  
  56. int main()
  57. {
  58.     int tab[8][8];
  59.     for(int i = 0; i < 8; i++)
  60.     {
  61.         for(int j = 0; j < 8; j++)
  62.         {
  63.             tab[i][j]=0;
  64.         }
  65.     }
  66.  
  67.     //start 3,3 end 6,6
  68.     for(int i = 0; i < 8; i++)
  69.     {
  70.         for(int j = 0; j < 8; j++)
  71.         {
  72.             cout<<tab[i][j]<<" ";
  73.         }
  74.         cout<<endl;
  75.     }
  76.     int x, y;
  77.     cout<<"START POSITION:"<<endl;
  78.     cout<<"y:";
  79.     cin>>y;
  80.     cout<<"x:";
  81.     cin>>x;
  82.     x--;
  83.     y--;
  84.     tab[y][x]=1;
  85.     chess(tab, y, x, y, x, 10);
  86.     for(int i = 0; i < 8; i++)
  87.     {
  88.         for(int j = 0; j < 8; j++)
  89.         {
  90.             cout<<tab[i][j]<<" ";
  91.         }
  92.         cout<<endl;
  93.     }
  94.     return 0;
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement