Entrainements + fin TP structures
This commit is contained in:
43
DEV1.1/SAé/test.c
Normal file
43
DEV1.1/SAé/test.c
Normal file
@@ -0,0 +1,43 @@
|
||||
# include <stdio.h>
|
||||
# include <stdlib.h>
|
||||
int deplacement_possible(int joueur, int grille[9][9], int taille_grille) {
|
||||
/* Renvoie 1 si un déplacement est possible, 0 sinon */
|
||||
int i,j;
|
||||
int pos_joueur_x, pos_joueur_y;
|
||||
|
||||
for (i = 0; i != taille_grille; i++) {
|
||||
for (j = 0; j != taille_grille; j++) {
|
||||
if (grille[i][j] == joueur) {
|
||||
pos_joueur_x = i;
|
||||
pos_joueur_y = j;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (i = (pos_joueur_x-1); i != (pos_joueur_x+2); i++) {
|
||||
for (j = (pos_joueur_y-1); j != (pos_joueur_y+2); j++) {
|
||||
printf("%d ; %d\n", i, j);
|
||||
if (grille[i][j] == 0 && i < taille_grille && j < taille_grille && i >= 0 && j >= 0) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
int grille[9][9] = {
|
||||
{0,2,0},
|
||||
{3,3,4},
|
||||
{0,0,1},
|
||||
};
|
||||
int taille_grille = 3;
|
||||
if (deplacement_possible(1, grille, taille_grille)) {
|
||||
printf("Possible.\n");
|
||||
}
|
||||
else {
|
||||
printf("Impossible. \n");
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
Reference in New Issue
Block a user