[R] Problem with random number simulation

Daniel Nordlund djnordlund at frontier.com
Mon Jul 25 05:18:08 CEST 2011


> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
> On Behalf Of AriGold
> Sent: Sunday, July 24, 2011 5:11 PM
> To: r-help at r-project.org
> Subject: [R] Problem with random number simulation
> 
> 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.
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.

Welcome to R-help.  The first thing you might want to do is read the posting guide (see immediately above).  Without any context, this looks suspiciously like school work.  If this is not school work then you might want to give some context for this task.  In addition, it would be beneficial if you commented your code and then told the list what it was that you expected to happen.  People are much more willing to help if you don't make them work so hard to figure out what you are trying to do.

Dan

Daniel Nordlund
Bothell, WA USA



More information about the R-help mailing list