狠狠拷打了gpt,写了个matlab脚本试试
% Parameters
corn_damage = 20;
butter_damage = 40;
attack_time = 2.9;
butter_prob = 0.25;
distance = 8;
zombie_speed = 1/4.7;
trap_time = 4;
num_plants = 52;
% Calculate the average rate of butter hits
lambda_butter = butter_prob * num_plants / attack_time;
% Calculate the average rate of corn hits
lambda_corn = (1 - butter_prob) * num_plants / attack_time;
% Test different zombie_HP values
for zombie_HP = logspace(log10(3e8), log10(3e20), 100)
% Initialize the zombie position and HP
zombie_position = distance;
zombie_HP_current = zombie_HP;
% Initialize the time and the trap status
time = 0;
trapped = false;
trap_end_time = 0;
% Main loop
while zombie_position > 0 && zombie_HP_current > 0
% Calculate the time to the next hit
hit_time = exprnd(1 / (lambda_butter + lambda_corn));
% Update the time
time = time + hit_time;
% Check if the zombie is trapped
if trapped && time < trap_end_time
% The zombie is trapped, so it doesn't move
else
% The zombie is not trapped, so it moves
zombie_position = zombie_position - zombie_speed * hit_time;
trapped = false;
end
% Check if the hit is a butter hit
if rand < butter_prob
% It's a butter hit, so the zombie is trapped and loses HP
zombie_HP_current = zombie_HP_current - butter_damage;
trapped = true;
trap_end_time = time + trap_time;
else
% It's a corn hit, so the zombie loses HP
zombie_HP_current = zombie_HP_current - corn_damage;
end
end
% Display the results
if zombie_HP_current <= 0
fprintf('For zombie_HP = %e, the plants defeated the zombie.\n', zombie_HP);
else
fprintf('For zombie_HP = %e, the zombie reached the plants.\n', zombie_HP);
end
end
跑血量太慢了,明天起床再跑全部的,或者富哥v个i914900k也行
代码有错误欢迎指正,毕竟是gpt写的