100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > matlab 钻石绘制 用MATLAB代码模拟大雕和钻石人单挑

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

时间:2024-06-24 04:31:43

相关推荐

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级兵。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。