1
I set up this code but as we know the bishop moves on the diagonals, but in my code he is moving straight... the "x" represents the houses that the bishop can pass. Can you tell me how to put the house on the diagonals?
#include <stdio.h>
int main(){
int linha, coluna, l, c;
printf("Movimento de um bispo no xadrez\n");;
printf("Digite a linha que o bispo se encontra: ");
scanf("%d", &linha);
printf("Digite a coluna que o bispo se encontra: ");
scanf("%d", &coluna);
printf("\nMovimentos possiveis:\n\n");
printf(" 1 2 3 4 5 6 7 8 \n");
printf(" -------------------------\n");
l = 1;
while(l <= 8){
printf("%3d |", l);
l++;
c = 1;
while(c <= 8){
if(l == linha && c == coluna){
printf(" o ");
}
if(l == linha || c == coluna){
printf(" x ");
}
else{
printf(" - ");
}
c++;
}
printf("\n");
}
return 0;
}
The most intuitive is to start from the position where the bishop is and navigate in each direction with a
for
. This is done only by modifying the increments in x and y or l and c if you want. In this case it would be +1 +1, +1 -1, -1 +1, -1 -1, for each direction respectively.– Isac
But as I was going to implement it in the code, I tried it here and I couldn’t
– Eduardo