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
|
// define variables
int Capital = 0;
int T = 0;
int lambda = 0.5;
float p = 0.495;
float p1 = 0.095;
float p2 = 0.745;
float R1,R2;
int M=3;
//set up canvas
size(480,480);
background(255,255,255);
//draw zero axis
stroke(200, 200, 200);
line(t,height/2-Capital,t+1,height/2-Capital);
//stroke(0,0,0);
while (T<100)
{
R1 = random(0,1);
T = T+1;
if (R1 < lambda) // Game A
{
if ( R1 < lambda * p )
Capital = Capital+1;
else
Capital = Capital-1;
}
R2 = random(0,1);
else
{
if ( Capital%M ==0 ) //play coin one of game B
{
if (R2 < p1)
Capital = Capital+1;
else
Capital = Capital-1;
}
else // play coin two of game B
{
if (R2 <p2)
Capital = Capital+1;
else
Capital = Capital-1;
}
}
}
|