J'ai a faire Le jeu de la vie pour la rentrée et j'ai un probleme lorsque j'execute mon programme. Esce que quelqu'un aurait Le jeu de la vie en algo pour m'aider a ensuite faire mon C?![]()
J'ai a faire Le jeu de la vie pour la rentrée et j'ai un probleme lorsque j'execute mon programme. Esce que quelqu'un aurait Le jeu de la vie en algo pour m'aider a ensuite faire mon C?![]()
Hio,
Ben, l'algo est décrit par les règles du jeu.![]()
Bienvenue dans la communauté de DVP
Si tu veux une aide , expose simplement ce que tu as fait et compris (ou pas compris) sur la question posée et les problèmes sur lesquel tu bûtes.j'ai un probleme lorsque j'execute mon programme.
J'ai crée toutes mes fonctions me permettant d'initialiser mon monde de l'afficher suivant le pourcentage ecrit par l'utilisateur. J'ai crée mes fonctions me permettant de de saisir mes regles et mes commandes. Mais dans mon main j'ai un soucis car, lorsque l'utilisateur a saisi regle et la commande, on ne visualise pas le monde auxiliaire crée avec la génération suivante. Voila le main que j'ai fait :
J'aimerai savoir ce qui cloche.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 int main() { int regle; int pourcentages_vivantes; int commande; printf("Bienvenue dans le jeu de la vie.\n"); printf("Ce jeu vous est presente par JKR production, tous droits reserves!\n"); pourcentages_vivantes=Initialiser_Pourcentage(); Initialiser_Monde(pourcentages_vivantes); do { Afficher_Monde(); regle=Saisir_Regles(); commande=Saisir_Commande(); switch (commande) { case 1: Appliquer_Regle(regle); break; case 2: Saisir_Regles(); break; case 3: pourcentages_vivantes=Initialiser_Pourcentage(); Initialiser_Monde(pourcentages_vivantes); Afficher_Monde(); regle=Saisir_Regles(); commande=Saisir_Commande(); break; } }while(commande!=4); }
Gio,
Où est le code des fonctions que main appelle ? Il faut qu'on sorte nos boules de cristal ?
ps : l'indentation, c'est bien, mais c'est encore mieux quand c'est fait correctement, c'est à dire de manière régulière et cohérente.
![]()
Déjà, si le code était complet, on y verrait plus clair...
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 Project : Forums Compiler : GNU GCC Compiler (called directly) Directory : C:\dev\forums\ -------------------------------------------------------------------------------- Switching to target: default Compiling: main.c main.c:2: warning: function declaration isn't a prototype main.c: In function `main': main.c:6: warning: implicit declaration of function `printf' main.c:10: warning: implicit declaration of function `Initialiser_Pourcentage' main.c:11: warning: implicit declaration of function `Initialiser_Monde' main.c:14: warning: implicit declaration of function `Afficher_Monde' main.c:15: warning: implicit declaration of function `Saisir_Regles' main.c:16: warning: implicit declaration of function `Saisir_Commande' main.c:20: warning: implicit declaration of function `Appliquer_Regle' main.c:36: warning: control reaches end of non-void function Linking console executable: console.exe .objs\dev\forums\main.o(.text+0x33): In function `main': C:/dev/forums/main.c:10: undefined reference to `Initialiser_Pourcentage' .objs\dev\forums\main.o(.text+0x3b):C:/dev/forums/main.c:11: undefined reference to `Initialiser_Monde' .objs\dev\forums\main.o(.text+0x40):C:/dev/forums/main.c:14: undefined reference to `Afficher_Monde' .objs\dev\forums\main.o(.text+0x45):C:/dev/forums/main.c:15: undefined reference to `Saisir_Regles' .objs\dev\forums\main.o(.text+0x4c):C:/dev/forums/main.c:16: undefined reference to `Saisir_Commande' .objs\dev\forums\main.o(.text+0x6e):C:/dev/forums/main.c:20: undefined reference to `Appliquer_Regle' .objs\dev\forums\main.o(.text+0x75):C:/dev/forums/main.c:23: undefined reference to `Saisir_Regles' .objs\dev\forums\main.o(.text+0x7c):C:/dev/forums/main.c:27: undefined reference to `Initialiser_Pourcentage' .objs\dev\forums\main.o(.text+0x84):C:/dev/forums/main.c:28: undefined reference to `Initialiser_Monde' .objs\dev\forums\main.o(.text+0x89):C:/dev/forums/main.c:29: undefined reference to `Afficher_Monde' .objs\dev\forums\main.o(.text+0x8e):C:/dev/forums/main.c:30: undefined reference to `Saisir_Regles' .objs\dev\forums\main.o(.text+0x93):C:/dev/forums/main.c:31: undefined reference to `Saisir_Commande' collect2: ld returned 1 exit status Process terminated with status 1 (0 minutes, 8 seconds) 12 errors, 9 warnings
Bjr
Voila toutes mes fonctions avec le programme principal. Quelque regles sont en commentaires car elles ne sont pas crées. Seule le regle High Life est faite.
Code :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303 #include <stdio.h> #include "Lejeudelavie[1].h" /* Initialiser pourcentage */ int Initialiser_Pourcentage() { int pourcentage; { printf("Choisissez le pourcentage de cellules vivantes entre 1 et 100.\n"); do { scanf("%d", &pourcentage); if (pourcentage<=0 || pourcentage>100) { printf("Erreur le pourcentage doit etre compris entre 1 et 100.\n"); } } while (pourcentage<1 || pourcentage>100); } return pourcentage; } /*Initialiser monde*/ void Initialiser_Monde(int pourcentage) { int Nb_vivantes = pourcentage*NB_CELLULES/100; int indice; int x; for (indice=0; indice<Nb_vivantes; indice=indice+1) { x=Nb_Aleatoire(0, NB_CELLULES); if (monde[x]==MORTE) { monde[x]=VIVANTE; } else { while (monde[x]==VIVANTE) { x=x+1; if (indice==NB_CELLULES) { x=0; } } monde[x+1]=VIVANTE; } } } /*Afficher monde*/ void Afficher_Monde() { int indice; for (indice=1; indice<=NB_CELLULES; indice=indice+1) { if (monde[indice]==1) { printf("*"); } else { if (monde[indice]==0) { printf("-"); } } if (indice%NB_COLONNE==0) { printf ("\n"); } } } /* Nombre de voisins*/ int Nb_Voisin(int x, int y) { int delta_x, delta_y; int x0,y0,n; n=0; for (delta_x=-1; delta_x=1; delta_x=delta_x+1) { for (delta_y=-1; delta_y=1; delta_y=delta_y+1) { x0=x+delta_x%NB_COLONNE; y0=y+delta_y%NB_LIGNE; if (x0<0) { x0=x0+NB_COLONNE; } if (y0<0) { y0=y0+NB_LIGNE; } n=n+monde[DeuxDvers1D(x0,y0)]; } } n=n-monde[DeuxDvers1D(x,y)]; return n; } /*Nombre aleatoire*/ int Nb_Aleatoire(int borne_min, int borne_max) { int nb_aleatoire; nb_aleatoire=borne_min+rand()%borne_max+1; return(nb_aleatoire); } /*Saisir regle*/ int Saisir_Regles() { int regle; { { printf("Choisissez la regle de votre choix:\n \n 1-Conway\n 2-High Life\n 3-Day And Night\n 4-Regle Perso\n"); } while(regle<1 || regle>4) { scanf("%d", ®le); printf("Veuillez choisir un nombre entre 1 et 4 pour choisir votre regle.\n"); } return regle; } } /*Appliquer regle*/ void Appliquer_Regle(int regle) { int indice; switch (regle) { case 1 : //Regle_Conway(); break; case 2 : Regle_High_Life(); break; case 3 : //Regle_Day_And_Night(); break; case 4 : //Regle_Perso(); break; } for(indice=0; indice<=NB_CELLULES; indice++) { monde[indice]=monde_aux[indice]; } } /* Monde 2 D vers 1 D*/ int DeuxDvers1D(int x,int y) { return (x*NB_COLONNE+y); } /*Afficher commande*/ int Saisir_Commande() { int commande; printf("\nQue voulez vous faire?\n 1-Generation suivante\n 2-Changer de regle\n 3-Reinitialiser le jeu\n 4-Quitter\n"); do { scanf("%d", &commande); printf("Choisir 1,2,3 ou 4.\n"); } while (commande<1 || commande>4); return commande; } /*Regle High Life */ void Regle_High_Life() { int x; int y; int nb_voisin; for (x=0; x=NB_LIGNE-1;) for (y=0; y=NB_COLONNE-1;) { switch (nb_voisin) { case 2 : monde_aux[DeuxDvers1D(x, y)]=1; break; case 3: monde_aux[DeuxDvers1D(x, y)]=1; break; case 4: case 6: monde_aux[DeuxDvers1D(x, y)]=1; break; case 7: case 8: default:monde_aux[DeuxDvers1D(x, y)]=0; } } } /*Regle Day And Night*/ /*void Regle_Day_And_Night() { int x; int y; int nb_voisin; for (x=0; x=NB_LIGNE-1;) for (y=0; y=NB_COLONNE-1;) { switch (nb_voisin) { case 3:monde_aux[DeuxDVers1D(x, y)]==1 || monde_aux[DeuxDVers1D(x, y)]==monde[DeuxDVers1D(x, y)]; break; case 4:monde_aux[DeuxDVers1D(x, y)]==monde[DeuxDVers1D(x, y)]; break; case 6:monde_aux[DeuxDVers1D(x, y)]==1 || monde_aux[DeuxDVers1D(x, y)]==monde[DeuxDVers1D(x, y)]; break; case 7:monde_aux[DeuxDVers1D(x, y)]==1 || monde_aux[DeuxDVers1D(x, y)]==monde[DeuxDVers1D(x, y)]; break; case 8:monde_aux[DeuxDVers1D(x, y)]==1 || monde_aux[DeuxDVers1D(x, y)]==monde[DeuxDVers1D(x, y)]; break; default:monde_aux[DeuxDVers1D(x, y)]==0; } } } */ /*Programme principale*/ int main() { int regle; int pourcentages_vivantes; int commande; printf("Bienvenue dans le jeu de la vie.\n"); printf("Ce jeu vous est presente par JKR production, tous droits reserves!\n"); pourcentages_vivantes=Initialiser_Pourcentage(); Initialiser_Monde(pourcentages_vivantes); do { Afficher_Monde(); regle=Saisir_Regles(); commande=Saisir_Commande(); switch (commande) { case 1: Appliquer_Regle(regle); break; case 2: Saisir_Regles(); break; case 3: pourcentages_vivantes=Initialiser_Pourcentage(); Initialiser_Monde(pourcentages_vivantes); Afficher_Monde(); regle=Saisir_Regles(); commande=Saisir_Commande(); break; } }while(commande!=4); }
Tu ne comprends pas le sens du mot 'compilable ?'
On est censés deviner ce qui manque ?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 Project : Forums Compiler : GNU GCC Compiler (called directly) Directory : C:\dev\forums\ -------------------------------------------------------------------------------- Switching to target: default Compiling: main.c main.c:3:29: Lejeudelavie[1].h: No such file or directory main.c:8: warning: function declaration isn't a prototype main.c: In function `Initialiser_Monde': main.c:32: error: `NB_CELLULES' undeclared (first use in this function) main.c:32: error: (Each undeclared identifier is reported only once main.c:32: error: for each function it appears in.) main.c:37: warning: implicit declaration of function `Nb_Aleatoire' main.c:38: error: `monde' undeclared (first use in this function) main.c:38: error: `MORTE' undeclared (first use in this function) main.c:40: error: `VIVANTE' undeclared (first use in this function) main.c: At top level: main.c:62: warning: function declaration isn't a prototype main.c: In function `Afficher_Monde': main.c:64: error: `NB_CELLULES' undeclared (first use in this function) main.c:66: error: `monde' undeclared (first use in this function) main.c:78: error: `NB_COLONNE' undeclared (first use in this function) main.c: In function `Nb_Voisin': main.c:94: warning: suggest parentheses around assignment used as truth value main.c:96: warning: suggest parentheses around assignment used as truth value main.c:98: error: `NB_COLONNE' undeclared (first use in this function) main.c:99: error: `NB_LIGNE' undeclared (first use in this function) main.c:109: error: `monde' undeclared (first use in this function) main.c:109: warning: implicit declaration of function `DeuxDvers1D' main.c: In function `Nb_Aleatoire': main.c:124: warning: implicit declaration of function `rand' main.c: At top level: main.c:130: warning: function declaration isn't a prototype main.c: In function `Appliquer_Regle': main.c:159: warning: implicit declaration of function `Regle_High_Life' main.c:171: error: `NB_CELLULES' undeclared (first use in this function) main.c:173: error: `monde' undeclared (first use in this function) main.c:173: error: `monde_aux' undeclared (first use in this function) main.c: In function `DeuxDvers1D': main.c:183: error: `NB_COLONNE' undeclared (first use in this function) main.c: At top level: main.c:190: warning: function declaration isn't a prototype main.c:207: warning: function declaration isn't a prototype main.c:207: error: conflicting types for 'Regle_High_Life' main.c:159: error: previous implicit declaration of 'Regle_High_Life' was here main.c: In function `Regle_High_Life': main.c:211: error: `NB_LIGNE' undeclared (first use in this function) main.c:212: error: `NB_COLONNE' undeclared (first use in this function) main.c:218: error: `monde_aux' undeclared (first use in this function) main.c: At top level: main.c:269: warning: function declaration isn't a prototype main.c:303:2: warning: no newline at end of file Process terminated with status 1 (0 minutes, 4 seconds) 22 errors, 13 warnings
Partager