Bonjour à tous,

Nous sommes étudiants à l'INSA de Rouen, et dans le cadre d'un projet informatique nous avons choisi de réaliser un labyrinthe, mais aussi d'en générer.
Venons en à notre problème : lorsque je compile mon programme de génération (qui est ici juste un bout du programme final), il me demande d'initialiser deux tableaux d'entiers mais... Je ne vois pas comment puisque selon moi ils le sont déjà... (J'ai bien évidemment déjà chercher sur différents forums / sites internet des indications... En vain.)

Pourriez-vous nous aider ?

Je vous joins notre programme pour mieux comprendre, mon problème se situe lignes 45 et 49 (pour MH et MV), le compilateur écrit pour chaque tableau :
"Illegal expression
Local variable "MH" does not seem to be initialized"

Merci d'avance pour votre aide !

Marine.



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
 
Program generateur;
 
uses sdl,sdl_image, sdl_mixer, crt, keyboard, sysutils ;
 
const MAX = 100;
 
Type Lab = array[1..MAX,1..MAX] of integer;
	 LabFinal = array[1..201,1..201] of char;
 
Procedure NettoieCellules(var laby:Lab; x2, y2, dimX, dimY, v1, v2:integer);
Begin
	laby[x2,y2] := v1;
	If (x2 > 0) And (laby[x2 - 1,y2] = v2) Then
		NettoieCellules(laby, x2 - 1, y2, dimX, dimY, v1, v2);
	If (x2 < dimX-1) And (laby[x2 + 1,y2] = v2) Then
		NettoieCellules(laby, x2 + 1, y2, dimX, dimY, v1, v2);
	If (y2 > 0) And (laby[x2,y2 - 1] = v2) Then
		NettoieCellules(laby, x2, y2 - 1, dimX, dimY, v1, v2);
	If (y2 < dimY-1) And (laby[x2,y2 + 1] = v2) Then
		NettoieCellules(laby, x2, y2 + 1, dimX, dimY, v1, v2);
End;
 
procedure genererLaby(dim : integer);
 
var i, j, dimX, dimY, dimF, nbMurs, a : integer;
	laby, MH, MV : lab;
	LabyF : labFinal;
	continue, rand, x1, y1, x2, y2, v1, v2 : integer; 
 
begin 
	dimX:=dim;
	dimY:=dim;
	dimF:=(2*dim)+1;
 
	randomize;
	nbMurs:=0;
 
	for i:=0 to dimX do 
		for j:=0 to dimY do 
			laby[i,j]:= (i*dimY)+j;
 
	for i:=0 to dimX do 
		for j:=0 to dimY do
			MH[i,j]=1;
 
	for i:=0 to dimX do 
		for j:=0 to dimY do
			MV[i,j]=1;
 
	While nbMurs <> ((dimX*dimY)-1) do 
	Begin 
		continue:=0;
		rand:=random(2);
		case rand of 
			0: begin {Murs horizontaux}
				x1:=random(dimX+1);
				y1:=random(dimY+1);
 
				if MH[x1,y1]=1 then 
					begin 
					continue:=1;
					x2:=x1;
					y2:=y1+1;
					end;
			   end;
			1: begin {Murs verticaux}
				x1:=random(dimX+1);
				y1:=random(dimY+1);
 
				if MV[x1,y1]=1 then 
					begin 
					continue:=1;
					x2:=x1+1;
					y2:=y1;
					end;
			   end;
		end;
 
		if continue=1 then 
		begin 
			v1:= laby[x1,y1];
			v2:= laby[x2,y2];
			if v1 <> v2 then 
			begin 
				case rand of 
				0 : MH[x1,y1]:=0;
				1 : MV[x1,y1]:=0;
				end;
 
				NettoieCellules(laby, x2, y2, dimX, dimX, v1, v2);
				nbMurs:=nbMurs+1;
			end;
		end;
	end;
 
 
	for i:=0 to dimF do 
		for j:=0 to dimF do 
			labyF[i,j]:='0';
 
	For i := 0 To dimX do
		Begin
		For j := 0 To dimY do
			If (MV[i,j] = 1) Then
				Begin
				labyF[2*(i+1)+1,j*2+1]:= '1';
				labyF[2*(i+1)+1,j*2+2]:= '1';
				labyF[2*(i+1)+1,j*2+3]:= '1';
				End;
		End; 
 
	For i := 0 To dimX do
		Begin
		For j := 0 To dimY do
			If (MH[i,j] = 1) Then
				Begin
				labyF[i*2+1,(j+1)*2+1]:= '1';
				labyF[i*2+2,(j+1)*2+1]:= '1';
				labyF[i*2+3,(j+1)*2+1]:= '1';
				End;
		end;
 
	labyF[(random(dimF div 2)+1)*2,1]:='D';
	labyF[(random(dimF div 2)+1)*2,dimF]:='8';
 
end;	
 
 
Begin 
	genererLaby(7);
end.