[R] Problem with random number simulation

AriGold ruchirpandya at gmail.com
Mon Jul 25 02:11:12 CEST 2011


Hi this is my first post.  I am trying to run a simulation for a computer
playing Von Neumann poker and adjusting it's expectation of an opponent's
behavior according to how the opponent plays.  This program involves random
generation of "hands" and shifting of parameters.  However, when I run the
code, no errors come up, but the program doesn't do anything.  Could someone
try running it?  And if ti does the same, could you tell me why it may be
doing this

A few points of clarification: After each round, an uneven coin (90/10
probability) is flipped to see if the game continues (hence the while loop). 
And every 10 hands, the noncomputer player changes strategy (hence the
if...modulus 20 statement)
Thanks

lambda=0.8
game=1
count=0
a=0.1
b=0.7
x=numeric()
y=numeric()
xval=x
yval=y
while(game==1)
{
        count=count+1
        x[count]=runif(1,0,1)
        y[count]=runif(1,0,1)
        if ((count%%20)<10)
        {
                if (x[count] > 0.15 & x[count]< 0.65)
                {
                        if(x[count]>y[count])
                        {
                                xval[count]=2
                                yval[count]=0
                        }
                        else
                        {
                                yval[count]=2
                                xval[count]=0
                        }
       
                }
                else if (x[count]<=0.15)
                {
                        if(y[count]<a)
                        {
                                xval[count]=2
                                yval[count]=0
                        }
                        else if (y[count]>b)
                        {
                                xval[count]=-1
                                yval[count]=3
                        }
                        else if (y[count]a)
                        {
                                z=rbinom(1,1,0.5)
                                if(z>0.5)
                                {
                                        xval[count]=-1
                                        yval[count]=3
                                }
                                else
                                {
                                        xval[count]=2
                                        yval[count]=0
                                }
                        }
                        if(x[count]>0.1)
                        {
                                a=(1/lambda)*a
                        }
                }
                else if (x[count]>=0.65)
                {
                        if(y[count]<a)
                        {
                                xval[count]=2
                                yval[count]=0}
                        }
                        else if(y[count]>0.7)
                        {
                                if(x[count]>y[count])
                                {
                                        xval[count]=3
                                        yval[count]=-1
                                }
                                else
                                {
                                        yval[count]=3
                                        xval[count]=-1
                                }
                        }
                        else if(yval[count]<=b & yval[count]>=a)
                        {
                                z=rbinom(1,1,0.5)
                                if(z>0.5)
                                {
                                        yval[count]=-1
                                        xval[count]=3
                                }
                                else
                                {
                                        xval[count]=2
                                        yval[count]=0
                                }
                        }
                        if(x[count]<0.7)
                        {
                                b = 0.8*b
                        }
                }
        }
        if((count&&20)<=10)
        {
                if(x[count]>0.1 & x[count]<0.7)
                {
                        if(x[count] > y[count] )
                        {
                                xval[count]=2
                                yval[count]=0
                        }
                        else
                        {
                                yval[count]=2
                                xval[count]=0
                        }
                        if(x[count]<a)
                        {
                                a=0.8*a
                        }
                        if(x[count]>b)
                        {
                                b=(1/0.8)*b
                        }
                }
                else if (x[count]<=0.1)
                {
                        if(y[count]<a)
                        {
                                xval[count]=2
                                yval[count]=0
                        }
                        else if (y[count]>b)
                        {
                                xval[count]=-1
                                yval[count]=3
                        }
                        else
                        {
                                z=rbinom(1,1,0.5)
                                if(z>0.5)
                                {
                                        xval[count]=-1
                                        yval[count]=3
                                }
                                else
                                {
                                        xval[count]=2
                                        yval[count]=0
                                }
                        }
                }
        else if (x[count]>=0.7)
        {
                if(y[count]<a)
                {
                        xval[count]=2
                        yval[count]=0}
                }
                else if(y[count]>b)
                {
                        if(x[count]>y[count])
                        {
                                xval[count]=3
                                yval[count]=-1
                        }
                        else
                        {
                                yval[count]=3
                                xval[count]=-1
                        }
                }
                else if(y[count]<=b & y[count]>=a)
                {
                        z=rbinom(1,1,0.5)
                        if(z>0.5)
                        {
                                yval[count]=-1
                                xval[count]=3
                        }
                        else
                        {
                                xval[count]=2
                                yval[count]=0
                        }
                }



        }
        game = rbinom(1,1,0.9) 

--
View this message in context: http://r.789695.n4.nabble.com/Problem-with-random-number-simulation-tp3691308p3691308.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list