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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
| #include <stdio.h>
#include <stdlib.h>
#define TAILLE 5
typedef struct tJeton{
int nX;
int nY;
}tJeton;
typedef enum Bool {true=1, false=0}Bool;
void InitTab(int nTab[TAILLE][TAILLE]);
void Moving(int nTab[TAILLE][TAILLE], tJeton jeton, int nCpt);
void Warp(int nTab[TAILLE][TAILLE], tJeton jeton);
void Place(int nTab[TAILLE][TAILLE], tJeton jeton, int nCpt);
void Display(int nTab[TAILLE][TAILLE]);
Bool CaseIsVoid(int nTab[TAILLE][TAILLE], tJeton jeton);
int main()
{
int nTab[TAILLE][TAILLE];
int nCpt=2;
tJeton Jeton={3,2};
InitTab(nTab[TAILLE][TAILLE]);
nTab[3][2] = 1;
for (nCpt; nCpt < TAILLE; nCpt++)
{
Moving(nTab[TAILLE][TAILLE],Jeton,nCpt);
}
Display(nTab[TAILLE][TAILLE]);
return 0;
}
void InitTab(int nTab[TAILLE][TAILLE]){
for (int i = 0; i < TAILLE; ++i)
{
nTab[i][i] = 0;
}
}
void Warp(int nTab[5][5], tJeton jeton){
if (jeton.nX == 6){
jeton.nX = 1;
}
}
Bool CaseIsVoid (int nTab[TAILLE][TAILLE], tJeton jeton){
if (nTab[jeton.nX][jeton.nY]=0){
return true;
}else{
return false;
}
}
void Place(int nTab[5][5], tJeton jeton, int nCpt){
nTab[jeton.nX][jeton.nY]=nCpt;
}
void Moving(int nTab[5][5], tJeton jeton, int nCpt){
jeton.nX = jeton.nX+=1;
jeton.nY = jeton.nY-=1;
Warp(nTab, jeton);
if (CaseIsVoid(nTab[5][5],jeton )== true)
{
Place(nTab[5][5], jeton, nCpt);
}else{
jeton.nX = jeton.nX-=1;
jeton.nY = jeton.nY-=1;
Warp(nTab, jeton);
Place(nTab[5][5], jeton, nCpt);
}
}
void Display(int nTab[TAILLE][TAILLE]){
int cpt;
for (cpt = 0; 1 < 5; cpt++)
{
printf("%d\n",nTab[cpt,1]);
printf("%d\n",nTab[cpt,2]);
printf("%d\n",nTab[cpt,3]);
printf("%d\n",nTab[cpt,4]);
printf("%d\n",nTab[cpt,5]);
}
} |
Partager