matlab 钻石绘制,用MATLAB代码模拟大雕和钻石人单挑

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

不考虑士气、幸运等偶然因素。

以下为测试用MATLAB代码和结论。

function r=damages(amountA,attA,defA,dmgA,hpA,amountB,attB,defB,dmgB,hpB)

%让大雕和钻石人单挑,其中A是大雕,B是钻石人。BAAB是钻石人先攻击,ABBA是大雕先攻击。

hpleftA=hpA;

hpleftB=hpB;

while(1)

if (amountB>0)

[amountA,hpleftA]=onedamage(amountB,attB,dmgB,amountA,defA,hpA,hpleftA);

else

r=1;

break;

end

if (amountA>0)

[amountB,hpleftB]=onedamage(amountA,attA,dmgA,amountB,defB,hpB,hpleftB);

else

r=-1;

break;

end

if (amountA>0)

[amountB,hpleftB]=onedamage(amountA,attA,dmgA,amountB,defB,hpB,hpleftB);

else

r=-1;

break;

end

if (amountB>0)

[amountA,hpleftA]=onedamage(amountB,attB,dmgB,amountA,defA,hpA,hpleftA);

else

r=1;

break;

end

end

end

function r=stat(times)

%这个函数用于多次模拟大雕和钻石人单挑。

result=[0 0];

for t=1:times

ran1=rand();

ran2=rand();

r=damages(1,13,11,11+ran1*4,60,1,13,12,10+ran2*4,60);%这是大雕和钻石人的数据

if (r==1)

result(1)=result(1)+1;

else result(2)=result(2)+1;

end

end

r=result(1)/times;%这是大雕的胜率

end

function t=dmg(a,b)

%这个用于计算伤害的倍数。

if (a>=b)

t=1+(a-b)*0.05;

if t>4

t=4;

end

else

t=1+(a-b)*0.025;

if t<0.3

t=0.3;

end

end

function [aB,hlB]=onedamage(amountA,attA,dmgA,amountB,defB,hpB,hpleftB)

%这个用于计算伤害和剩余生命值。

totalhpB=(amountB-1)*hpB+hpleftB;

dmgAtoB=dmg(attA,defB)*dmgA*amountA;

if (dmgAtoB

totalhpB=totalhpB-dmgAtoB;

if ((totalhpB/hpB)-floor(totalhpB/hpB))>0

aB=floor(totalhpB/hpB)+1;

else aB=floor(totalhpB/hpB);

end

hlB=totalhpB-(aB-1)*hpB;

else

totalhpB=0;

aB=0;

hlB=0;

end

end

结论:如果是单挑,那么当大雕先攻击时,大雕的胜率约为80%,当钻石人先攻击时,大雕的胜率约为36%,由此可见,钻石人只能是5级兵。

如果是大规模战斗的话(按60个计算),那么当大雕先攻击时,大雕的胜率约为72%,当钻石人先攻击时,大雕的胜率约为47%,由此可见,钻石人只能是5级兵。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值