Chess MD
seif ya termaunknown
c_cpp
2 months ago
1.2 kB
2
Indexable
Never
#include <iostream> using std::cin; using std::cout; int main() { int matrix[8][8] = {0}; int i, j; cout << "Entrer une position (i,j): \n"; cout << "\t i= "; cin >> i; cout << "\t j= "; cin >> j; int pos_bishop_x = i-1; int pos_bishop_y = 8-j; cout << "(bishop_x, bishop_y) = " << pos_bishop_x << " , " << pos_bishop_y << std::endl; for(int k = 0; k < 8; k++) { for(int h = 0; h < 8; h++) { /*if(j-1 >= k && i-1 >= h) matrix[j-1-k][i-1-h] if( (h+1 == last_i - 1 && k+1 == last_j - 1) || (h+1 == last_i + 1 && k+1 == last_j - 1) || (h+1 == last_i - 1 && k+1 == last_j + 1) || (h+1 == last_i + 1 && k+1 == last_j + 1) ) { matrix[k][h] = 1; if(last_i == 1 || last_j == 1) { last_i = i; last_j = j; } else { last_i = h+1; last_j = k+1; } }*/ int pos_x = h; int pos_y = 7-k; // cout << "(x, y) = " << pos_x << " , " << pos_y << std::endl; if(pos_bishop_y-pos_y == pos_bishop_x-pos_x || pos_y-pos_bishop_y == pos_bishop_x-pos_x) matrix[k][h] = 1; cout << " " << (k+1 == j && h+1 == i ? 8 : matrix[k][h]); } cout << std::endl; } return 0; }