Can Mathematica help me win my on-line game?
Running the code below, which shows the results for runs of 1000 shots, the rewards as set mean you should always take the 100% shot. With different rewards you could add a condition to take a different shot depending on the level of the increased reward.
shot[chance_, reward_, hike_] := Module[{result},
result = If[chance < RandomInteger[{1, 100}], "miss", "hit"];
Switch[result,
"hit", score += reward; misshike = 0,
"miss", misshike += hike]]
calc[chance_, reward_, hike_] := Module[{},
table = Table[
score = 0;
misshike = 0;
Do[shot[chance, reward, hike], {1000}]; score, {100}];
N@Through[{Mean, StandardDeviation}@table]]
TableForm[{
calc[100, 10, Null],
calc[20, 40, 5],
calc[10, 60, 10],
calc[5, 100, 15]}, TableHeadings -> {
{"100%", "20%", "10%", "5%"}, {"Average", "Std.dev."}}]
I know I'm a billion years late on this, and an answer now won't do anyone any good, but I found it really interesting for some reason. I'm not great with probabilities, but my reasoning seemed to match the simulation, so I think it's correct.
We should expect it to take $\frac{1}{p}$ tries to get a goal, where $p$ is the probability of a goal. This means we would have $\frac{1}{p} - 1$ failures where the pot increases each time, followed by 1 goal where the pot pays out.
The expected value of a win without the increasing cups is just $pb$ where $b$ is the base number of cups. So the expected value of a payout is $(\frac{1}{p}-1)a + b$ where $a$ is the additional cups gained for each loss, and this makes the expected value of each attempt (the average, essentially) $(1-p)a + p b$.
p = {1, 0.2, 0.1, 0.05};
a = {0, 5, 10, 15};
b = {10, 40, 60, 100};
TableForm[
Transpose[{100 p, (1/p - 1) a + b, (1 - p) a + p b}],
TableHeadings -> {None, {"Goal Probability (%)",
"Expected Value of a Win", "Expected Value of Each Attempt"}}
]
I think there might be a mistake in the accepted answer, where the score
is only incremented by the reward
amount. If I understand it correctly, I think the score
should be incremented by reward + misshike
. Making that change, I get a table like this:
This looks a lot like 1000 times the expected value of each attempt. My own attempt at simulating the result:
simulate[probability_, additional_, base_, n_ : 1000] := Module[{
value = base,
cups = 0
},
Reap[
Do[
If[
RandomReal[] < probability,
Sow[value]; value = base,
Sow[0]; value += additional
],
n
]
][[2, 1]]
]
p = {1, 0.2, 0.1, 0.05};
a = {0, 5, 10, 15};
b = {10, 40, 60, 100};
ListLinePlot[
Accumulate /@ MapThread[simulate, {p, a, b}],
PlotLegends -> (ToString[Round[100 #]] <> "%" & /@ p),
Prolog -> {
Opacity[0.5],
Line[{{1, #}, {1000, #}}] & /@ {10000, 12000, 15000, 19250},
Text[#, {100, #}, {0, -0.6}] & /@ {10000, 12000, 15000, 19250}
}
]
In summary, unless I'm hugely mistaken, I think that the math and simulations are in agreement that the 5% options is nearly 2x as lucrative as the 100% option. As for the effect of other players, you can try set a threshold and only play games when the reward is above a certain level. For example, if you only play the 5% game when the reward is over 250, you can maximize the value of each play. Of course, you spend a substantial amount of time waiting for the jackpot to increase, and waste even more time since there's an excellent chance someone else will take a turn and win the pot before you if there's 79 others playing.
val = 100;
inc = 15;
prob = 0.05;
newlist = Reap[
Do[
If[val >= 250 \[And] RandomReal[] <= 1/80,
If[
RandomReal[] < prob,
Sow[val, "Agent 2"]; val = 100,
Sow[0, "Agent 2"]; val += inc
],
If[
RandomReal[] < prob,
Sow[val, "Agent 1"]; val = 100,
Sow[0, "Agent 1"]; val += inc
]
],
1000000
],
{"Agent 1", "Agent 2"}];
Show[
Plot[
19.25 x, {x, 1, 7000},
PlotStyle -> Directive[Dashed, Black]
],
ListLinePlot[{
Accumulate@newlist[[2, 1, 1]],
Accumulate@newlist[[2, 2, 1]]
}
]
]
It looks like you can increase the value of each token you spend. However, you end up playing far fewer games over a specified period than someone who plays indiscriminately. I'm not sure if that would matter here, though, it sounds like the most important thing is to not waste tokens.