Program Juegodelavida; uses crt; const max=20; type tpcasilla=record probabilidad:real; estado:integer; estadofinal:integer; end; tpvectorY=record vectorY:array [1..max] of tpcasilla; end; tpvectorX=array [1..max] of tpvectorY; procedure mostrarmenu; begin Textcolor(yellow); Gotoxy(10,6); writeln('1:Generar Mundo.'); Gotoxy(10,9); writeln('2:Ejecucion.'); Gotoxy(10,12); writeln('3:Carga estado inicial.'); Gotoxy(10,15); writeln('4:Salir.'); Gotoxy(10,18); Textcolor(white); write('Respuesta(1 al 4):') end; function menu:integer; var opcion:integer; begin while not ((opcion>0) and (opcion<5) and (IOResult=0))do begin {$i-} clrscr; mostrarmenu; readln(opcion); {$i+} menu:=opcion; end; end; function comprobar(m:string):boolean; begin if (m[1]>='0')and (m[1]<='1') then if (m[2]='.') then if ((m[1]='0') and (m[3]>='0') and (m[3]<='9')) or((m[1]='1') and (m[3]='0')) then comprobar:=true else comprobar:=false; end; procedure transfor_entero(x:integer;var y:char); begin case x of 0:(y):='0'; 1:(y):='1'; 2:(y):='2'; 3:(y):='3'; 4:(y):='4'; 5:(y):='5'; 6:(y):='6'; 7:(y):='7'; 8:(y):='8'; 9:(y):='9'; end; end; function probabilidad_estado:string; var x:integer; y:char; m,y1,y2,y3:string; begin x:=random(2); transfor_entero(x,y); y1:=y; if y1='0' then begin x:=random(10); transfor_entero(x,y); y3:=y; end else y3:='0'; y2:='.'; m:=concat(y1,y2,y3); probabilidad_estado:=m; end; procedure casillas(var Ncasillas:integer;var primera:boolean;var m:string); var numero:string; i:word; begin ClrScr; if primera=true then begin repeat write('Genere el numero de casillas por lado(4 al 20):'); {$i-} readln(Ncasillas); writeln; {$i+} until (IOResult=0) and (Ncasillas>3) and (Ncasillas<21); primera:=false; write('Genere la probabilidad del estado inicial:'); repeat begin readln(numero); m:=numero; end; until (length(m)=3) and (comprobar(m)=true); end else begin Ncasillas:=random(16); Ncasillas:=Ncasillas+4; m:=probabilidad_estado; write('El mundo sera creado de ',Ncasillas,' por lado'); end; end; procedure comp_prob(m,mcasilla:string;var vivas:integer); begin if m>mcasilla then vivas:=0 else vivas:=1; end; Procedure dibujar_mundo(Vx:tpvectorX;Ncasillas:integer); var i,j:word; begin ClrScr; for i:=1 to Ncasillas do begin for j:=1 to Ncasillas do begin gotoxy(i,j); write(Vx[i].vectorY[j].estado); end; end; readln; end; procedure generar_mundo(var primera:boolean;var vx:tpvectorX;var Ncasillas:integer); var i,j:word; m:string; mcasilla:string[3]; vivas:integer; vy:tpvectorY; begin casillas(Ncasillas,primera,m); ClrScr; for i:=1 to Ncasillas do begin for j:=1 to Ncasillas do begin if (i=1) or (j=1) or (i=Ncasillas) or (j=Ncasillas) then vy.vectorY[j].estado:=0 else begin mcasilla:=probabilidad_estado; comp_prob(m,mcasilla,vivas); vy.vectorY[j].estado:=vivas; end; end; vx[i]:=vy; end; dibujar_mundo(vx,Ncasillas); end; procedure sumarvecinas(vx:tpvectorX;i,j:word;Var total:integer); var X,Y,A,B,C,D:word; begin X:=i; Y:=j; A:=i-1; B:=i+1; C:=j-1; D:=j+1; total:=0; for i:=A to B do begin for j:=C to D do begin if (i<>X) or (j<>Y) then total:=vx[i].vectorY[j].estado+total; end; end; end; procedure estado_nuevo(var vx:tpvectorX;total:integer;i,j:word); begin with vx[i].vectorY[j] do begin if (total=3) and (estado=0) then estadofinal:=1; if ((total<5) or (total>5)) and (estado=1) then estadofinal:=0; end; end; procedure vecinas(var vx:tpvectorX;Ncasillas:integer); var i,j:word; total:integer; begin for i:=2 to Ncasillas-1 do begin for j:=2 to Ncasillas-1 do begin sumarvecinas(vx,i,j,total); estado_nuevo(vx,total,i,j); end end; end; procedure estado_actual(var vx:tpvectorX;Ncasillas:integer); var i,j:word; begin begin for i:=2 to Ncasillas-1 do begin for j:=2 to Ncasillas-1 do begin with vx[i].vectorY[j] do estado:=estadofinal; end; end; end; dibujar_mundo(vx,Ncasillas) end; procedure Ejecucion(vx:tpvectorX;Ncasillas:integer); var a:char; cont:word; begin cont:=0; repeat begin vecinas(vx,Ncasillas); estado_actual(vx,Ncasillas); writeln('salir pulse "s" y luego enter:'); cont:=cont+1; writeln('Turno:',cont); readln(a) end; until a='s' end; var x:integer; salir:boolean; primera:boolean; Vx:tpvectorX; Ncasillas:integer; BEGIN randomize; salir:=false; primera:=true; while salir=false do begin case menu of 1:generar_mundo(primera,Vx,Ncasillas); 2:ejecucion(Vx,Ncasillas); {3:carga_estado_inicial;} 4:salir:=true; end; end; END. ---------------------------- (añadido tras someter) ---------------------------- 15:22:51 11/12/09 -> Segun los datos introducidos los ficheros son: G16P03D2 -> Los autores del trabajo son: Bracero Sáez, Ignacio Garza Castillón, Miguel Nombres originales de los archivos entregados -> JUEGODEL.PAS, JUEGODELAVIDA.txt