Chess Game in C

Asked

Viewed 860 times

0

I’m learning C. My college professor asked to do a program that reads a horse’s position in the chess game and prints ALL the possibilities of movement. I’m racking my brain to know how I’ll know the letter and the number the user asked for?

  • Use an array to map the board to the position the user asked for use a simple variable since the intention is to map the possibilities of the movement of a piece. Have and good luck in parallel processing matter if you have in course (;

  • Thank you for the reply.

1 answer

2

// criar o tabuleiro
char tabuleiro[8][8];

// Pede ao usuário informar a posição da peça que deseja mover
printf("Digite a linha onde esta sua peca: ");
scanf("%d", &linAtual);
printf("Digite a coluna onde esta sua peca: ");
scanf("%d", &colAtual);

// Pede ao usuário informar para onde deseja que a peça vá
printf("Digite a linha desejada: ");
scanf("%d", &linDes);
printf("Digite a colun desejada: ");
scanf("%d", &colDes);

// Você pode usar essas informações do usuário pra localizar e mover a peça
char peca = tabuleiro [colAtual][linAtual];
tabuleiro [colAtual][linAtual] = " ";
tabuleiro [colDes][linDes]= peca;

Then guy you will have to think about how to differentiate the pieces(you can get an idea by the code above) and you will also have to define the rules of movement (very if and I) good luck.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.