The chessboard is viewed as an 8x8 square character array. The natural numbers v1 and g1 are entered from the keyboard, which denote the numbers of the vertical (counting from left to right) and the horizontal (counting from bottom to top) for the square on which the white chess piece stands, and the numbers v2 and g2, which denote the corresponding coordinates of the second, black , figure.
Determine the squares that the first piece can go to so as not to be hit by the second. Provide for the possibility of entering data on such pieces: round (rook), queen, knight. The type of figure is set by the user, respectively, the letters R, Q, K.
After entering the data about each of the figures, display the chessboard, denoting the positions of the given figures on it with the corresponding letters, with the symbol "*" - the positions to which the first piece can be moved, with the symbol "x" - the positions of the first figure that are under attack, and the symbol "." - all other cells.
Provide for the possibility of considering several situations in the process of the program.
Ps: no structures
thanks in advance
here's a somewhat similar exercise but with a rook, a bishop and a pawn
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
#include <iostream>
using namespace std;
void main()
{
setlocale(LC_ALL, "Russian");
int T=0, C=0, P=0;
char t, c, p;
bool f;
int array[]={1,2,3,4,5,6,7,8};
char array_1[]={'a','b','c','d','e','f','g','h'};
for(int i=0; i<8; i++){
for(char j=0; j<8; j++)
{
cout << " . " << " " ;
}
cout<<endl;
}
cout<<"Введите координаты Туры"<<endl; // enter rook's coordinates
cout<<"Введите число: "<<endl; // enter a number
cin>>T;
cout<<"Введите букву: "<<endl; //enter a letter
cin>>t;
cout<<"Введите координаты Слона"<<endl; //enter bishop's coordinates
cout<<"Введите число: "<<endl; // ent a num
cin>>C;
cout<<"Введите букву: "<<endl; // ent a letter
cin>>c;
cout<<"Введите координаты Пешки"<<endl; // pawn's coordinates
cout<<"Введите число: "<<endl; //number
cin>>P;
cout<<"Введите букву: "<<endl; //letter
cin>>p;
for(int i=0; i<8; i++){
for(char j=0; j<8; j++)
{
if(T==C && t==c || T==P && t==p || C==P && c==p) {cout<<"Координаты фигур совпадают!"<<endl;} // the coordinates match
if(array[i]==T && array_1[j]==t || array[i]==C && array_1[j]==c || array[i]==P && array_1[j]==p) cout << " * " << " " ;
else cout << " . " << " " ;
}
cout<<endl;
}
system("pause");
}
|