
Hello, I have a C++ code for 2D random walks with traps and I want to convert it in a R code with its syntaxs, can anyone help??????? 
It's easy for me to adapt the body but I want help with the beginig (variable declaration) and th end exporting the output to a file ( like write.table() or sink() )

Thank you...

#include <iostream>
#include <math.h>#include <fstream.h>#include <time.h>
#define IA 16807#define IM 2147483647#define AM (1.0/IM)#define IQ 127773
#define IR 2836#define NTAB 32#define NDIV (1+(IM-1)/NTAB)#define EPS 1.2*pow(10,-7)#define RNMX (1.0-EPS)
using namespace std;float rand1(long *idum);

int main(){ long run=10000,adr=-run,x,y,hapa=0,i=0; int dimx=700,dimy=700,nrg=50, M[dimx][dimy]; double rnd,sum=0; long k[run+1],frekuenca;
 bool njehsuar[run+1], next; ofstream Txt("EndjeMePengesa2D.txt"); printf("\nProgrami ekzekutohet:\ni=1 ne %d",run); for (i=1;i<=run;i++){ 
njehsuar[i]=true; k[i]=0; } while (i<nrg){ x=dimx*rand(&adr);y=dimy*rand(&adr); if (M[x][y]!=1){
M[x][y]=1;i++
 } }for (i=1;i<=run;i++){x=dimx*rand1(&adr); y=dimy*rand1(&adr);
 hapa=0; next=false; if (M[x][y]!=1){while (!next){hapa+=1;rnd=rand1(&adr);if (rnd<=0.25){
x+=1; if (x>dimx) {x=0;}}else if (rnd >0.25 && rnd<=0.5){x-=1;
 if (x<0) {x=dimx;}}else if (rnd >0.5 && rnd < 0.75){ y+=1; if (y>dimy) {y=0;}
}else{ y-=1; if (y<0) {y=dimy;}}if (M[x][y]==1) {next=true;}
} } k[i]=hapa; if (i%1000==0) printf("\ni=%d",i); á } Txt.close();
 cout << "-------------------------------------------"<< endl;
 cout << "Hap skedarin EndjeMePengesa2D.txt per te pare rezultatet." << endl; system("PAUSE"); return 0;}


 		 	   		  
	[[alternative HTML version deleted]]

