1167790
1、问题:
炉石传说是暴雪出的一款卡牌对战类游戏,策略和博弈,卡组的组合,费用曲线等诸多要素会影响胜局,今天聊聊这两张卡:
玩过的同学都知道,法力龙虽然不会被寒冰箭,英雄的小火球点掉,但是可以被奥弹biu死,那么问题来了:
** 假如对面场上只有法力龙(满血),法师一个奥弹清掉法力龙的概率是多少呢?**
2、上代码
var combat = {
hero : 0,
dragon : 0,
hit : function(){
if(this.dragon===2){
this.hero++;//精灵龙只有两血,如果前两发奥弹打死了精灵龙,那么剩下一发必然打脸
}else{
var randomHit = Math.random();
//The Math.random() function returns a floating-point, pseudo-random number in the range [0, 1)
if(randomHit<0.5){
this.dragon++;
}
else{
this.hero++;
}
}
},
getDragon:function(){
return this.dragon;
},
init:function(){
this.dragon = 0;
this.hero = 0;
}
}
var count = 0;
for(var i=0;i<100000000;i++){
combat.init(); //初始化战斗
var x = 3; //一共三发
while(x>0){
combat.hit();
x--;
}
if(combat.getDragon()===2){
count++;
}
if(combat.getDragon()===3){
console.log("error");//检查是否有错误
}
}
console.log("dragon die "+count+" times");
dragon die 49998591 times dragon die 50011641 times dragon die 50001475 times dragon die 50006546 times dragon die 49991350 times
结果是50%应该没错了,但是宝宝有个问题,这个过程对吗?