Heroes vs Bug
Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)
WHAT IS IT?
(a general understanding of what the model is trying to show or explain)
HOW IT WORKS
(what rules the agents use to create the overall behavior of the model)
HOW TO USE IT
(how to use the model, including a description of each of the items in the Interface tab)
THINGS TO NOTICE
(suggested things for the user to notice while running the model)
THINGS TO TRY
(suggested things for the user to try to do (move sliders, switches, etc.) with the model)
EXTENDING THE MODEL
(suggested things to add or change in the Code tab to make the model more complicated, detailed, accurate, etc.)
NETLOGO FEATURES
(interesting or unusual features of NetLogo that the model uses, particularly in the Code tab; or where workarounds were needed for missing features)
RELATED MODELS
(models in the NetLogo Models Library and elsewhere which are of related interest)
CREDITS AND REFERENCES
(a reference to the model's URL on the web if it has one, as well as any other necessary credits, citations, and links)
Comments and Questions
breed [mobs mob] breed [heroes hero] globals[ generation startLife startSpeed startDef startAtk ] heroes-own[ max-life life attack defense target ] mobs-own[ max-life life attack defense ] to Start clear-all clear-output set generation 0 set startLife 100 set startDef 1 set startSpeed 1 set startAtk 1 set-default-shape mobs "bug" set-default-shape heroes "person" ask patches [ init ] reset-ticks end to init ;; patch procedure set pcolor green if not any? heroes [ invoke-heroes-no-parent ] if( random-float 1.0 < hero_spawn / 100 and count turtles-here = 0 ) [ invoke-heroes-no-parent ] initMobs end to invoke-heroes-no-parent sprout-heroes 1 [ set max-life startLife + random-float 2 * random-float life_variation set attack startAtk + random-float 2 * random-float attack_variation set defense startDef + random-float 2 * random-float defense_variation set target nobody set life max-life ] end to invoke-heroes [parent1 parent2] sprout-heroes 1 [ set max-life average [max-life] of parent1 [max-life] of parent2 + random-float life_variation set attack average [attack] of parent1 [attack] of parent2 + random-float attack_variation set defense average [defense] of parent1 [defense] of parent2 + random-float defense_variation set target nobody set life max-life ] end to invoke-mobs sprout-mobs 1 [ set max-life random-float [max-life] of max-one-of heroes [max-life] set attack random-float [attack] of max-one-of heroes [attack] set defense random-float [defense] of max-one-of heroes [defense] set life max-life ] end to go ask heroes [moveHeroes] ask mobs [moveMobs] ask heroes [isDead] ask mobs [isDead] if(count mobs = 0)[ reproduce set generation generation + 1 repopMobs ] if not any? heroes [ stop ] tick end to moveHeroes let attackers self ifelse(target != nobody and ([patch-here] of target = [patch-here] of self or [distance attackers] of target < 2))[ ifelse(random 100 < 50)[ ;; output-print (word "ATTACK: " target " attack " self) ask target [attackTarget attackers] attackTarget target ] [ ;; output-print (word "ATTACK: " self " attack " target) attackTarget target ask target [attackTarget attackers] ] ] [ let nearest-neighbor min-one-of mobs [ distance myself ] set target nearest-neighbor if(target != nobody)[ face target fd 0.5 ] ] end to moveMobs let me self let attacker heroes with [target = me] if( count attacker > 0) [ face one-of attacker fd 0.5 ] end to isDead if(life <= 0)[ die ] end to reproduce ask patches [ if ( random-float 1.0 <= hero_spawn / 100.0 and count turtles-here = 0)[ invoke-heroes one-of heroes one-of heroes ] ] end to repopMobs ask patches [initMobs] end to initMobs if( random-float 1.0 < mob_spawn / 100 and count turtles-here = 0 ) [ invoke-mobs ] end to attackTarget [targetAttack] let damage [attack] of self let defenseTarget (random-float 1.0 * [defense] of targetAttack) let variation damage - defenseTarget ;;output-print (word "DAMAGE: " self " deal " variation " to " targetAttack) if(variation > 0) [ ask targetAttack [set life (life - variation)] ] end to-report average [a b] report (a + b) / 2.0 end
There is only one version of this model, created over 11 years ago by Leo B.
This model does not have any ancestors.
This model does not have any descendants.