Con la partecipazione della più celebre coppia di Hollywood in veste di mascotte.

Programmi PASCAL per il Risiko

Programma che calcola la probabilità (AVSD) dei diversi esiti degli attacchi a oltranza

program AVSD;
uses crt;
var A,D,N: integer;
VS: array[1..20,1..20] of real;

begin
clrscr;
readln;
writeln('N=?');
readln(N);
if N<20 then BEGIN
for A:=1 to N do for D:=1 to N do VS[A,D]:=0;
VS[1,1]:=0.417;
VS[1,2]:=0.2546*VS[1,1];
VS[1,3]:=0.1736*VS[1,2];
for D:=4 to N do VS[1,D]:=0.1736*VS[1,D-1];
VS[2,1]:=0.5787+0.4123*VS[1,1];
VS[2,2]:=0.2276+0.3241*VS[1,1];
VS[2,3]:=0.0863*VS[2,1]+0.5257*VS[1,2];
for D:=4 to N do VS[2,D]:=0.0863*VS[2,D-2]+0.5257*VS[1,D-1];
VS[3,1]:=0.6597+0.3403*VS[2,1];
VS[3,2]:=0.3095+0.3511*VS[2,1]+0.3394*VS[1,2];
VS[3,3]:=0.1154+0.2369*VS[2,1]+0.3283*VS[1,2];
for D:=4 to N do VS[3,D]:=0.1154*VS[3,D-3]+0.2369*VS[2,D-2]+0.3283*VS[1,D-1];
for A:=4 to N do VS[A,1]:=0.6597+0.3403*VS[A-1,1];
for A:=4 to N do VS[A,2]:=0.3095+0.3511*VS[A-1,1]+0.3394*VS[A-2,2];
for A:=4 to N do VS[A,3]:=0.1154+0.2369*VS[A-1,1]+0.3283*VS[A-2,2]+0.3195*VS[A-3,3];
for A:=4 to N do for D:=4 to N do
VS[A,D]:=0.1154*VS[A,D-3]+0.2369*VS[A-1,D-2]+0.3283*VS[A-2,D-1]+0.3195*VS[A-3,D];
for A:=1 to N do for D:=1 to N do begin write('(',A,'VS',D,')=',VS[A,D]:5:4,'  ') end;
readln;
END
else writeln('N deve essere minore di 20');
end.

Programma che determina le probabilità P(v,AF) di riuscire a conquistare v territori terminando con AF armate sull'ultimo dei territori conquistati

program QuantearmateperderaiaRisiko;
uses math;
var A,D,S,AF,N,i,j,v: integer;
C,mind,SOMMA:real;
p: array[0..20,0..20] of real;

function Fattoriale(x:integer):longint;
begin
if x=0 then
Fattoriale:=1
else
Fattoriale:=x*Fattoriale(x-1);
end;

function Comb(x,y:integer):real;
begin
if x<0 then Comb:=0 else if y<0 then Comb:=0 else if x-y<0 then Comb:=0 else
Comb:=(Fattoriale(x))/(Fattoriale(y)*Fattoriale(x-y))
end;

begin
writeln('Dato un certo numero A di armate attaccanti, uesto programma calcola la probabilità');
writeln('di riuscire a conquistare un certo numero D di territori, difesi ciascuno da una sola armata,');
writeln('arrivando ad occupare il territorio finale con un certo numero AF di armate');
writeln('Armate attaccanti=?');
readln(A);
writeln('Territori da conquistare=?');
readln(D);
BEGIN
for i:=0 to 20 do for j:=0 to 20 do p[i,j]:=0;
for v:=0 to D do for AF:=0 to A do
BEGIN
N:=A+1-AF;
if AF>2 then
begin
C:=Comb(N,v);
p[v,AF]:=C*exp(v*ln(0.6597))*exp((N-v)*ln(0.3403));
writeln('p[',v,',',AF,']=',p[v,AF]:5:4);
readln;
end;
if AF = 2 then begin
C:=Comb(N-1,v-1);
p[v,AF]:=C*exp((v-1)*ln(0.6597))*exp((N-v)*ln(0.3403))*0.5787;
writeln('p[',v,',',AF,']=',p[v,AF]:5:4);
readln;
end;
if AF = 1 then  begin
C:=Comb(N-2,v-2);
p[v,AF]:=C*exp((v-2)*ln(0.6597))*exp((N-v)*ln(0.3403))*0.417;
writeln('p[',v,',',AF,']=',p[v,AF]:5:4);
readln;
end;
if AF = 0 then  begin
C:=Comb(N-2,v-2);
p[v,AF]:=C*exp((v-2)*ln(0.6597))*exp((N-v)*ln(0.3403))*0.583;
writeln('p[',v,',',AF,']=',p[v,AF]:5:4);
readln;
end
END;
readln;
END
end.



Nessun commento: