Nsites=Input["Input dimensions of forest N"];​​n=Nsites;(*dimensionsofforest-nxn*)​​f=Input["Input probability f"]; (*probabilityofgreensitebecomingredifnonearestneighboursarered*)​​p=Input["Input probability p"]; (*probabilityofblacksitesproutinggrowthandbecominggreen*)​​t=Input["Imput number of time steps t"]; (*numberoftimestepstotake*)​​sample=Input["number of times to sample code for pdf"];​​(*mbymmatrixfilledrandomlywithsitesforblack/red/green*)​​Nmat=Table[RandomInteger[{0,1}],{n+2},{n+2}];​​​​(*Surroundingthematrixwith"filler"valuesofNulltoallowtheiffunctionstoaccessallofthematrixwithoutfaultingwheni+1*)​​​​Nmat[[{1,n+2},All]]=Null;​​Nmat[[All,{1,n+2}]]=Null;​​​​(*Createtablestoiterativelystorethetotalnumberofeachsiteattheendofthefixedtimeforeachsampley​​ andthevaluesateachtimestep*)​​totals=Table[Null,{sample}];​​timesteps=Table[Null,{sample}];​​(*setthenumberoftimestosamplethecodey,toresultinthepdfandloop*)​​For[y=1,y<sample+1,y++,​​​​(*Createatabletoiterativelystorethetotalnumberofeachsiteateverytimestep*)​​s=Table[Null,{t}];​​​​(*Setthenumberoftimestepsttoloopover*)​​For[ii=1,ii<t+1,ii++,​​(*Createamatrixctobefilledwith1'swhenagreensiteisneighbouredbyared.​​Allsitessurroundingthegreenincludingdiagonalswillbeconsidered.​​ThecmatrixwillbeaddedtoNmattoupdatethevaluesfromgreen(1)tored(2)*)​​​​r=Table[0,{i,1,n+2},{j,1,n+2}];​​​​For[i=2,i<n+2,i++,​​ For[j=2,j<n+2,j++,​​​​ (*Testforagreensite*)​​ If[Nmat[[i,j]]==1&&​​ (*Checkifanyneighbouringsiteisred,iftrue,settingc(i,j)=1*)​​ If[Nmat[[i,j+1]]==2||​​ Nmat[[i,j-1]]==2||​​ Nmat[[i+1,j]]==2||​​ Nmat[[i-1,j]]==2,​​ True],​​ r[[i,j]]=1;​​ ];​​ ];​​];