The following warnings occurred:
Warning [2] count(): Parameter must be an array or an object that implements Countable - Line: 795 - File: showthread.php PHP 7.4.33 (FreeBSD)
File Line Function
/showthread.php 795 errorHandler->error





Post Reply 
Question about a simple game
04-23-2019, 08:09 PM
Post: #1
Question about a simple game
Hi All,

I wrote a simple game where the user plays against the calculator/PC. The game is an iterative one. In ach iteration the user and the PC generate random numbers (0,1). The user’s random value is added to a summation variable, while the calculator’s random number is subtracted from that summation variable. If the summation variable reaches or exceeds a user-chosen value T, the user is the winner. If the summation variable reaches -T or less, the the calculator win. Here is the pseudo-code:

Code:
Sum = 0
I = 0
Do
  Me = Rand(0,1)
  Sum = Sum + Me
  PC = Rand(0,1)
  Sum = Sum – PC
  I   = I + 1
Until Sum >= T or Sum <= -T

if Sum >= T Then 
  Show "You Win"
else
  Show "You lose"
end

I noticed that the average iterations, I, for either player (the user or the calculator) to win is a function of T. I used quadratic fit of I as a function of T. The curves I obtained from the numerous runs indicate that the underlying relation between I and T is:

I = 0.5*T^2 + T = T*(T/2 + 1)

My question is, can someone derive the above equation based on whatever statistical assumptions?

Namir
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Question about a simple game - Namir - 04-23-2019 08:09 PM
RE: Question about a simple game - Namir - 04-24-2019, 03:15 AM
RE: Question about a simple game - Namir - 04-24-2019, 03:14 PM
RE: Question about a simple game - Namir - 04-24-2019, 03:10 PM



User(s) browsing this thread: 1 Guest(s)