2014年的12月29日,写了个VBS脚本,计算还需要连胜多少把才能让自己的胜率提升1%:
这个脚本的地址在:http://my.oschina.net/Tsybius2014/blog/362078
结果后来连着输了几把,胜率掉了1%(汗)。正好昨天看了下QBasic,就用QBasic写段代码计算一下吧
我的编码环境为:编译器为Win32下的FreeBasic(版本1.00.0),IDE为FBIde(版本0.4.6r4)
这段代码计算了还需要连胜多少把才能把自己的胜率提升1%,也计算了还需要连败多少把就会让胜率降低1%
计算规则:
1)以当前玩了426局,获胜86局为例,当前的胜率是0.201878,截去小数后是20%。
2)在这个基础上,连胜4局后,玩了430局,获胜90局,胜率为0.209302,截去小数后还是20%;但在连胜5局后,玩了431局,获胜91局,胜率到达0.211137,截去小数后胜率到达21%!这个时候,就认为是连胜5局后,就可以让胜率增加1个百分点。
3)同理,计算负场时,连负4局后,玩了430局,获胜86局,胜率为0.2,即20%;连负5局后,玩了431局,获胜86局,胜率为0.199536,截去小数后,是19%,视为胜率下降一个百分点。
需要注意的几点是:
1)胜率100%的时候,再连胜多少局胜率都是100%
2)胜率99%的时候,再连胜多少局胜率都是99%
3)胜率0%的时候,再连负多少局胜率都是0%
程序代码如下:
REM 计算还需要连胜多少局才能让胜率涨一点
REM 计算还需要连败多少局才能让胜率降一点
DIM GAMEPLAYED AS INTEGER
DIM GAMEWON AS INTEGER
DIM INPUT1 AS STRING : INPUT "HOW MANY GAMES HAVE YOU PLAYED? "; INPUT1
DIM INPUT2 AS STRING : INPUT "HOW MANY GAMES HAVE YOU WON? "; INPUT2
PRINT
GAMEPLAYED = FIX(VAL(INPUT1))
GAMEWON = FIX(VAL(INPUT2))
PRINT "GAMEPLAYED: "; GAMEPLAYED
PRINT "GAMEWON: "; GAMEWON
PRINT
'输入合法性校验
IF GAMEPLAYED < 0 OR GAMEWON < 0 OR GAMEPLAYED < GAMEWON THEN
PRINT "GAMEPLAYED MUST BIGGER-EQUAL THAN 0"
PRINT "GAMEWON MUST BIGGER-EQUAL THAN 0"
PRINT "GAMEPLAYED MUST BIGGER THAN GAMEWON"
GOTO PRG_FINISH
END IF
'计算当前胜率
PRINT "CURRENT WINNING RATE: "; GAMEWON * 100 \ GAMEPLAYED; "%"
'计数器
DIM COUNTER AS INTEGER
'计算还需要多少局连胜才能增长一点胜率
'检查特例
IF GAMEPLAYED = GAMEWON THEN
PRINT "NO NEED TO IMPROVE!"
GOTO MISSION1_COMPLETE
ELSEIF GAMEWON * 100 \ GAMEPLAYED = 99 THEN
PRINT "NO SOLUTION TO IMPROVE!"
GOTO MISSION1_COMPLETE
END IF
'模拟玩一局赢一局的过程
COUNTER = 1
DO
IF (GAMEWON + COUNTER - 1) * 100 \ (GAMEPLAYED + COUNTER - 1) < _
(GAMEWON + COUNTER) * 100 \ (GAMEPLAYED + COUNTER) THEN
EXIT DO
ELSE
COUNTER = COUNTER + 1
END IF
LOOP
'打印结论1
PRINT "TO IMPROVE 1% WINNING RATE, YOU NEED TO WIN"; COUNTER; " GAME(S) CONTINUOUSLY"
MISSION1_COMPLETE:
'计算还需要多少局连败才能降低一点胜率
'检查特例
IF GAMEWON = 0 THEN
PRINT "WINNING PERCENTAGE: 0%"
PRINT "CANNOT DECLINE ANY MORE!"
GOTO MISSION2_COMPLETE
END IF
'模拟玩一局输一局的过程
COUNTER = 1
DO
IF (GAMEWON) * 100 \ (GAMEPLAYED + COUNTER - 1) > _
(GAMEWON) * 100 \ (GAMEPLAYED + COUNTER) THEN
EXIT DO
ELSE
COUNTER = COUNTER + 1
END IF
LOOP
'打印结论2
PRINT "TO DECLINE 1% WINNING RATE, YOU NEED TO LOSE"; COUNTER; " GAME(S) CONTINUOUSLY"
MISSION2_COMPLETE:
PRG_FINISH:
SLEEP
END
运行结果截图:
END
来源:oschina
链接:https://my.oschina.net/u/1425762/blog/363453