Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <string>
- using namespace std;
- int checked_positions[8][8];
- int counter=0;
- int pos_x[8]= {-2, -1, 1, 2, 2, 1, -1, -2};
- int pos_y[8]= {1, 2, 2, 1, -1, -2, -2, -1};
- int chess(int tab[][8], int init_x, int init_y, int prev_x, int prev_y, int over)
- {
- int value;
- if(over > 1)
- {
- if(init_x == 6 && init_y == 6)
- {
- char X = init_x;
- X = X+65;
- cout<<"victory"<<endl;
- tab[init_x][init_y]=2;
- cout<<"("<<X<<", "<<init_y+1<<")"<<endl;
- return 8;
- }
- else
- {
- for(int i=0; i<8; i++)
- {
- int x = init_x+pos_x[i];
- int y = init_y+pos_y[i];
- if(x!=prev_x && y!=prev_y)
- if(x<8 && x>0 && y<8 && y>0)
- {
- value = chess(tab, x, y, init_x, init_y, --over);
- if(value == 8)
- {
- char X = init_x;
- X = X+65;
- tab[init_x][init_y]=1;
- cout<<"("<<X<<", "<<init_y+1<<")"<<endl;
- return 8;
- }
- }
- }
- }
- }
- return 0;
- }
- int main()
- {
- int tab[8][8];
- for(int i = 0; i < 8; i++)
- {
- for(int j = 0; j < 8; j++)
- {
- tab[i][j]=0;
- }
- }
- //start 3,3 end 6,6
- for(int i = 0; i < 8; i++)
- {
- for(int j = 0; j < 8; j++)
- {
- cout<<tab[i][j]<<" ";
- }
- cout<<endl;
- }
- int x, y;
- cout<<"START POSITION:"<<endl;
- cout<<"y:";
- cin>>y;
- cout<<"x:";
- cin>>x;
- x--;
- y--;
- tab[y][x]=1;
- chess(tab, y, x, y, x, 10);
- for(int i = 0; i < 8; i++)
- {
- for(int j = 0; j < 8; j++)
- {
- cout<<tab[i][j]<<" ";
- }
- cout<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement