В настоящее время я работаю над симуляцией зомби-апокалипсиса в NetLogo 2D. В моем текущем моделировании, когда зомби сталкиваются с людьми, люди имеют 100% шанс превратиться в зомби. Я хотел бы изменить это, чтобы я мог использовать ползунок для установки коэффициента конверсии - например, если у меня коэффициент 50% на моем слайдере, тогда, когда зомби сталкиваются с людьми, есть 50% вероятность, что они превратятся в зомби, иначе убейте атакующего зомби.
Вот как я в настоящее время настроил свой проект, способ, которым я это делал до сих пор, - это обнаруживать, когда они сталкиваются, и устанавливать здоровье людей на -1, а затем делать оператор if, который говорит, что если здоровье ниже 1, сделать из них зомби.
Я был бы признателен за любую помощь в правильном направлении, так как я потратил время на размышления об этом и не нашел никакого решения.
breed[humans person]
breed[zombies zombie]
globals[rad]
humans-own[zombies_seen zombies_hit humans_speed per_vis_rad per_vis_ang health]
zombies-own[zombies_speed humans_around_me closest_humans]
patches-own[solid]
to setup_world
clear-all
reset-ticks
set rad 1
ask patches[
set pcolor green
]
create-humans number_of_humans [
setxy random-xcor random-ycor
set color blue
set size 5
set shape "person"
set humans_speed 1 + random-float 0.1
set health 100
adjust_vision_cone
]
ask humans[
ask patches in-radius 5[
set pcolor yellow
]
]
create-zombies number_of_zombies [
setxy random-xcor random-ycor
set color red
set size 4
set shape "person"
set zombies_speed 0.5
]
ask zombies[
move-to one-of patches with [pcolor = green]
]
ask humans[
ask patches in-radius 5[
set pcolor green
]
]
draw_solid_patches
end
to draw_solid_patches
ask patches [
set solid false
]
ask n-of 100 patches with [pcolor = green][
set pcolor brown
set solid true
]
end
to detect_wall
if[solid] of patch-ahead 1 = true[
right 90
left 90
]
end
to run_model
Every 0.01 [
make_humans_move
make_zombies_move
tick
reset_patch_colour
if not any? humans [stop]
if ticks = 500000 [stop]
]
end
to make_humans_move
ask humans[
if health > 1 [
show_visualisations
right 45
left 45
let have_seen_zombies human_function
detect_wall
forward humans_speed
]
if health < 1 [ ; this is where it looks at the health of the humans, and checks to see if they have been hit by a zombie, because their health would be below 1.
set breed zombies
set color red
set size 4
set shape "person"
set zombies_speed 0.5
]
]
end
to make_zombies_move
ask zombies[
detect_wall
right 45
left 45
smell_humans
detect_wall
forward zombies_speed
]
end
to smell_humans
if any? humans in-radius 10 [
set heading towards one-of humans in-radius 10]
detect_wall
end
to show_visualisations
if show_vis_cone = true [
ask patches in-cone per_vis_rad per_vis_ang with [pcolor = green] [
set pcolor orange
]
]
end
to reset_patch_colour
ask patches with [pcolor = orange] [
set pcolor green
]
end
to adjust_vision_cone
set per_vis_rad 10 + random 10
set per_vis_ang 90
end
to-report human_function
let seen [false]
let hit [false]
ask zombies in-cone per_vis_rad per_vis_ang [
set seen true
]
ask zombies in-radius rad [
set hit true
]
ifelse seen = true [
set zombies_seen zombies_seen + 1
right 180
][
right (random zwr - (zwr / 2))
]
if hit = true [
set zombies_hit zombies_hit + 1
set color black
set health -1 ; this is where I make the human into a zombie, I need to have a method here that will refer to the convert_probability variable.
]
report seen
end
Внеся минимальные изменения в свой код, вы можете заменить set health -1
на
if random 100 < conversion_probability [ set health 0 ]
где conversion_probability
- ползунок от 0 до 100, как вы сказали в вопросе.
Я также хочу отметить, что вы можете обнаруживать такие стены
to detect_wall
if [solid] of patch-ahead 2
[
face one-of patches in-radius 2 with [not solid]
]
end
выполнение left x
, а затем right x
только заставляет черепаху повернуться влево, а затем повернуться лицом к тому месту, где она была изначально; если она не увидит зомби, это не сильно изменит поведение humans
.
Я также хотел добавить помимо ответа, что на вашу модель довольно интересно смотреть.