how to write chess with these conditions?

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");
}
Last edited on
So you mean something like this?

White: qd5
Black: rf3
  a b c d e f g h 
8 * . . * . . * . 
7 . * . * . x . . 
6 . . * * * . . . 
5 * * * Q * x * * 
4 . . * * * . . . 
3 . x . x . r . . 
2 * . . * . . . . 
1 . . . * . . . . 
@dutch, yup, pretty sure that's what the outcome should look like:) but how to provide the possibility of entering data on 3 pieces in one code? i'm quite confused. i guess the example i gave isn't really relevant to my code
Last edited on
I assume you're only supposed to enter one piece for white and one piece for black. The choice of pieces is out of three: queen, rook, knight (why they leave out the bishop is anyone's guess).

As for the instruction "provide for the possibility of considering several situations in the process of the program", that presumably just means to loop until the user wants to quit.

Here's some more output from my program (I allow the bishop, too). I use 'N' for knight, since 'K' usually stands for the king. The white piece is uppercase, the black peice is lowercase, although they can be entered as either.

White: Rg4
Black: nc6
  a b c d e f g h 
8 . . . . . . * . 
7 . . . . . . * . 
6 . . n . . . * . 
5 . . . . . . * . 
4 * x * x * * R * 
3 . . . . . . * . 
2 . . . . . . * . 
1 . . . . . . * . 

White: Qd2
Black: rc8
  a b c d e f g h 
8 . . r x . . . . 
7 . . . * . . . . 
6 . . . * . . . * 
5 * . . * . . * . 
4 . * . * . * . . 
3 . . x * * . . . 
2 * * x Q * * * * 
1 . . x * * . . . 

White: Qg6
Black: be8
  a b c d e f g h 
8 . . . . b . * . 
7 . . . . . x * * 
6 * * x * * * Q * 
5 . . . . . * * x 
4 . . . . * . * . 
3 . . . * . . * . 
2 . . * . . . * . 
1 . * . . . . * . 

White: Qa6
Black: ra3
  a b c d e f g h 
8 x . * . . . . . 
7 x * . . . . . . 
6 Q * * * * * * * 
5 x * . . . . . . 
4 x . * . . . . . 
3 r . . x . . . . 
2 . . . . * . . . 
1 . . . . . * . . 

White: Nd4
Black: qc4
  a b c d e f g h 
8 . . . . . . . . 
7 . . . . . . . . 
6 . . x . x . . . 
5 . x . . . * . . 
4 . . q N . . . . 
3 . x . . . * . . 
2 . . x . x . . . 
1 . . . . . . . . 

White: Ng3
Black: rb6
  a b c d e f g h 
8 . . . . . . . . 
7 . . . . . . . . 
6 . r . . . . . . 
5 . . . . . * . * 
4 . . . . * . . . 
3 . . . . . . N . 
2 . . . . * . . . 
1 . . . . . * . * 

White: x

Topic archived. No new replies allowed.