请原谅任何错误,这是我的第一篇帖子!最近我很无聊,正试着做一个批量脚本克隆一个我曾经看过的街机游戏:http://antikrish.com/2013/01/28/whittakers-ascot-gold-cup-horse-racing-arcade-game/。
规则
我不记得规则,我希望它公平,所以制定了我自己。
问题
我参加了比赛,一切看起来都很好!但是过了一段时间,我注意到马匹几乎从来没有赢过。现在,这可以用概率解释,但我想检查,所以我修改了我的代码,以跟踪结果随着时间的推移,并看到更高编号的马是一贯更经常地赢!
我上传了一个图表(http://i.imgur.com/IZuXnye.png),它显示了三组1000场比赛的胜利者的结果,其中允许抽签(并被算作所有比赛结束后的胜利)。现在,这种行为不一定是一件坏事,意味着每匹马都有机会,但我不知道为什么会发生这种情况。
原因
在我看来,这种行为可能发生的原因有三个:
所以,有人能告诉我为什么会发生这种事吗?
提前感谢!
这是代码,如果有用的话:
@ECHO OFF
COLOR 0B
setlocal EnableDelayedExpansion
set total = 0
set totalscore[0]=0
set totalscore[1]=0
set totalscore[2]=0
set totalscore[3]=0
set totalscore[4]=0
set totalscore[5]=0
set totalscore[6]=0
:START
set /a total = total + 1
set score[0]=0
set score[1]=0
set score[2]=0
set score[3]=0
set score[4]=0
set score[5]=0
set score[6]=0
set winner=0
:LOOP
cls
echo Race Number: %total%
for /l %%n in (1,1,6) do (
set /a num=!random! %%%%n + 1
IF !num! == %%n set /a score[%%n]=!score[%%n]! + !num!
<NUL set /p=%%n:
for /l %%x in (1, 1, !score[%%n]!) do <NUL set /p=^|
set /a sum=60 - !score[%%n]!
for /l %%x in (1, 1, !sum!) do <NUL set /p=_
echo F
)
for /l %%n in (1,1,6) do (
if !score[%%n]! == 60 (
echo winner: %%n
set /a totalscore[%%n]=!totalscore[%%n]! + 1
set winner=1
)
)
echo.
echo Previous Results
for /l %%n in (1,1,6) do (
echo %%n: !totalscore[%%n]!
)
if %winner%==1 GOTO END
timeout /t 0 /nobreak > NUL
GOTO LOOP
:END
echo.
pause
GOTO START编辑--我认为这是一种概率怪癖,因为马匹6有机会在10圈后完成比赛,而其他所有的马在身体上都不行。这对每匹马加起来,将马的几率降低到低于它的几率(也就是说,只有当另一匹马的表现不佳时,马1才会获胜)。
谢谢你的答复:)
发布于 2013-10-28 16:57:32
问题归结为概率!
如果我们把游戏简化为6步:
如果我们为每匹马这样做,可怜的马就永远不会有机会了!
发布于 2013-10-28 16:17:31
calcs中的国税是不正确的。请换到
rem Generate a number in range [1-%%n]
set /a num=!random! * %%n / 32767 + 1
rem if horse number is <= random then move horse
if !num! GEQ %%n set /a score[%%n]=!score[%%n]! + %%n%随机%返回0到32767之间的数字
发布于 2013-10-28 18:02:05
%随机%变量返回一个假定分布在0到32767之间的均匀数字,因此获得1到n之间相同分布的数字的正确方法是:
set /a num=!random! * %%n / 32768 + 1..。也可以通过这种方式获得:
set /a "num=!random! * %%n >> 16 + 1"如果使用%随机%的余数(模数)为n,则如下所示:
set /a num=!random! %% %%n + 1..。然后,你得到一个完全不同的,未知的分布,可能是偏向于某些价值。
均匀分布随机数的生成并不容易,因此您应该很好地利用生成%随机%变量的方法,而不改变它的原始分布。
https://stackoverflow.com/questions/19639629
复制相似问题